From 216b4e36fff47442425f5b98257d37a47cf5862a Mon Sep 17 00:00:00 2001 From: Chinedu Francis Nwafili Date: Mon, 21 Jan 2019 16:58:58 -0500 Subject: [PATCH] Rename immutable slices test --- .../wasm/whitelisted_immutable_slices.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs diff --git a/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs new file mode 100644 index 00000000..92b4cbd3 --- /dev/null +++ b/crates/web-sys/tests/wasm/whitelisted_immutable_slices.rs @@ -0,0 +1,26 @@ +//! When generating our web_sys APIs we default to setting slice references that +//! get passed to JS as mutable in case they get mutated in JS. +//! +//! 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. +//! +//! @see https://github.com/rustwasm/wasm-bindgen/issues/1005 + +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; +use web_sys::WebGlRenderingContext; + +#[wasm_bindgen(module = "./tests/wasm/element.js")] +extern "C" { + fn new_webgl_rendering_context() -> WebGlRenderingContext; +} + +// 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, &[5000.]); +}