diff options
Diffstat (limited to 'vendor/wasm-bindgen/tests')
19 files changed, 165 insertions, 8 deletions
diff --git a/vendor/wasm-bindgen/tests/wasm/api.rs b/vendor/wasm-bindgen/tests/wasm/api.rs index c1c542d67..26da4fc9a 100644 --- a/vendor/wasm-bindgen/tests/wasm/api.rs +++ b/vendor/wasm-bindgen/tests/wasm/api.rs @@ -1,6 +1,5 @@ use js_sys::{Uint8Array, WebAssembly}; use wasm_bindgen::prelude::*; -use wasm_bindgen::{self, JsCast}; use wasm_bindgen_test::*; #[wasm_bindgen(module = "tests/wasm/api.js")] diff --git a/vendor/wasm-bindgen/tests/wasm/classes.js b/vendor/wasm-bindgen/tests/wasm/classes.js index 93a76107a..bcb61e054 100644 --- a/vendor/wasm-bindgen/tests/wasm/classes.js +++ b/vendor/wasm-bindgen/tests/wasm/classes.js @@ -43,6 +43,10 @@ exports.js_exceptions = () => { let b = wasm.ClassesExceptions1.new(); b.foo(b); assert.throws(() => b.bar(b), /recursive use of an object/); + // TODO: throws because it tries to borrow_mut, but the throw_str from the previous line doesn't clean up the + // RefMut so the object is left in a broken state. + // We still try to call free here so the object is removed from the FinalizationRegistry when weak refs are enabled. + assert.throws(() => b.free(), /recursive use of an object/); let c = wasm.ClassesExceptions1.new(); let d = wasm.ClassesExceptions2.new(); diff --git a/vendor/wasm-bindgen/tests/wasm/closures.js b/vendor/wasm-bindgen/tests/wasm/closures.js index dfc3d871e..9d2ca1e98 100644 --- a/vendor/wasm-bindgen/tests/wasm/closures.js +++ b/vendor/wasm-bindgen/tests/wasm/closures.js @@ -150,7 +150,7 @@ exports.pass_reference_first_arg_twice = (a, b, c) => { }; exports.call_destroyed = f => { - assert.throws(f, /invoked recursively or destroyed/); + assert.throws(f, /closure invoked.*after being dropped/); }; let FORGOTTEN_CLOSURE = null; diff --git a/vendor/wasm-bindgen/tests/wasm/closures.rs b/vendor/wasm-bindgen/tests/wasm/closures.rs index dc88b43ad..e94ed2427 100644 --- a/vendor/wasm-bindgen/tests/wasm/closures.rs +++ b/vendor/wasm-bindgen/tests/wasm/closures.rs @@ -493,7 +493,6 @@ fn test_closure_returner() { type ClosureType = dyn FnMut() -> BadStruct; use js_sys::{Object, Reflect}; - use wasm_bindgen::JsCast; js_test_closure_returner(); diff --git a/vendor/wasm-bindgen/tests/wasm/futures.js b/vendor/wasm-bindgen/tests/wasm/futures.js index 5f4564bac..b95608660 100644 --- a/vendor/wasm-bindgen/tests/wasm/futures.js +++ b/vendor/wasm-bindgen/tests/wasm/futures.js @@ -18,6 +18,10 @@ exports.call_exports = async function() { assert.strictEqual("Hi, Jim!", await wasm.async_take_reference("Jim")); const foo = await new wasm.AsyncStruct(); assert.strictEqual(42, await foo.method()); + await wasm.async_take_js_reference(42); + const buffer = new Int32Array([1, 2, 3, 4]); + await wasm.async_take_mut_slice(buffer); + assert.deepStrictEqual(buffer, new Int32Array([42, 42, 42, 42])); }; exports.call_promise = async function() { diff --git a/vendor/wasm-bindgen/tests/wasm/futures.rs b/vendor/wasm-bindgen/tests/wasm/futures.rs index ad2be0f71..7dfddf209 100644 --- a/vendor/wasm-bindgen/tests/wasm/futures.rs +++ b/vendor/wasm-bindgen/tests/wasm/futures.rs @@ -126,6 +126,16 @@ impl AsyncStruct { } } +#[wasm_bindgen] +pub async fn async_take_js_reference(x: &JsValue) { + assert_eq!(*x, 42); +} + +#[wasm_bindgen] +pub async fn async_take_mut_slice(x: &mut [i32]) { + x.fill(42); +} + #[wasm_bindgen_test] async fn test_promise() { assert_eq!(call_promise().await.as_string(), Some(String::from("ok"))) diff --git a/vendor/wasm-bindgen/tests/wasm/import_class.js b/vendor/wasm-bindgen/tests/wasm/import_class.js index 848be7b14..778ffd15b 100644 --- a/vendor/wasm-bindgen/tests/wasm/import_class.js +++ b/vendor/wasm-bindgen/tests/wasm/import_class.js @@ -25,6 +25,26 @@ class Construct { assert_internal_string(s) { assert.strictEqual(this.internal_string, s); } + + ["kebab-case"]() { + return 42; + } + + get ["kebab-case-val"]() { + return 42; + } + + set ["kebab-case-val"](val) {} + + static ["static-kebab-case"]() { + return 42; + } + + static get ["static-kebab-case-val"]() { + return 42; + } + + static set ["static-kebab-case-val"](val) {} } Construct.internal_string = ''; diff --git a/vendor/wasm-bindgen/tests/wasm/import_class.rs b/vendor/wasm-bindgen/tests/wasm/import_class.rs index 7de986147..55cc1d1be 100644 --- a/vendor/wasm-bindgen/tests/wasm/import_class.rs +++ b/vendor/wasm-bindgen/tests/wasm/import_class.rs @@ -23,6 +23,19 @@ extern "C" { #[wasm_bindgen(method)] fn assert_internal_string(this: &Construct, s: &str); + #[wasm_bindgen(method, js_name = "kebab-case")] + fn kebab_case(this: &Construct) -> u32; + #[wasm_bindgen(method, getter, js_name = "kebab-case-val")] + fn kebab_case_val(this: &Construct) -> u32; + #[wasm_bindgen(method, setter, js_name = "kebab-case-val")] + fn set_kebab_case_val(this: &Construct, val: u32); + #[wasm_bindgen(static_method_of = Construct, js_name = "static-kebab-case")] + fn static_kebab_case() -> u32; + #[wasm_bindgen(static_method_of = Construct, getter, js_name = "static-kebab-case-val")] + fn static_kebab_case_val() -> u32; + #[wasm_bindgen(static_method_of = Construct, setter, js_name = "static-kebab-case-val")] + fn set_static_kebab_case_val(val: u32); + type NewConstructors; #[wasm_bindgen(constructor)] fn new(arg: i32) -> NewConstructors; @@ -137,6 +150,14 @@ fn construct() { assert_eq!(f.clone().get_internal_string(), "this"); f.append_to_internal_string(" foo"); f.assert_internal_string("this foo"); + + assert_eq!(f.kebab_case(), 42); + f.set_kebab_case_val(0); + // our setter does nothing so this is 42 anyway + assert_eq!(f.kebab_case_val(), 42); + assert_eq!(Construct::static_kebab_case(), 42); + Construct::set_static_kebab_case_val(0); + assert_eq!(Construct::static_kebab_case_val(), 42); } #[wasm_bindgen_test] diff --git a/vendor/wasm-bindgen/tests/wasm/imports.js b/vendor/wasm-bindgen/tests/wasm/imports.js index 70d8a3b08..a47968d35 100644 --- a/vendor/wasm-bindgen/tests/wasm/imports.js +++ b/vendor/wasm-bindgen/tests/wasm/imports.js @@ -140,4 +140,7 @@ exports.same_name_from_import = (a) => a * 3; exports.same_js_namespace_from_module = { func_from_module_1_same_js_namespace: (a) => a * 5 -}
\ No newline at end of file +} + +exports["kebab-case"] = () => 42; +exports["\"string'literal\nbreakers\r"] = () => 42; diff --git a/vendor/wasm-bindgen/tests/wasm/imports.rs b/vendor/wasm-bindgen/tests/wasm/imports.rs index 88dbf5ed6..27e4a67dc 100644 --- a/vendor/wasm-bindgen/tests/wasm/imports.rs +++ b/vendor/wasm-bindgen/tests/wasm/imports.rs @@ -81,6 +81,12 @@ extern "C" { #[wasm_bindgen(js_namespace = same_js_namespace_from_module)] fn func_from_module_1_same_js_namespace(s: i32) -> i32; + + #[wasm_bindgen(js_name = "kebab-case")] + fn kebab_case() -> u32; + + #[wasm_bindgen(js_name = "\"string'literal\nbreakers\r")] + fn string_literal_breakers() -> u32; } #[wasm_bindgen(module = "tests/wasm/imports_2.js")] @@ -321,3 +327,9 @@ fn func_from_two_modules_same_js_namespace() { assert_eq!(func_from_module_1_same_js_namespace(2), 10); assert_eq!(func_from_module_2_same_js_namespace(2), 12); } + +#[wasm_bindgen_test] +fn invalid_idents() { + assert_eq!(kebab_case(), 42); + assert_eq!(string_literal_breakers(), 42); +} diff --git a/vendor/wasm-bindgen/tests/wasm/intrinsics.rs b/vendor/wasm-bindgen/tests/wasm/intrinsics.rs index 15985e812..843d2d289 100644 --- a/vendor/wasm-bindgen/tests/wasm/intrinsics.rs +++ b/vendor/wasm-bindgen/tests/wasm/intrinsics.rs @@ -3,7 +3,7 @@ use std::convert::TryFrom; use std::fmt::Debug; -use js_sys::{Object, RangeError, Reflect}; +use js_sys::{Array, Object, RangeError, Reflect}; use wasm_bindgen::{JsCast, JsValue}; use wasm_bindgen_test::wasm_bindgen_test; @@ -78,6 +78,7 @@ fn types() { assert!(JsValue::UNDEFINED.is_undefined()); assert!(JsValue::NULL.is_null()); assert!(Object::new().is_object()); + assert!(Array::new().is_array()); assert!(JsValue::symbol(None).is_symbol()); assert!(JsValue::from_str("hi").is_string()); assert!(JsValue::bigint_from_str("5").is_bigint()); diff --git a/vendor/wasm-bindgen/tests/wasm/jscast.rs b/vendor/wasm-bindgen/tests/wasm/jscast.rs index 1279634d2..45d0b862b 100644 --- a/vendor/wasm-bindgen/tests/wasm/jscast.rs +++ b/vendor/wasm-bindgen/tests/wasm/jscast.rs @@ -1,5 +1,4 @@ use wasm_bindgen::prelude::*; -use wasm_bindgen::JsCast; use wasm_bindgen_test::*; #[wasm_bindgen(module = "tests/wasm/jscast.js")] diff --git a/vendor/wasm-bindgen/tests/wasm/link_to.js b/vendor/wasm-bindgen/tests/wasm/link_to.js new file mode 100644 index 000000000..3028a6ae8 --- /dev/null +++ b/vendor/wasm-bindgen/tests/wasm/link_to.js @@ -0,0 +1,4 @@ +const fs = require('fs'); +const url = require('url'); + +exports.read_file = (str) => fs.readFileSync(url.fileURLToPath(str), "utf8"); diff --git a/vendor/wasm-bindgen/tests/wasm/link_to.rs b/vendor/wasm-bindgen/tests/wasm/link_to.rs new file mode 100644 index 000000000..e631bdb03 --- /dev/null +++ b/vendor/wasm-bindgen/tests/wasm/link_to.rs @@ -0,0 +1,30 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; + +#[wasm_bindgen(module = "/tests/wasm/link_to.js")] +extern "C" { + #[wasm_bindgen(catch)] + fn read_file(url: &str) -> Result<String, JsValue>; +} + +#[wasm_bindgen_test] +fn test_module() { + let link = wasm_bindgen::link_to!(module = "/tests/wasm/linked_module.js"); + assert_eq!(read_file(&link).unwrap(), "// linked module\n"); +} + +#[wasm_bindgen_test] +fn test_raw_module() { + let link = wasm_bindgen::link_to!(raw_module = "./not-found.js"); + assert!(read_file(&link).is_err()); +} + +#[wasm_bindgen_test] +fn test_inline_js() { + // Test two invocations to ensure that snippet indices from different + // Program structs are offset correctly. + let link1 = wasm_bindgen::link_to!(inline_js = "// inline js 1\n"); + let link2 = wasm_bindgen::link_to!(inline_js = "// inline js 2\n"); + assert_eq!(read_file(&link1).unwrap(), "// inline js 1\n"); + assert_eq!(read_file(&link2).unwrap(), "// inline js 2\n"); +} diff --git a/vendor/wasm-bindgen/tests/wasm/linked_module.js b/vendor/wasm-bindgen/tests/wasm/linked_module.js new file mode 100644 index 000000000..b979535b2 --- /dev/null +++ b/vendor/wasm-bindgen/tests/wasm/linked_module.js @@ -0,0 +1 @@ +// linked module diff --git a/vendor/wasm-bindgen/tests/wasm/main.rs b/vendor/wasm-bindgen/tests/wasm/main.rs index 51e6dcafe..987962c88 100644 --- a/vendor/wasm-bindgen/tests/wasm/main.rs +++ b/vendor/wasm-bindgen/tests/wasm/main.rs @@ -32,11 +32,13 @@ pub mod intrinsics; pub mod js_keywords; pub mod js_objects; pub mod jscast; +pub mod link_to; pub mod math; pub mod no_shims; pub mod node; pub mod option; pub mod optional_primitives; +pub mod owned; pub mod result; pub mod result_jserror; pub mod rethrow; @@ -51,6 +53,6 @@ pub mod vendor_prefix; // should not be executed #[wasm_bindgen(start)] -pub fn start() { +fn start() { panic!(); } diff --git a/vendor/wasm-bindgen/tests/wasm/owned.js b/vendor/wasm-bindgen/tests/wasm/owned.js new file mode 100644 index 000000000..e1d5dfbe1 --- /dev/null +++ b/vendor/wasm-bindgen/tests/wasm/owned.js @@ -0,0 +1,13 @@ +const wasm = require("wasm-bindgen-test.js"); + +exports.create_garbage = async function () { + for (let i = 0; i < 100; i++) { + new wasm.OwnedValue(1).add(new wasm.OwnedValue(2)).n(); + } + + if ("gc" in global) { + global.gc(); + } else { + console.warn("test runner doesn't expose GC function"); + } +}; diff --git a/vendor/wasm-bindgen/tests/wasm/owned.rs b/vendor/wasm-bindgen/tests/wasm/owned.rs new file mode 100644 index 000000000..7d51673a5 --- /dev/null +++ b/vendor/wasm-bindgen/tests/wasm/owned.rs @@ -0,0 +1,35 @@ +use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; + +#[wasm_bindgen] +pub struct OwnedValue { + pub n: f64, +} + +#[wasm_bindgen] +impl OwnedValue { + #[wasm_bindgen(constructor)] + pub fn new(n: f64) -> Self { + Self { n } + } + + pub fn add(self, other: OwnedValue) -> Self { + Self { + n: self.n + other.n, + } + } + + pub fn n(self) -> f64 { + self.n + } +} + +#[wasm_bindgen(module = "tests/wasm/owned.js")] +extern "C" { + fn create_garbage(); +} + +#[wasm_bindgen_test] +fn test_create_garbage() { + create_garbage() +} diff --git a/vendor/wasm-bindgen/tests/wasm/simple.rs b/vendor/wasm-bindgen/tests/wasm/simple.rs index 611b5320a..5f22b6ea9 100644 --- a/vendor/wasm-bindgen/tests/wasm/simple.rs +++ b/vendor/wasm-bindgen/tests/wasm/simple.rs @@ -1,5 +1,5 @@ use wasm_bindgen::prelude::*; -use wasm_bindgen::{intern, unintern, JsCast}; +use wasm_bindgen::{intern, unintern}; use wasm_bindgen_test::*; #[wasm_bindgen(module = "tests/wasm/simple.js")] |