Skip to content

Commit e95d3fa

Browse files
committed
Assert that a bunch more function signatures don't require JS glue
1 parent 7428b73 commit e95d3fa

File tree

4 files changed

+80
-10
lines changed

4 files changed

+80
-10
lines changed

crates/cli-support/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ wasm-bindgen-anyref-xform = { path = '../anyref-xform', version = '=0.2.48' }
2323
wasm-bindgen-shared = { path = "../shared", version = '=0.2.48' }
2424
wasm-bindgen-threads-xform = { path = '../threads-xform', version = '=0.2.48' }
2525
wasm-bindgen-wasm-interpreter = { path = "../wasm-interpreter", version = '=0.2.48' }
26-
wasm-webidl-bindings = "0.1.0"
26+
wasm-webidl-bindings = "0.1.1"

crates/cli-support/src/js/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,11 @@ impl<'a> Context<'a> {
20012001
if assert_no_shim {
20022002
panic!(
20032003
"imported function was annotated with `#[wasm_bindgen(assert_no_shim)]` \
2004-
but we need to generate a JS shim for it"
2004+
but we need to generate a JS shim for it:\n\n\
2005+
\timport = {:?}\n\n\
2006+
\tbinding = {:?}\n\n\
2007+
\twebidl = {:?}",
2008+
import, binding, webidl,
20052009
);
20062010
}
20072011

tests/wasm/math.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ extern "C" {
1010
// return value is always `f64` to faithfully capture what was sent to JS
1111
// (what we're interested in) because all JS numbers fit in `f64` anyway.
1212
// This is testing what happens when we pass numbers to JS and what it sees.
13-
#[wasm_bindgen(js_name = roundtrip)]
13+
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
1414
fn roundtrip_i8(a: i8) -> f64;
15-
#[wasm_bindgen(js_name = roundtrip)]
15+
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
1616
fn roundtrip_i16(a: i16) -> f64;
17-
#[wasm_bindgen(js_name = roundtrip)]
17+
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
1818
fn roundtrip_i32(a: i32) -> f64;
19-
#[wasm_bindgen(js_name = roundtrip)]
19+
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
2020
fn roundtrip_u8(a: u8) -> f64;
21-
#[wasm_bindgen(js_name = roundtrip)]
21+
#[wasm_bindgen(assert_no_shim, js_name = roundtrip)]
2222
fn roundtrip_u16(a: u16) -> f64;
2323
#[wasm_bindgen(js_name = roundtrip)]
2424
fn roundtrip_u32(a: u32) -> f64;

tests/wasm/no_shims.rs

+69-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ use wasm_bindgen_test::*;
1414
1515
module.exports.trivial = function () {};
1616
17+
module.exports.incoming_bool = function () { return true; };
18+
module.exports.incoming_u8 = function () { return 255; };
19+
module.exports.incoming_i8 = function () { return -127; };
20+
module.exports.incoming_u16 = function () { return 65535; };
21+
module.exports.incoming_i16 = function () { return 32767; };
22+
module.exports.incoming_u32 = function () { return 4294967295; };
1723
module.exports.incoming_i32 = function () { return 0; };
1824
module.exports.incoming_f32 = function () { return 1.5; };
1925
module.exports.incoming_f64 = function () { return 13.37; };
2026
27+
module.exports.outgoing_u8 = function (k) { assert_eq(k, 255); };
28+
module.exports.outgoing_i8 = function (i) { assert_eq(i, -127); };
29+
module.exports.outgoing_u16 = function (l) { assert_eq(l, 65535); };
30+
module.exports.outgoing_i16 = function (j) { assert_eq(j, 32767); };
2131
module.exports.outgoing_i32 = function (x) { assert_eq(x, 0); };
2232
module.exports.outgoing_f32 = function (y) { assert_eq(y, 1.5); };
2333
module.exports.outgoing_f64 = function (z) { assert_eq(z, 13.37); };
@@ -33,18 +43,42 @@ use wasm_bindgen_test::*;
3343
assert_eq(v, 'hello');
3444
return v;
3545
};
46+
47+
module.exports.MyNamespace = {};
48+
module.exports.MyNamespace.incoming_namespaced = function () { return 3.14; };
49+
module.exports.MyNamespace.outgoing_namespaced = function (pi) { assert_eq(3.14, pi); };
3650
")]
3751
extern "C" {
3852
#[wasm_bindgen(assert_no_shim)]
3953
fn trivial();
4054

55+
#[wasm_bindgen(assert_no_shim)]
56+
fn incoming_bool() -> bool;
57+
#[wasm_bindgen(assert_no_shim)]
58+
fn incoming_u8() -> u8;
59+
#[wasm_bindgen(assert_no_shim)]
60+
fn incoming_i8() -> i8;
61+
#[wasm_bindgen(assert_no_shim)]
62+
fn incoming_u16() -> u16;
63+
#[wasm_bindgen(assert_no_shim)]
64+
fn incoming_i16() -> i16;
65+
#[wasm_bindgen(assert_no_shim)]
66+
fn incoming_u32() -> u32;
4167
#[wasm_bindgen(assert_no_shim)]
4268
fn incoming_i32() -> i32;
4369
#[wasm_bindgen(assert_no_shim)]
4470
fn incoming_f32() -> f32;
4571
#[wasm_bindgen(assert_no_shim)]
4672
fn incoming_f64() -> f64;
4773

74+
#[wasm_bindgen(assert_no_shim)]
75+
fn outgoing_u8(k: u8);
76+
#[wasm_bindgen(assert_no_shim)]
77+
fn outgoing_i8(i: i8);
78+
#[wasm_bindgen(assert_no_shim)]
79+
fn outgoing_u16(l: u16);
80+
#[wasm_bindgen(assert_no_shim)]
81+
fn outgoing_i16(j: i16);
4882
#[wasm_bindgen(assert_no_shim)]
4983
fn outgoing_i32(x: i32);
5084
#[wasm_bindgen(assert_no_shim)]
@@ -55,6 +89,11 @@ extern "C" {
5589
#[wasm_bindgen(assert_no_shim)]
5690
fn many(x: i32, y: f32, z: f64) -> i32;
5791

92+
#[wasm_bindgen(assert_no_shim, js_namespace = MyNamespace)]
93+
fn incoming_namespaced() -> f64;
94+
#[wasm_bindgen(assert_no_shim, js_namespace = MyNamespace)]
95+
fn outgoing_namespaced(x: f64);
96+
5897
// Note that this should only skip the JS shim if we have anyref support
5998
// enabled.
6099
//
@@ -66,20 +105,47 @@ extern "C" {
66105
fn no_shims() {
67106
trivial();
68107

108+
let k = incoming_u8();
109+
assert_eq!(k, 255);
110+
outgoing_u8(k);
111+
112+
let l = incoming_u16();
113+
assert_eq!(l, 65535);
114+
outgoing_u16(l);
115+
116+
let m = incoming_u32();
117+
assert_eq!(m, 4294967295);
118+
119+
let i = incoming_i8();
120+
assert_eq!(i, -127);
121+
outgoing_i8(i);
122+
123+
let j = incoming_i16();
124+
assert_eq!(j, 32767);
125+
outgoing_i16(j);
126+
69127
let x = incoming_i32();
70128
assert_eq!(x, 0);
129+
outgoing_i32(x);
130+
71131
let y = incoming_f32();
72132
assert_eq!(y, 1.5);
133+
outgoing_f32(y);
134+
73135
let z = incoming_f64();
74136
assert_eq!(z, 13.37);
75-
76-
outgoing_i32(x);
77-
outgoing_f32(y);
78137
outgoing_f64(z);
79138

80139
let w = many(x, y, z);
81140
assert_eq!(w, 42);
82141

142+
let pi = incoming_namespaced();
143+
assert_eq!(pi, 3.14);
144+
outgoing_namespaced(pi);
145+
146+
let b = incoming_bool();
147+
assert!(b);
148+
83149
let v = JsValue::from("hello");
84150
let vv = works_when_anyref_support_is_enabled(v.clone());
85151
assert_eq!(v, vv);

0 commit comments

Comments
 (0)