Skip to content

Commit a3e6c90

Browse files
authored
Make use of rest operator in library_dylink.js. NFC (#21990)
1 parent ba5a64d commit a3e6c90

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

src/library_dylink.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,30 @@ var LibraryDylink = {
7373
#if !DISABLE_EXCEPTION_CATCHING || SUPPORT_LONGJMP == 'emscripten'
7474
$createInvokeFunction__internal: true,
7575
$createInvokeFunction__deps: ['$dynCall', 'setThrew', '$stackSave', '$stackRestore'],
76-
$createInvokeFunction: (sig) => {
77-
return function() {
78-
var sp = stackSave();
79-
try {
80-
return dynCall(sig, arguments[0], Array.prototype.slice.call(arguments, 1));
81-
} catch(e) {
82-
stackRestore(sp);
83-
// Create a try-catch guard that rethrows the Emscripten EH exception.
76+
$createInvokeFunction: (sig) => (ptr, ...args) => {
77+
var sp = stackSave();
78+
try {
79+
return dynCall(sig, ptr, args);
80+
} catch(e) {
81+
stackRestore(sp);
82+
// Create a try-catch guard that rethrows the Emscripten EH exception.
8483
#if EXCEPTION_STACK_TRACES
85-
// Exceptions thrown from C++ and longjmps will be an instance of
86-
// EmscriptenEH.
87-
if (!(e instanceof EmscriptenEH)) throw e;
84+
// Exceptions thrown from C++ and longjmps will be an instance of
85+
// EmscriptenEH.
86+
if (!(e instanceof EmscriptenEH)) throw e;
8887
#else
89-
// Exceptions thrown from C++ will be a pointer (number) and longjmp
90-
// will throw the number Infinity. Use the compact and fast "e !== e+0"
91-
// test to check if e was not a Number.
92-
if (e !== e+0) throw e;
93-
#endif
94-
_setThrew(1, 0);
95-
#if WASM_BIGINT
96-
// In theory this if statement could be done on
97-
// creating the function, but I just added this to
98-
// save wasting code space as it only happens on exception.
99-
if (sig[0] == "j") return 0n;
100-
#endif
101-
}
88+
// Exceptions thrown from C++ will be a pointer (number) and longjmp
89+
// will throw the number Infinity. Use the compact and fast "e !== e+0"
90+
// test to check if e was not a Number.
91+
if (e !== e+0) throw e;
92+
#endif
93+
_setThrew(1, 0);
94+
#if WASM_BIGINT
95+
// In theory this if statement could be done on
96+
// creating the function, but I just added this to
97+
// save wasting code space as it only happens on exception.
98+
if (sig[0] == "j") return 0n;
99+
#endif
102100
}
103101
},
104102
#endif
@@ -140,8 +138,7 @@ var LibraryDylink = {
140138
// `__cxa_find_matching_catch_` (see jsifier.js) that we know are needed,
141139
// but a side module loaded at runtime might need different/additional
142140
// variants so we create those dynamically.
143-
sym = wasmImports[symName] = function() {
144-
var args = Array.from(arguments);
141+
sym = wasmImports[symName] = (...args) => {
145142
#if MEMORY64
146143
args = args.map(Number);
147144
#endif

0 commit comments

Comments
 (0)