mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-29 04:31:33 +00:00
Implement WebIDL callback interfaces
This commit implements callback interfaces for WebIDL, the final WebIDL construct that we were unconditionally ignoring! Callback interfaces are implemented as dictionaries of callbacks. Single-operation callback interfaces are also expanded when flattening to accept a `Function` as well, in accordance with the WebIDL spec. New features have been added to `web-sys` for all the new callback interface types. Additionally the `EventTarget.webidl` was tweaked to not have `EventListener?` as this is required for all functional usage and there's no need to keep that sort of web browser compat here. Closes #258
This commit is contained in:
4
crates/webidl-tests/callbacks.js
Normal file
4
crates/webidl-tests/callbacks.js
Normal file
@ -0,0 +1,4 @@
|
||||
global.TakeCallbackInterface = class {
|
||||
a() {}
|
||||
b() {}
|
||||
};
|
38
crates/webidl-tests/callbacks.rs
Normal file
38
crates/webidl-tests/callbacks.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use wasm_bindgen_test::*;
|
||||
use js_sys::Function;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/callbacks.rs"));
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn multi_op_same_name() {
|
||||
let a = CallbackInterface2::new();
|
||||
let b = TakeCallbackInterface::new().unwrap();
|
||||
b.b(&a);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn single_op_function() {
|
||||
let a = Function::new_no_args("");
|
||||
let b = TakeCallbackInterface::new().unwrap();
|
||||
b.a_with_callback(&a);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn single_op_dict() {
|
||||
let a = CallbackInterface1::new();
|
||||
let b = TakeCallbackInterface::new().unwrap();
|
||||
b.a_with_callback_interface1(&a);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn dict_methods() {
|
||||
let mut a = CallbackInterface1::new();
|
||||
a.foo(&Function::new_no_args(""));
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn dict_methods1() {
|
||||
let mut a = CallbackInterface2::new();
|
||||
a.foo(&Function::new_no_args(""));
|
||||
a.bar(&Function::new_no_args(""));
|
||||
}
|
14
crates/webidl-tests/callbacks.webidl
vendored
Normal file
14
crates/webidl-tests/callbacks.webidl
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
callback interface CallbackInterface1 {
|
||||
void foo();
|
||||
};
|
||||
|
||||
callback interface CallbackInterface2 {
|
||||
void foo();
|
||||
void bar();
|
||||
};
|
||||
|
||||
[Constructor()]
|
||||
interface TakeCallbackInterface {
|
||||
void a(CallbackInterface1 arg);
|
||||
void b(CallbackInterface2 arg);
|
||||
};
|
@ -11,3 +11,4 @@ pub mod simple;
|
||||
pub mod throws;
|
||||
pub mod dictionary;
|
||||
pub mod global;
|
||||
pub mod callbacks;
|
||||
|
Reference in New Issue
Block a user