mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-07-31 20:11:55 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -7,5 +7,5 @@ fn take_and_return_a_bunch_of_slices() {
|
||||
let f = ArrayBufferTest::new().unwrap();
|
||||
let x = f.get_buffer();
|
||||
f.set_buffer(None);
|
||||
f.set_buffer(Some(x));
|
||||
f.set_buffer(Some(&x));
|
||||
}
|
||||
|
@@ -153,3 +153,13 @@ global.MixinFoo = class MixinFoo {
|
||||
global.Overloads = class {
|
||||
foo() {}
|
||||
};
|
||||
|
||||
global.InvokeCallback = class {
|
||||
invoke(f) { f(); }
|
||||
callAdd(f) {
|
||||
return f(1, 2);
|
||||
}
|
||||
callRepeat(f) {
|
||||
return f('ab', 4);
|
||||
}
|
||||
};
|
||||
|
@@ -1,4 +1,6 @@
|
||||
use wasm_bindgen_test::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/simple.rs"));
|
||||
|
||||
@@ -130,3 +132,26 @@ fn overload_naming() {
|
||||
o.foo_with_arg_and_f32("x", 2.0);
|
||||
o.foo_with_arg_and_i16("x", 5);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn callback() {
|
||||
let o = InvokeCallback::new().unwrap();
|
||||
{
|
||||
static mut HIT: bool = false;
|
||||
let cb = Closure::wrap(Box::new(move || {
|
||||
unsafe { HIT = true; }
|
||||
}) as Box<FnMut()>);
|
||||
o.invoke(cb.as_ref().unchecked_ref());
|
||||
assert!(unsafe { HIT });
|
||||
}
|
||||
|
||||
let cb = Closure::wrap(Box::new(move |a, b| {
|
||||
a + b
|
||||
}) as Box<FnMut(u32, u32) -> u32>);
|
||||
assert_eq!(o.call_add(cb.as_ref().unchecked_ref()), 3);
|
||||
|
||||
let cb = Closure::wrap(Box::new(move |a: String, b| {
|
||||
a.repeat(b)
|
||||
}) as Box<FnMut(String, usize) -> String>);
|
||||
assert_eq!(o.call_repeat(cb.as_ref().unchecked_ref()), "abababab");
|
||||
}
|
||||
|
12
crates/webidl-tests/simple.webidl
vendored
12
crates/webidl-tests/simple.webidl
vendored
@@ -100,3 +100,15 @@ interface Overloads {
|
||||
void foo(DOMString arg, optional long a);
|
||||
void foo(DOMString arg, (float or short) b);
|
||||
};
|
||||
|
||||
callback MyCallback = any();
|
||||
callback AddCallback = long(long a, long b);
|
||||
callback RepeatCallback = DOMString(DOMString a, long cnt);
|
||||
callback GetAnswer = long();
|
||||
|
||||
[Constructor()]
|
||||
interface InvokeCallback {
|
||||
void invoke(MyCallback callback);
|
||||
long callAdd(AddCallback callback);
|
||||
DOMString callRepeat(RepeatCallback callback);
|
||||
};
|
||||
|
Reference in New Issue
Block a user