Skip to content

Commit

Permalink
Add failing immutable slice test
Browse files Browse the repository at this point in the history
  • Loading branch information
chinedufn committed Jan 17, 2019
1 parent 177ef22 commit 1d0c2fe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
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 @@ -151,6 +151,11 @@ export function new_title() {
return document.createElement("title");
}

export function new_webgl_rendering_context() {
const canvas = document.createElement('canvas');
return canvas.getContext('webgl');
}

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
26 changes: 26 additions & 0 deletions crates/web-sys/tests/wasm/immutable_slices.rs
Original file line number Diff line number Diff line change
@@ -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.]);
}
1 change: 1 addition & 0 deletions crates/web-sys/tests/wasm/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub mod style_element;
pub mod table_element;
pub mod title_element;
pub mod xpath_result;
pub mod immutable_slices;

#[wasm_bindgen_test]
fn deref_works() {
Expand Down
2 changes: 2 additions & 0 deletions crates/webidl-tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// intentionally left blank

// QUESTION FOR REVIEWER: WHY? (I'll include this context in the comment)

0 comments on commit 1d0c2fe

Please sign in to comment.