Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitelist send_with_u8_array slice #2015

Merged
merged 4 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/web-sys/tests/wasm/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export function new_webgl2_rendering_context() {
return canvas.getContext('webgl2');
}

export function new_websocket () {
const websocket = new WebSocket("");
return websocket;
}

export function new_xpath_result() {
let xmlDoc = new DOMParser().parseFromString("<root><value>tomato</value></root>", "application/xml");
let xpathResult = xmlDoc.evaluate("/root//value", xmlDoc, null, XPathResult.ANY_TYPE, null);
Expand Down
129 changes: 66 additions & 63 deletions crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,89 @@
//! In certain cases we know for sure that the slice will not get mutated - for
//! example when working with the WebGlRenderingContext APIs.
//!
//! These tests ensure that whitelisted methods do indeed accept mutable slices.
//! These tests ensure that whitelisted methods do indeed accept immutable slices.
//! Especially important since this whitelist is stringly typed and currently
//! maintained by hand.
//!
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005

use wasm_bindgen::prelude::*;
use web_sys::{WebGl2RenderingContext, WebGlRenderingContext};
use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket};
use wasm_bindgen_test::*;

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen(module = "/tests/wasm/element.js")]
extern "C" {
fn new_webgl_rendering_context() -> WebGlRenderingContext;
fn new_webgl2_rendering_context() -> WebGl2RenderingContext;
fn new_websocket() -> WebSocket;
// TODO: Add a function to create another type to test here.
// These functions come from element.js
}

// TODO: Uncomment WebGlRenderingContext test. Every now and then we can check if this works
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking to see if these tests can pass in CI now sine it's been a year

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope

// in the latest geckodriver.
//
// Currently commented out because WebGl isn't working in geckodriver.
//
// It currently works in chromedriver so if you need to run this in the meantime you can
// uncomment this block and run it in using chromedriver.
//
// CHROMEDRIVER=chromedriver cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features test_webgl_rendering_context_immutable_slices

// Ensure that our whitelisted WebGlRenderingContext methods work
//#[wasm_bindgen_test]
//fn test_webgl_rendering_context_immutable_slices() {
// let gl = new_webgl_rendering_context();
//
// gl.vertex_attrib1fv_with_f32_array(0, &[1.]);
// gl.vertex_attrib2fv_with_f32_array(0, &[1.]);
// gl.vertex_attrib3fv_with_f32_array(0, &[1.]);
// gl.vertex_attrib4fv_with_f32_array(0, &[1.]);
//
// gl.uniform1fv_with_f32_array(None, &[1.]);
// gl.uniform2fv_with_f32_array(None, &[1.]);
// gl.uniform3fv_with_f32_array(None, &[1.]);
// gl.uniform4fv_with_f32_array(None, &[1.]);
//
// gl.uniform_matrix2fv_with_f32_array(None, false, &[1.]);
// gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]);
// gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]);
//
// gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array(
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// Some(&[1]),
// );
// gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_u8_array(
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// 0,
// Some(&[1]),
// );
// gl.compressed_tex_image_2d_with_u8_array(0, 0, 0, 0, 0, 0, &[1]);
// }
//
//#[wasm_bindgen_test]
//fn test_webgl2_rendering_context_immutable_slices() {
// let gl = new_webgl2_rendering_context();
// GECKODRIVER=geckodriver cargo test -p web-sys --target wasm32-unknown-unknown --all-features test_webgl_rendering_context_immutable_slices
#[wasm_bindgen_test]
fn test_webgl_rendering_context_immutable_slices() {
let gl = new_webgl_rendering_context();

gl.vertex_attrib1fv_with_f32_array(0, &[1.]);
gl.vertex_attrib2fv_with_f32_array(0, &[1.]);
gl.vertex_attrib3fv_with_f32_array(0, &[1.]);
gl.vertex_attrib4fv_with_f32_array(0, &[1.]);

gl.uniform1fv_with_f32_array(None, &[1.]);
gl.uniform2fv_with_f32_array(None, &[1.]);
gl.uniform3fv_with_f32_array(None, &[1.]);
gl.uniform4fv_with_f32_array(None, &[1.]);

gl.uniform_matrix2fv_with_f32_array(None, false, &[1.]);
gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]);
gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]);

gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array(
0,
0,
0,
0,
0,
0,
0,
0,
Some(&[1]),
);
gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_u8_array(
0,
0,
0,
0,
0,
0,
0,
0,
Some(&[1]),
);
gl.compressed_tex_image_2d_with_u8_array(0, 0, 0, 0, 0, 0, &[1]);
}

// GECKODRIVER=geckodriver cargo test -p web-sys --target wasm32-unknown-unknown --all-features test_webgl2_rendering_context_immutable_slices
#[wasm_bindgen_test]
fn test_webgl2_rendering_context_immutable_slices() {
let gl = new_webgl2_rendering_context();

gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]);
}

// GECKODRIVER=geckodriver cargo test -p web-sys --target wasm32-unknown-unknown --all-features test_websocket_immutable_slices
#[wasm_bindgen_test]
fn test_websocket_immutable_slices() {
let ws = new_websocket();
ws.send_with_u8_array(&[0]);
}

// gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
// gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
// gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]);
//}
//
// TODO:
//#[wasm_bindgen_test]
//fn test_another_types_immutable_slices_here() {
Expand Down
2 changes: 2 additions & 0 deletions crates/webidl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ fn immutable_slice_whitelist() -> BTreeSet<&'static str> {
"clearBufferfv",
"clearBufferiv",
"clearBufferuiv",
// WebSocket
"send",
// TODO: Add another type's functions here. Leave a comment header with the type name
])
}
Expand Down