Assert that a bunch more function signatures don't require JS glue

This commit is contained in:
Nick Fitzgerald 2019-07-11 15:43:43 -07:00
parent bce892b625
commit afb33e5cf4
4 changed files with 80 additions and 10 deletions

View File

@ -23,4 +23,4 @@ wasm-bindgen-anyref-xform = { path = '../anyref-xform', version = '=0.2.48' }
wasm-bindgen-shared = { path = "../shared", version = '=0.2.48' }
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.48' }
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.48' }
wasm-webidl-bindings = "0.1.0"
wasm-webidl-bindings = "0.1.1"

View File

@ -2001,7 +2001,11 @@ impl<'a> Context<'a> {
if assert_no_shim {
panic!(
"imported function was annotated with `#[wasm_bindgen(assert_no_shim)]` \
but we need to generate a JS shim for it"
but we need to generate a JS shim for it:\n\n\
\timport = {:?}\n\n\
\tbinding = {:?}\n\n\
\twebidl = {:?}",
import, binding, webidl,
);
}

View File

@ -10,15 +10,15 @@ extern "C" {
// return value is always `f64` to faithfully capture what was sent to JS
// (what we're interested in) because all JS numbers fit in `f64` anyway.
// This is testing what happens when we pass numbers to JS and what it sees.
#[wasm_bindgen(js_name = roundtrip)]
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
fn roundtrip_i8(a: i8) -> f64;
#[wasm_bindgen(js_name = roundtrip)]
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
fn roundtrip_i16(a: i16) -> f64;
#[wasm_bindgen(js_name = roundtrip)]
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
fn roundtrip_i32(a: i32) -> f64;
#[wasm_bindgen(js_name = roundtrip)]
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
fn roundtrip_u8(a: u8) -> f64;
#[wasm_bindgen(js_name = roundtrip)]
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
fn roundtrip_u16(a: u16) -> f64;
#[wasm_bindgen(js_name = roundtrip)]
fn roundtrip_u32(a: u32) -> f64;

View File

@ -14,10 +14,20 @@ use wasm_bindgen_test::*;
module.exports.trivial = function () {};
module.exports.incoming_bool = function () { return true; };
module.exports.incoming_u8 = function () { return 255; };
module.exports.incoming_i8 = function () { return -127; };
module.exports.incoming_u16 = function () { return 65535; };
module.exports.incoming_i16 = function () { return 32767; };
module.exports.incoming_u32 = function () { return 4294967295; };
module.exports.incoming_i32 = function () { return 0; };
module.exports.incoming_f32 = function () { return 1.5; };
module.exports.incoming_f64 = function () { return 13.37; };
module.exports.outgoing_u8 = function (k) { assert_eq(k, 255); };
module.exports.outgoing_i8 = function (i) { assert_eq(i, -127); };
module.exports.outgoing_u16 = function (l) { assert_eq(l, 65535); };
module.exports.outgoing_i16 = function (j) { assert_eq(j, 32767); };
module.exports.outgoing_i32 = function (x) { assert_eq(x, 0); };
module.exports.outgoing_f32 = function (y) { assert_eq(y, 1.5); };
module.exports.outgoing_f64 = function (z) { assert_eq(z, 13.37); };
@ -33,11 +43,27 @@ use wasm_bindgen_test::*;
assert_eq(v, 'hello');
return v;
};
module.exports.MyNamespace = {};
module.exports.MyNamespace.incoming_namespaced = function () { return 3.14; };
module.exports.MyNamespace.outgoing_namespaced = function (pi) { assert_eq(3.14, pi); };
")]
extern "C" {
#[wasm_bindgen(assert_no_shim)]
fn trivial();
#[wasm_bindgen(assert_no_shim)]
fn incoming_bool() -> bool;
#[wasm_bindgen(assert_no_shim)]
fn incoming_u8() -> u8;
#[wasm_bindgen(assert_no_shim)]
fn incoming_i8() -> i8;
#[wasm_bindgen(assert_no_shim)]
fn incoming_u16() -> u16;
#[wasm_bindgen(assert_no_shim)]
fn incoming_i16() -> i16;
#[wasm_bindgen(assert_no_shim)]
fn incoming_u32() -> u32;
#[wasm_bindgen(assert_no_shim)]
fn incoming_i32() -> i32;
#[wasm_bindgen(assert_no_shim)]
@ -45,6 +71,14 @@ extern "C" {
#[wasm_bindgen(assert_no_shim)]
fn incoming_f64() -> f64;
#[wasm_bindgen(assert_no_shim)]
fn outgoing_u8(k: u8);
#[wasm_bindgen(assert_no_shim)]
fn outgoing_i8(i: i8);
#[wasm_bindgen(assert_no_shim)]
fn outgoing_u16(l: u16);
#[wasm_bindgen(assert_no_shim)]
fn outgoing_i16(j: i16);
#[wasm_bindgen(assert_no_shim)]
fn outgoing_i32(x: i32);
#[wasm_bindgen(assert_no_shim)]
@ -55,6 +89,11 @@ extern "C" {
#[wasm_bindgen(assert_no_shim)]
fn many(x: i32, y: f32, z: f64) -> i32;
#[wasm_bindgen(assert_no_shim, js_namespace = MyNamespace)]
fn incoming_namespaced() -> f64;
#[wasm_bindgen(assert_no_shim, js_namespace = MyNamespace)]
fn outgoing_namespaced(x: f64);
// Note that this should only skip the JS shim if we have anyref support
// enabled.
//
@ -66,20 +105,47 @@ extern "C" {
fn no_shims() {
trivial();
let k = incoming_u8();
assert_eq!(k, 255);
outgoing_u8(k);
let l = incoming_u16();
assert_eq!(l, 65535);
outgoing_u16(l);
let m = incoming_u32();
assert_eq!(m, 4294967295);
let i = incoming_i8();
assert_eq!(i, -127);
outgoing_i8(i);
let j = incoming_i16();
assert_eq!(j, 32767);
outgoing_i16(j);
let x = incoming_i32();
assert_eq!(x, 0);
outgoing_i32(x);
let y = incoming_f32();
assert_eq!(y, 1.5);
outgoing_f32(y);
let z = incoming_f64();
assert_eq!(z, 13.37);
outgoing_i32(x);
outgoing_f32(y);
outgoing_f64(z);
let w = many(x, y, z);
assert_eq!(w, 42);
let pi = incoming_namespaced();
assert_eq!(pi, 3.14);
outgoing_namespaced(pi);
let b = incoming_bool();
assert!(b);
let v = JsValue::from("hello");
let vv = works_when_anyref_support_is_enabled(v.clone());
assert_eq!(v, vv);