diff --git a/crates/webidl-tests/global.js b/crates/webidl-tests/global.js index 305de81b3..b703d16ca 100644 --- a/crates/webidl-tests/global.js +++ b/crates/webidl-tests/global.js @@ -1,4 +1,8 @@ -global.global_no_args = () => 3; -global.global_with_args = (a, b) => a + b; -global.global_attribute = 'x'; +const map = { + global_no_args: () => 3, + global_with_args: (a, b) => a + b, + global_attribute: 'x', +}; + +global.get_global = () => map; diff --git a/crates/webidl-tests/global.rs b/crates/webidl-tests/global.rs index d52305fc1..2a9846909 100644 --- a/crates/webidl-tests/global.rs +++ b/crates/webidl-tests/global.rs @@ -1,13 +1,20 @@ use js_sys::Object; +use wasm_bindgen::prelude::*; use wasm_bindgen_test::*; include!(concat!(env!("OUT_DIR"), "/global.rs")); +#[wasm_bindgen] +extern { + fn get_global() -> Global; +} + #[wasm_bindgen_test] fn works() { - assert_eq!(Global::global_no_args(), 3); - assert_eq!(Global::global_with_args("a", "b"), "ab"); - assert_eq!(Global::global_attribute(), "x"); - Global::set_global_attribute("y"); - assert_eq!(Global::global_attribute(), "y"); + let x = get_global(); + assert_eq!(x.global_no_args(), 3); + assert_eq!(x.global_with_args("a", "b"), "ab"); + assert_eq!(x.global_attribute(), "x"); + x.set_global_attribute("y"); + assert_eq!(x.global_attribute(), "y"); } diff --git a/crates/webidl-tests/simple.js b/crates/webidl-tests/simple.js index eaeb2bbd5..8498b547d 100644 --- a/crates/webidl-tests/simple.js +++ b/crates/webidl-tests/simple.js @@ -87,7 +87,11 @@ global.Unforgeable = class Unforgeable { } }; -global.m = () => 123; +global.GlobalMethod = class { + m() { return 123; } +}; + +global.get_global_method = () => new GlobalMethod(); global.Indexing = function () { return new Proxy({}, { diff --git a/crates/webidl-tests/simple.rs b/crates/webidl-tests/simple.rs index 7c1923f8b..21a710e41 100644 --- a/crates/webidl-tests/simple.rs +++ b/crates/webidl-tests/simple.rs @@ -72,9 +72,16 @@ fn nullable_method() { assert!(f.opt(None) == None); } +#[wasm_bindgen] +extern { + fn get_global_method() -> GlobalMethod; +} + + #[wasm_bindgen_test] fn global_method() { - assert_eq!(GlobalMethod::m(), 123); + let x = get_global_method(); + assert_eq!(x.m(), 123); } #[wasm_bindgen_test]