Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rest and spread operators in multi-threaded code. NFC #21270

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2911,7 +2911,7 @@ addToLibrary({
// code paths as similar as possible on both sides.)
// -1 - code is the encoding of a proxied EM_ASM, as a negative number
// (positive numbers are non-EM_ASM calls).
return proxyToMainThread.apply(null, [-1 - code, sync].concat(args));
return proxyToMainThread(-1 - code, sync, ...args);
}
#endif
#if ASSERTIONS
Expand Down
16 changes: 6 additions & 10 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,21 +957,17 @@ var LibraryPThread = {
#if MEMORY64
// Calls proxyToMainThread but returns a bigint rather than a number
$proxyToMainThreadPtr__deps: ['$proxyToMainThread'],
$proxyToMainThreadPtr: function() {
return BigInt(proxyToMainThread.apply(null, arguments));
},
$proxyToMainThreadPtr: (...args) => BigInt(proxyToMainThread(...args)),
#endif

$proxyToMainThread__deps: ['$withStackSave', '_emscripten_run_on_main_thread_js'].concat(i53ConversionDeps),
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...(number|boolean))} */',
$proxyToMainThread: function(index, sync) {
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...number)} */',
$proxyToMainThread: (index, sync, ...callArgs) => {
// Additional arguments are passed after those two, which are the actual
// function arguments.
// The serialization buffer contains the number of call params, and then
// all the args here.
// We also pass 'sync' to C separately, since C needs to look at it.
var numCallArgs = arguments.length - 2;
var outerArgs = arguments;
// Allocate a buffer, which will be copied by the C code.
return withStackSave(() => {
// First passed parameter specifies the number of arguments to the function.
Expand All @@ -980,11 +976,11 @@ var LibraryPThread = {
// type info here). To do that, add a "prefix" before each value that
// indicates if it is a BigInt, which effectively doubles the number of
// values we serialize for proxying. TODO: pack this?
var serializedNumCallArgs = numCallArgs {{{ WASM_BIGINT ? "* 2" : "" }}};
var serializedNumCallArgs = callArgs.length {{{ WASM_BIGINT ? "* 2" : "" }}};
var args = stackAlloc(serializedNumCallArgs * 8);
var b = {{{ getHeapOffset('args', 'i64') }}};
for (var i = 0; i < numCallArgs; i++) {
var arg = outerArgs[2 + i];
for (var i = 0; i < callArgs.length; i++) {
var arg = callArgs[i];
#if WASM_BIGINT
if (typeof arg == 'bigint') {
// The prefix is non-zero to indicate a bigint.
Expand Down
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_pthreads.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4923
4920
2 changes: 1 addition & 1 deletion test/other/metadce/test_metadce_minimal_pthreads.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13664
13635
Loading