Skip to content

Commit 03218d9

Browse files
Support 8 argument closures.
1 parent befefe0 commit 03218d9

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

src/closure.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ doit! {
695695
(A B C D E)
696696
(A B C D E F)
697697
(A B C D E F G)
698+
(A B C D E F G H)
698699
}
699700

700701
// Copy the above impls down here for where there's only one argument and it's a

src/convert/closures.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ stack_closures! {
117117
(5 invoke5 invoke5_mut A B C D E)
118118
(6 invoke6 invoke6_mut A B C D E F)
119119
(7 invoke7 invoke7_mut A B C D E F G)
120+
(8 invoke8 invoke8_mut A B C D E F G H)
120121
}
121122

122123
impl<'a, 'b, A, R> IntoWasmAbi for &'a (Fn(&A) -> R + 'b)

tests/wasm/closures.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ exports.many_arity_call7 = a => {
4747
exports.many_arity_call8 = a => {
4848
a(1, 2, 3, 4, 5, 6, 7);
4949
};
50+
exports.many_arity_call9 = a => {
51+
a(1, 2, 3, 4, 5, 6, 7, 8);
52+
};
5053

5154
let LONG_LIVED_DROPPING_CACHE = null;
5255

tests/wasm/closures.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
fn many_arity_call6(a: &Closure<Fn(u32, u32, u32, u32, u32)>);
2626
fn many_arity_call7(a: &Closure<Fn(u32, u32, u32, u32, u32, u32)>);
2727
fn many_arity_call8(a: &Closure<Fn(u32, u32, u32, u32, u32, u32, u32)>);
28+
fn many_arity_call9(a: &Closure<Fn(u32, u32, u32, u32, u32, u32, u32, u32)>);
2829

2930
#[wasm_bindgen(js_name = many_arity_call1)]
3031
fn many_arity_call_mut1(a: &Closure<FnMut()>);
@@ -42,6 +43,8 @@ extern "C" {
4243
fn many_arity_call_mut7(a: &Closure<FnMut(u32, u32, u32, u32, u32, u32)>);
4344
#[wasm_bindgen(js_name = many_arity_call8)]
4445
fn many_arity_call_mut8(a: &Closure<FnMut(u32, u32, u32, u32, u32, u32, u32)>);
46+
#[wasm_bindgen(js_name = many_arity_call9)]
47+
fn many_arity_call_mut9(a: &Closure<FnMut(u32, u32, u32, u32, u32, u32, u32, u32)>);
4548

4649
#[wasm_bindgen(js_name = many_arity_call1)]
4750
fn many_arity_stack1(a: &Fn());
@@ -59,6 +62,8 @@ extern "C" {
5962
fn many_arity_stack7(a: &Fn(u32, u32, u32, u32, u32, u32));
6063
#[wasm_bindgen(js_name = many_arity_call8)]
6164
fn many_arity_stack8(a: &Fn(u32, u32, u32, u32, u32, u32, u32));
65+
#[wasm_bindgen(js_name = many_arity_call9)]
66+
fn many_arity_stack9(a: &Fn(u32, u32, u32, u32, u32, u32, u32, u32));
6267

6368
fn long_lived_dropping_cache(a: &Closure<Fn()>);
6469
#[wasm_bindgen(catch)]
@@ -164,6 +169,9 @@ fn many_arity() {
164169
many_arity_call8(&Closure::new(|a, b, c, d, e, f, g| {
165170
assert_eq!((a, b, c, d, e, f, g), (1, 2, 3, 4, 5, 6, 7))
166171
}));
172+
many_arity_call9(&Closure::new(|a, b, c, d, e, f, g, h| {
173+
assert_eq!((a, b, c, d, e, f, g, h), (1, 2, 3, 4, 5, 6, 7, 8))
174+
}));
167175

168176
let s = String::new();
169177
many_arity_call_mut1(&Closure::once(move || drop(s)));
@@ -202,6 +210,11 @@ fn many_arity() {
202210
drop(s);
203211
assert_eq!((a, b, c, d, e, f, g), (1, 2, 3, 4, 5, 6, 7));
204212
}));
213+
let s = String::new();
214+
many_arity_call_mut9(&Closure::once(move |a, b, c, d, e, f, g, h| {
215+
drop(s);
216+
assert_eq!((a, b, c, d, e, f, g, h), (1, 2, 3, 4, 5, 6, 7, 8));
217+
}));
205218

206219
many_arity_stack1(&(|| {}));
207220
many_arity_stack2(&(|a| assert_eq!(a, 1)));
@@ -213,6 +226,9 @@ fn many_arity() {
213226
many_arity_stack8(
214227
&(|a, b, c, d, e, f, g| assert_eq!((a, b, c, d, e, f, g), (1, 2, 3, 4, 5, 6, 7))),
215228
);
229+
many_arity_stack9(
230+
&(|a, b, c, d, e, f, g, h| assert_eq!((a, b, c, d, e, f, g, h), (1, 2, 3, 4, 5, 6, 7, 8))),
231+
);
216232
}
217233

218234
struct Dropper(Rc<Cell<bool>>);

0 commit comments

Comments
 (0)