Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Anton Danilkin
2018-09-07 13:46:20 +03:00
46 changed files with 1293 additions and 360 deletions

View File

@@ -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));
}

View File

@@ -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);
}
};

View File

@@ -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");
}

View File

@@ -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);
};