mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-13 13:01:22 +00:00
Fix tagging static methods as structural
This commit is contained in:
@ -1979,17 +1979,20 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
|||||||
match &op.kind {
|
match &op.kind {
|
||||||
decode::OperationKind::Regular => {
|
decode::OperationKind::Regular => {
|
||||||
let nargs = descriptor.unwrap_function().arguments.len();
|
let nargs = descriptor.unwrap_function().arguments.len();
|
||||||
|
let nargs = nargs - if op.is_static { 0 } else { 1 };
|
||||||
let mut s = format!("function(");
|
let mut s = format!("function(");
|
||||||
for i in 0..nargs - 1 {
|
for i in 0..nargs {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
drop(write!(s, ", "));
|
drop(write!(s, ", "));
|
||||||
}
|
}
|
||||||
drop(write!(s, "x{}", i));
|
drop(write!(s, "x{}", i));
|
||||||
}
|
}
|
||||||
s.push_str(") { \nreturn this.");
|
s.push_str(") { \nreturn ");
|
||||||
|
s.push_str(&location);
|
||||||
|
s.push_str(".");
|
||||||
s.push_str(&import.function.name);
|
s.push_str(&import.function.name);
|
||||||
s.push_str("(");
|
s.push_str("(");
|
||||||
for i in 0..nargs - 1 {
|
for i in 0..nargs {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
drop(write!(s, ", "));
|
drop(write!(s, ", "));
|
||||||
}
|
}
|
||||||
|
@ -131,3 +131,9 @@ exports.CatchConstructors = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.StaticStructural = class {
|
||||||
|
static static_structural(x) {
|
||||||
|
return x + 3;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -84,6 +84,10 @@ extern "C" {
|
|||||||
type CatchConstructors;
|
type CatchConstructors;
|
||||||
#[wasm_bindgen(constructor, catch)]
|
#[wasm_bindgen(constructor, catch)]
|
||||||
fn new(x: u32) -> Result<CatchConstructors, JsValue>;
|
fn new(x: u32) -> Result<CatchConstructors, JsValue>;
|
||||||
|
|
||||||
|
type StaticStructural;
|
||||||
|
#[wasm_bindgen(static_method_of = StaticStructural, structural)]
|
||||||
|
fn static_structural(a: u32) -> u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
@ -213,3 +217,8 @@ fn catch_constructors() {
|
|||||||
assert!(CatchConstructors::new(0).is_err());
|
assert!(CatchConstructors::new(0).is_err());
|
||||||
assert!(CatchConstructors::new(1).is_ok());
|
assert!(CatchConstructors::new(1).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn static_structural() {
|
||||||
|
assert_eq!(StaticStructural::static_structural(30), 33);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user