mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 04:21:21 +00:00
web-sys: Add support for Global
-scope methods
This commit adds further support for the `Global` attribute to not only emit structural accessors but also emit functions that don't take `&self`. All methods on a `[Global]` interface will not require `&self` and will call functions and/or access properties on the global scope. This should enable things like: Window::location() // returns `Location` Window::fetch(...) // invokes the `fetch` function Closes #659
This commit is contained in:
4
crates/webidl-tests/global.js
Normal file
4
crates/webidl-tests/global.js
Normal file
@ -0,0 +1,4 @@
|
||||
global.global_no_args = () => 3;
|
||||
global.global_with_args = (a, b) => a + b;
|
||||
global.global_attribute = 'x';
|
||||
|
12
crates/webidl-tests/global.rs
Normal file
12
crates/webidl-tests/global.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/global.rs"));
|
||||
|
||||
#[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");
|
||||
}
|
6
crates/webidl-tests/global.webidl
vendored
Normal file
6
crates/webidl-tests/global.webidl
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
[Global=x]
|
||||
interface Global {
|
||||
unsigned long global_no_args();
|
||||
DOMString global_with_args(DOMString a, DOMString b);
|
||||
attribute DOMString global_attribute;
|
||||
};
|
@ -10,3 +10,4 @@ pub mod namespace;
|
||||
pub mod simple;
|
||||
pub mod throws;
|
||||
pub mod dictionary;
|
||||
pub mod global;
|
||||
|
@ -87,11 +87,7 @@ global.Unforgeable = class Unforgeable {
|
||||
}
|
||||
};
|
||||
|
||||
global.GlobalMethod = class GlobalMethod {
|
||||
constructor() {
|
||||
this.m = () => 123;
|
||||
}
|
||||
};
|
||||
global.m = () => 123;
|
||||
|
||||
global.Indexing = function () {
|
||||
return new Proxy({}, {
|
||||
|
@ -64,8 +64,7 @@ fn nullable_method() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn global_method() {
|
||||
let f = GlobalMethod::new().unwrap();
|
||||
assert_eq!(f.m(), 123);
|
||||
assert_eq!(GlobalMethod::m(), 123);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
|
Reference in New Issue
Block a user