|
4 | 4 | //! In certain cases we know for sure that the slice will not get mutated - for
|
5 | 5 | //! example when working with the WebGlRenderingContext APIs.
|
6 | 6 | //!
|
7 |
| -//! These tests ensure that whitelisted methods do indeed accept mutable slices. |
| 7 | +//! These tests ensure that whitelisted methods do indeed accept immutable slices. |
8 | 8 | //! Especially important since this whitelist is stringly typed and currently
|
9 | 9 | //! maintained by hand.
|
10 | 10 | //!
|
11 | 11 | //! @see https://github.com/rustwasm/wasm-bindgen/issues/1005
|
12 | 12 |
|
13 |
| -use wasm_bindgen::prelude::*; |
14 |
| -use web_sys::{WebGl2RenderingContext, WebGlRenderingContext}; |
| 13 | +use web_sys::{WebGl2RenderingContext, WebGlRenderingContext, WebSocket}; |
| 14 | +use wasm_bindgen::{JsValue, JsCast}; |
15 | 15 |
|
16 |
| -#[wasm_bindgen(module = "/tests/wasm/element.js")] |
17 |
| -extern "C" { |
18 |
| - fn new_webgl_rendering_context() -> WebGlRenderingContext; |
19 |
| - fn new_webgl2_rendering_context() -> WebGl2RenderingContext; |
20 |
| -// TODO: Add a function to create another type to test here. |
21 |
| -// These functions come from element.js |
| 16 | +// Ensure that our whitelisted WebGlRenderingContext methods compile with immutable slices. |
| 17 | +fn test_webgl_rendering_context_immutable_slices() { |
| 18 | + let gl = JsValue::null().unchecked_into::<WebGlRenderingContext>(); |
| 19 | + |
| 20 | + gl.vertex_attrib1fv_with_f32_array(0, &[1.]); |
| 21 | + gl.vertex_attrib2fv_with_f32_array(0, &[1.]); |
| 22 | + gl.vertex_attrib3fv_with_f32_array(0, &[1.]); |
| 23 | + gl.vertex_attrib4fv_with_f32_array(0, &[1.]); |
| 24 | + |
| 25 | + gl.uniform1fv_with_f32_array(None, &[1.]); |
| 26 | + gl.uniform2fv_with_f32_array(None, &[1.]); |
| 27 | + gl.uniform3fv_with_f32_array(None, &[1.]); |
| 28 | + gl.uniform4fv_with_f32_array(None, &[1.]); |
| 29 | + |
| 30 | + gl.uniform_matrix2fv_with_f32_array(None, false, &[1.]); |
| 31 | + gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]); |
| 32 | + gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]); |
| 33 | + |
| 34 | + gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array( |
| 35 | + 0, |
| 36 | + 0, |
| 37 | + 0, |
| 38 | + 0, |
| 39 | + 0, |
| 40 | + 0, |
| 41 | + 0, |
| 42 | + 0, |
| 43 | + Some(&[1]), |
| 44 | + ); |
| 45 | + gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_u8_array( |
| 46 | + 0, |
| 47 | + 0, |
| 48 | + 0, |
| 49 | + 0, |
| 50 | + 0, |
| 51 | + 0, |
| 52 | + 0, |
| 53 | + 0, |
| 54 | + Some(&[1]), |
| 55 | + ); |
| 56 | + gl.compressed_tex_image_2d_with_u8_array(0, 0, 0, 0, 0, 0, &[1]); |
22 | 57 | }
|
23 | 58 |
|
24 |
| -// TODO: Uncomment WebGlRenderingContext test. Every now and then we can check if this works |
25 |
| -// in the latest geckodriver. |
26 |
| -// |
27 |
| -// Currently commented out because WebGl isn't working in geckodriver. |
28 |
| -// |
29 |
| -// It currently works in chromedriver so if you need to run this in the meantime you can |
30 |
| -// uncomment this block and run it in using chromedriver. |
31 |
| -// |
32 |
| -// CHROMEDRIVER=chromedriver cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features test_webgl_rendering_context_immutable_slices |
| 59 | +// Ensure that our whitelisted WebGl2RenderingContext methods compile with immutable slices. |
| 60 | +fn test_webgl2_rendering_context_immutable_slices() { |
| 61 | + let gl = JsValue::null().unchecked_into::<WebGl2RenderingContext>(); |
33 | 62 |
|
34 |
| -// Ensure that our whitelisted WebGlRenderingContext methods work |
35 |
| -//#[wasm_bindgen_test] |
36 |
| -//fn test_webgl_rendering_context_immutable_slices() { |
37 |
| -// let gl = new_webgl_rendering_context(); |
38 |
| -// |
39 |
| -// gl.vertex_attrib1fv_with_f32_array(0, &[1.]); |
40 |
| -// gl.vertex_attrib2fv_with_f32_array(0, &[1.]); |
41 |
| -// gl.vertex_attrib3fv_with_f32_array(0, &[1.]); |
42 |
| -// gl.vertex_attrib4fv_with_f32_array(0, &[1.]); |
43 |
| -// |
44 |
| -// gl.uniform1fv_with_f32_array(None, &[1.]); |
45 |
| -// gl.uniform2fv_with_f32_array(None, &[1.]); |
46 |
| -// gl.uniform3fv_with_f32_array(None, &[1.]); |
47 |
| -// gl.uniform4fv_with_f32_array(None, &[1.]); |
48 |
| -// |
49 |
| -// gl.uniform_matrix2fv_with_f32_array(None, false, &[1.]); |
50 |
| -// gl.uniform_matrix3fv_with_f32_array(None, false, &[1.]); |
51 |
| -// gl.uniform_matrix4fv_with_f32_array(None, false, &[1.]); |
52 |
| -// |
53 |
| -// gl.tex_image_2d_with_i32_and_i32_and_i32_and_format_and_type_and_opt_u8_array( |
54 |
| -// 0, |
55 |
| -// 0, |
56 |
| -// 0, |
57 |
| -// 0, |
58 |
| -// 0, |
59 |
| -// 0, |
60 |
| -// 0, |
61 |
| -// 0, |
62 |
| -// Some(&[1]), |
63 |
| -// ); |
64 |
| -// gl.tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_u8_array( |
65 |
| -// 0, |
66 |
| -// 0, |
67 |
| -// 0, |
68 |
| -// 0, |
69 |
| -// 0, |
70 |
| -// 0, |
71 |
| -// 0, |
72 |
| -// 0, |
73 |
| -// Some(&[1]), |
74 |
| -// ); |
75 |
| -// gl.compressed_tex_image_2d_with_u8_array(0, 0, 0, 0, 0, 0, &[1]); |
76 |
| -// } |
77 |
| -// |
78 |
| -//#[wasm_bindgen_test] |
79 |
| -//fn test_webgl2_rendering_context_immutable_slices() { |
80 |
| -// let gl = new_webgl2_rendering_context(); |
| 63 | + gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); |
| 64 | + gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); |
| 65 | + gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]); |
| 66 | +} |
| 67 | + |
| 68 | +// Ensure that our whitelisted WebSocket methods compile with immutable slices. |
| 69 | +fn test_websocket_immutable_slices() { |
| 70 | + let ws = JsValue::null().unchecked_into::<WebSocket>(); |
| 71 | + ws.send_with_u8_array(&[0]); |
| 72 | +} |
81 | 73 |
|
82 |
| -// gl.tex_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); |
83 |
| -// gl.tex_sub_image_3d_with_opt_u8_array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Some(&[1])); |
84 |
| -// gl.compressed_tex_image_3d_with_u8_array(0, 0, 0, 0, 0, 0, 0, &[1]); |
85 |
| -//} |
86 |
| -// |
87 | 74 | // TODO:
|
88 | 75 | //#[wasm_bindgen_test]
|
89 | 76 | //fn test_another_types_immutable_slices_here() {
|
|
0 commit comments