mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-15 05:51:23 +00:00
Support [NoInterfaceObject] in web-sys
This commit enables `[NoInterfaceObject]` annotated interfaces in `web-sys`. The `NoInterfaceObject` attribute means that there's not actually a JS class for the object, but all of its properties and such can still be accessed structually and invoked. This should help provide more bindings for some more common types on the web! Note that this builds on recent features to ensure that `dyn_into` and friends always fail for `NoInterfaceObject` objects because they don't actually have a class. Closes #893 Closes #1257 Closes #1315
This commit is contained in:
@ -12,3 +12,4 @@ pub mod global;
|
||||
pub mod namespace;
|
||||
pub mod simple;
|
||||
pub mod throws;
|
||||
pub mod no_interface;
|
||||
|
8
crates/webidl-tests/no_interface.js
Normal file
8
crates/webidl-tests/no_interface.js
Normal file
@ -0,0 +1,8 @@
|
||||
global.GetNoInterfaceObject = class {
|
||||
static get() {
|
||||
return {
|
||||
number: 3,
|
||||
foo: () => {},
|
||||
}
|
||||
}
|
||||
};
|
11
crates/webidl-tests/no_interface.rs
Normal file
11
crates/webidl-tests/no_interface.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use js_sys::Object;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/no_interface.rs"));
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn smoke() {
|
||||
let obj = GetNoInterfaceObject::get();
|
||||
assert_eq!(obj.number(), 3.0);
|
||||
obj.foo();
|
||||
}
|
9
crates/webidl-tests/no_interface.webidl
vendored
Normal file
9
crates/webidl-tests/no_interface.webidl
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
[NoInterfaceObject]
|
||||
interface NoInterfaceObject {
|
||||
readonly attribute double number;
|
||||
void foo();
|
||||
};
|
||||
|
||||
interface GetNoInterfaceObject {
|
||||
static NoInterfaceObject get();
|
||||
};
|
Reference in New Issue
Block a user