Skip to content

Commit 31e823d

Browse files
authored
Use rest and spread operators in multi-threaded code. NFC (#21270)
These operators are available everywhere that we can run mutli-threaded code.
1 parent 3495d9a commit 31e823d

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
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: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -957,21 +957,17 @@ 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));
962-
},
960+
$proxyToMainThreadPtr: (...args) => BigInt(proxyToMainThread(...args)),
963961
#endif
964962
965963
$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) {
964+
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...number)} */',
965+
$proxyToMainThread: (index, sync, ...callArgs) => {
968966
// Additional arguments are passed after those two, which are the actual
969967
// function arguments.
970968
// The serialization buffer contains the number of call params, and then
971969
// all the args here.
972970
// We also pass 'sync' to C separately, since C needs to look at it.
973-
var numCallArgs = arguments.length - 2;
974-
var outerArgs = arguments;
975971
// Allocate a buffer, which will be copied by the C code.
976972
return withStackSave(() => {
977973
// First passed parameter specifies the number of arguments to the function.
@@ -980,11 +976,11 @@ var LibraryPThread = {
980976
// type info here). To do that, add a "prefix" before each value that
981977
// indicates if it is a BigInt, which effectively doubles the number of
982978
// values we serialize for proxying. TODO: pack this?
983-
var serializedNumCallArgs = numCallArgs {{{ WASM_BIGINT ? "* 2" : "" }}};
979+
var serializedNumCallArgs = callArgs.length {{{ WASM_BIGINT ? "* 2" : "" }}};
984980
var args = stackAlloc(serializedNumCallArgs * 8);
985981
var b = {{{ getHeapOffset('args', 'i64') }}};
986-
for (var i = 0; i < numCallArgs; i++) {
987-
var arg = outerArgs[2 + i];
982+
for (var i = 0; i < callArgs.length; i++) {
983+
var arg = callArgs[i];
988984
#if WASM_BIGINT
989985
if (typeof arg == 'bigint') {
990986
// 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)