Skip to content

Commit f8bbf16

Browse files
committed
Use rest and spread operators in multi-threaded code. NFC
These operators are available everywhere that we can run mutli-threaded code.
1 parent 97053db commit f8bbf16

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2911,7 +2911,7 @@ addToLibrary({
29112911
// code paths as similar as possible on both sides.)
29122912
// -1 - code is the encoding of a proxied EM_ASM, as a negative number
29132913
// (positive numbers are non-EM_ASM calls).
2914-
return proxyToMainThread.apply(null, [-1 - code, sync].concat(args));
2914+
return proxyToMainThread(-1 - code, sync, ...args);
29152915
}
29162916
#endif
29172917
#if ASSERTIONS

src/library_pthread.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -957,21 +957,19 @@ var LibraryPThread = {
957957
#if MEMORY64
958958
// Calls proxyToMainThread but returns a bigint rather than a number
959959
$proxyToMainThreadPtr__deps: ['$proxyToMainThread'],
960-
$proxyToMainThreadPtr: function() {
961-
return BigInt(proxyToMainThread.apply(null, arguments));
960+
$proxyToMainThreadPtr: (...args) {
961+
return BigInt(proxyToMainThread(...args));
962962
},
963963
#endif
964964
965965
$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_on_main_thread_js'].concat(i53ConversionDeps),
966-
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...(number|boolean))} */',
967-
$proxyToMainThread: function(index, sync) {
966+
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...number)} */',
967+
$proxyToMainThread: (index, sync, ...callArgs) => {
968968
// Additional arguments are passed after those two, which are the actual
969969
// function arguments.
970970
// The serialization buffer contains the number of call params, and then
971971
// all the args here.
972972
// We also pass 'sync' to C separately, since C needs to look at it.
973-
var numCallArgs = arguments.length - 2;
974-
var outerArgs = arguments;
975973
// Allocate a buffer, which will be copied by the C code.
976974
return withStackSave(() => {
977975
// First passed parameter specifies the number of arguments to the function.
@@ -980,11 +978,11 @@ var LibraryPThread = {
980978
// type info here). To do that, add a "prefix" before each value that
981979
// indicates if it is a BigInt, which effectively doubles the number of
982980
// values we serialize for proxying. TODO: pack this?
983-
var serializedNumCallArgs = numCallArgs {{{ WASM_BIGINT ? "* 2" : "" }}};
981+
var serializedNumCallArgs = callArgs.length {{{ WASM_BIGINT ? "* 2" : "" }}};
984982
var args = stackAlloc(serializedNumCallArgs * 8);
985983
var b = {{{ getHeapOffset('args', 'i64') }}};
986-
for (var i = 0; i < numCallArgs; i++) {
987-
var arg = outerArgs[2 + i];
984+
for (var i = 0; i < callArgs.length; i++) {
985+
var arg = callArgs[i];
988986
#if WASM_BIGINT
989987
if (typeof arg == 'bigint') {
990988
// The prefix is non-zero to indicate a bigint.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4923
1+
4920
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13664
1+
13635

0 commit comments

Comments
 (0)