mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-07-31 03:51:56 +00:00
Merge pull request #792 from afdw/master
Add support for variadic arguments in WebIDL
This commit is contained in:
@@ -110,6 +110,13 @@ global.OptionalAndUnionArguments = class OptionalAndUnionArguments {
|
||||
}
|
||||
};
|
||||
|
||||
global.Variadic = class Variadic {
|
||||
constructor() {}
|
||||
sum(...values) {
|
||||
return values.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
};
|
||||
|
||||
global.PartialInterface = class PartialInterface {
|
||||
get un() {
|
||||
return 1;
|
||||
|
@@ -94,6 +94,24 @@ fn optional_and_union_arguments() {
|
||||
assert_eq!(f.m_with_b_and_str_and_opt_bool("abc", false, "5", Some(true)), "string, abc, boolean, false, string, 5, boolean, true");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn variadic() {
|
||||
let f = Variadic::new().unwrap();
|
||||
assert_eq!(f.sum_5(1, 2, 3, 4, 5), 15);
|
||||
assert_eq!(
|
||||
f.sum(
|
||||
&::js_sys::Array::of5(
|
||||
&JsValue::from_f64(1f64),
|
||||
&JsValue::from_f64(2f64),
|
||||
&JsValue::from_f64(3f64),
|
||||
&JsValue::from_f64(4f64),
|
||||
&JsValue::from_f64(5f64),
|
||||
)
|
||||
),
|
||||
15
|
||||
);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn unforgeable_is_structural() {
|
||||
let f = Unforgeable::new().unwrap();
|
||||
|
5
crates/webidl-tests/simple.webidl
vendored
5
crates/webidl-tests/simple.webidl
vendored
@@ -57,6 +57,11 @@ interface OptionalAndUnionArguments {
|
||||
);
|
||||
};
|
||||
|
||||
[Constructor()]
|
||||
interface Variadic {
|
||||
short sum(short... values);
|
||||
};
|
||||
|
||||
[Constructor()]
|
||||
interface Unforgeable {
|
||||
[Unforgeable] readonly attribute short uno;
|
||||
|
Reference in New Issue
Block a user