mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-19 16:01:23 +00:00
Whitelist send_with_u8_array slice (#2015)
* Whitelist send_with_u8_array slice Fixes #2014 * Fix send slice * Remove chromedriver comment * Get slice tests running in CI
This commit is contained in:
committed by
GitHub
parent
1e75e415b3
commit
bab83a7ff4
@ -151,16 +151,6 @@ export function new_title() {
|
|||||||
return document.createElement("title");
|
return document.createElement("title");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function new_webgl_rendering_context() {
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
return canvas.getContext('webgl');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function new_webgl2_rendering_context() {
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
return canvas.getContext('webgl2');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function new_xpath_result() {
|
export function new_xpath_result() {
|
||||||
let xmlDoc = new DOMParser().parseFromString("<root><value>tomato</value></root>", "application/xml");
|
let xmlDoc = new DOMParser().parseFromString("<root><value>tomato</value></root>", "application/xml");
|
||||||
let xpathResult = xmlDoc.evaluate("/root//value", xmlDoc, null, XPathResult.ANY_TYPE, null);
|
let xpathResult = xmlDoc.evaluate("/root//value", xmlDoc, null, XPathResult.ANY_TYPE, null);
|
||||||
|
@ -4,86 +4,73 @@
|
|||||||
//! In certain cases we know for sure that the slice will not get mutated - for
|
//! In certain cases we know for sure that the slice will not get mutated - for
|
||||||
//! example when working with the WebGlRenderingContext APIs.
|
//! 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
|
//! Especially important since this whitelist is stringly typed and currently
|
||||||
//! maintained by hand.
|
//! maintained by hand.
|
||||||
//!
|
//!
|
||||||
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005
|
//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005
|
||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket};
|
||||||
use web_sys::{WebGl2RenderingContext, WebGlRenderingContext};
|
use wasm_bindgen::{JsValue, JsCast};
|
||||||
|
|
||||||
#[wasm_bindgen(module = "/tests/wasm/element.js")]
|
// Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices.
|
||||||
extern "C" {
|
fn test_webgl_rendering_context_immutable_slices() {
|
||||||
fn new_webgl_rendering_context() -> WebGlRenderingContext;
|
let gl = JsValue::null().unchecked_into::<WebGlRenderingContext>();
|
||||||
fn new_webgl2_rendering_context() -> WebGl2RenderingContext;
|
|
||||||
// TODO: Add a function to create another type to test here.
|
gl.vertex_attrib1fv_with_f32_array(0, &[1.]);
|
||||||
// These functions come from element.js
|
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Uncomment WebGlRenderingContext test. Every now and then we can check if this works
|
// Ensure that our whitelisted WebGl2RenderingContext methods compile with immutable slices.
|
||||||
// in the latest geckodriver.
|
fn test_webgl2_rendering_context_immutable_slices() {
|
||||||
//
|
let gl = JsValue::null().unchecked_into::<WebGl2RenderingContext>();
|
||||||
// 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
|
gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
|
||||||
//#[wasm_bindgen_test]
|
gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1]));
|
||||||
//fn test_webgl_rendering_context_immutable_slices() {
|
gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]);
|
||||||
// let gl = new_webgl_rendering_context();
|
}
|
||||||
//
|
|
||||||
// gl.vertex_attrib1fv_with_f32_array(0, &[1.]);
|
// Ensure that our whitelisted WebSocket methods compile with immutable slices.
|
||||||
// gl.vertex_attrib2fv_with_f32_array(0, &[1.]);
|
fn test_websocket_immutable_slices() {
|
||||||
// gl.vertex_attrib3fv_with_f32_array(0, &[1.]);
|
let ws = JsValue::null().unchecked_into::<WebSocket>();
|
||||||
// gl.vertex_attrib4fv_with_f32_array(0, &[1.]);
|
ws.send_with_u8_array(&[0]);
|
||||||
//
|
}
|
||||||
// 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();
|
|
||||||
|
|
||||||
// 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:
|
// TODO:
|
||||||
//#[wasm_bindgen_test]
|
//#[wasm_bindgen_test]
|
||||||
//fn test_another_types_immutable_slices_here() {
|
//fn test_another_types_immutable_slices_here() {
|
||||||
|
@ -244,6 +244,8 @@ fn immutable_slice_whitelist() -> BTreeSet<&'static str> {
|
|||||||
"clearBufferfv",
|
"clearBufferfv",
|
||||||
"clearBufferiv",
|
"clearBufferiv",
|
||||||
"clearBufferuiv",
|
"clearBufferuiv",
|
||||||
|
// WebSocket
|
||||||
|
"send",
|
||||||
// TODO: Add another type's functions here. Leave a comment header with the type name
|
// TODO: Add another type's functions here. Leave a comment header with the type name
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user