Skip to content

Commit 29ccf14

Browse files
committed
Merge branch 'main' into typo
2 parents 3e908ab + b53978e commit 29ccf14

23 files changed

+139
-49
lines changed

site/source/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ You can bind to C++ operators using ``[Operator=]``:
318318
.. note::
319319

320320
- The operator name can be anything (``add`` is just an example).
321-
- Support is currently limited to operators that contain ``=``: ``+=``, ``*=``, ``-=`` etc., and to the array indexing operator ``[]``.
321+
- Support is currently limited to the following binary operators: ``+``, ``-``, ``*``, ``/``, ``%``, ``^``, ``&``, ``|``, ``=``, ``<``, ``>``, ``+=``, ``-=``, ``*=``, ``/=``, ``%=``, ``^=``, ``&=``, ``|=``, ``<<``, ``>>``, ``>>=``, ``<<=``, ``==``, ``!=``, ``<=``, ``>=``, ``<=>``, ``&&``, ``||``, and to the array indexing operator ``[]``.
322322

323323

324324
enums

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,6 @@ Emit instructions for the new Wasm exception handling proposal with exnref,
11661166
which was adopted on Oct 2023. The implementation of the new proposal is
11671167
still in progress and this feature is currently experimental.
11681168

1169-
.. note:: Applicable during both linking and compilation
1170-
11711169
Default value: false
11721170

11731171
.. _nodejs_catch_exit:

src/library.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,10 +2136,24 @@ addToLibrary({
21362136
$runtimeKeepaliveCounter__internal: true,
21372137
$runtimeKeepaliveCounter: 0,
21382138

2139-
$keepRuntimeAlive__deps: ['$runtimeKeepaliveCounter'],
21402139
#if isSymbolNeeded('$noExitRuntime')
2140+
// If the `noExitRuntime` symbol is included in the build then
2141+
// keepRuntimeAlive is always conditional since its state can change
2142+
// at runtime.
2143+
$keepRuntimeAlive__deps: ['$runtimeKeepaliveCounter'],
21412144
$keepRuntimeAlive: () => noExitRuntime || runtimeKeepaliveCounter > 0,
2145+
#elif !EXIT_RUNTIME
2146+
// When `noExitRuntime` is not include and EXIT_RUNTIME=0 then we know the
2147+
// runtime can never exit (i.e. should always be kept alive).
2148+
// However for pthreads we always default to allowing the runtime to exit
2149+
// otherwise threads never exit and are not joinable.
2150+
#if PTHREADS
2151+
$keepRuntimeAlive: () => !ENVIRONMENT_IS_PTHREAD,
21422152
#else
2153+
$keepRuntimeAlive: () => true,
2154+
#endif
2155+
#else
2156+
$keepRuntimeAlive__deps: ['$runtimeKeepaliveCounter'],
21432157
$keepRuntimeAlive: () => runtimeKeepaliveCounter > 0,
21442158
#endif
21452159

src/library_wasm_worker.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,13 @@ addToLibrary({
5555
},
5656

5757
// Executes a wasm function call received via a postMessage.
58+
$_wasmWorkerRunPostMessage__deps: ['$callUserCallback'],
5859
$_wasmWorkerRunPostMessage: (e) => {
5960
// '_wsc' is short for 'wasm call', trying to use an identifier name that
6061
// will never conflict with user code
61-
#if ENVIRONMENT_MAY_BE_NODE
62-
// In Node.js environment, message event 'e' containing the actual data sent,
63-
// while in the browser environment it's contained by 'e.data'.
64-
let data = ENVIRONMENT_IS_NODE ? e : e.data;
65-
#else
6662
let data = e.data;
67-
#endif
6863
let wasmCall = data['_wsc'];
69-
wasmCall && getWasmTableEntry(wasmCall)(...data['x']);
64+
wasmCall && callUserCallback(() => getWasmTableEntry(wasmCall)(...data['x']));
7065
},
7166

7267
// src/postamble_minimal.js brings this symbol in to the build, and calls this
@@ -87,6 +82,11 @@ addToLibrary({
8782
assert(m['sz'] % 16 == 0);
8883
#endif
8984

85+
#if !MINIMAL_RUNTIME && isSymbolNeeded('$noExitRuntime')
86+
// Wasm workers basically never exit their runtime
87+
noExitRuntime = 1;
88+
#endif
89+
9090
#if STACK_OVERFLOW_CHECK >= 2
9191
// _emscripten_wasm_worker_initialize() initializes the stack for this
9292
// Worker, but it cannot call to extern __set_stack_limits() function, or
@@ -209,6 +209,12 @@ if (ENVIRONMENT_IS_WASM_WORKER
209209
#endif
210210
});
211211
worker.onmessage = _wasmWorkerRunPostMessage;
212+
#if ENVIRONMENT_MAY_BE_NODE
213+
if (ENVIRONMENT_IS_NODE) {
214+
/** @suppress {checkTypes} */
215+
worker.on('message', (msg) => worker.onmessage({ data: msg }));
216+
}
217+
#endif
212218
return _wasmWorkersID++;
213219
},
214220

@@ -226,9 +232,7 @@ if (ENVIRONMENT_IS_WASM_WORKER
226232
#if ASSERTIONS
227233
assert(!ENVIRONMENT_IS_WASM_WORKER, 'emscripten_terminate_all_wasm_workers() cannot be called from a Wasm Worker: only the main browser thread has visibility to terminate all Workers!');
228234
#endif
229-
Object.values(_wasmWorkers).forEach((worker) => {
230-
worker.terminate();
231-
});
235+
Object.values(_wasmWorkers).forEach((worker) => worker.terminate());
232236
_wasmWorkers = {};
233237
},
234238

src/runtime_pthread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (ENVIRONMENT_IS_PTHREAD) {
2727
// Create as web-worker-like an environment as we can.
2828

2929
var parentPort = worker_threads['parentPort'];
30-
parentPort.on('message', (data) => onmessage({ data: data }));
30+
parentPort.on('message', (msg) => onmessage({ data: msg }));
3131

3232
Object.assign(globalThis, {
3333
self: global,

src/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ var EXCEPTION_STACK_TRACES = false;
781781
// Emit instructions for the new Wasm exception handling proposal with exnref,
782782
// which was adopted on Oct 2023. The implementation of the new proposal is
783783
// still in progress and this feature is currently experimental.
784-
// [compile+link]
784+
// [link]
785785
var WASM_EXNREF = false;
786786

787787
// Emscripten throws an ExitStatus exception to unwind when exit() is called.

src/wasm_worker.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,19 @@ if (ENVIRONMENT_IS_NODE) {
1414

1515
var parentPort = nodeWorkerThreads.parentPort;
1616

17-
parentPort.on('message', (data) => typeof onmessage === "function" && onmessage({ data: data }));
17+
parentPort.on('message', (msg) => global.onmessage?.({ data: msg }));
18+
19+
// Weak map of handle functions to their wrapper. Used to implement
20+
// addEventListener/removeEventListener.
21+
var wrappedHandlers = new WeakMap();
22+
function wrapMsgHandler(h) {
23+
var f = wrappedHandlers.get(h)
24+
if (!f) {
25+
f = (msg) => h({data: msg});
26+
wrappedHandlers.set(h, f);
27+
}
28+
return f;
29+
}
1830

1931
var fs = require('fs');
2032
var vm = require('vm');
@@ -28,8 +40,8 @@ if (ENVIRONMENT_IS_NODE) {
2840
importScripts: (f) => vm.runInThisContext(fs.readFileSync(f, 'utf8'), {filename: f}),
2941
postMessage: (msg) => parentPort.postMessage(msg),
3042
performance: global.performance || { now: Date.now },
31-
addEventListener: (name, handler) => parentPort.on(name, handler),
32-
removeEventListener: (name, handler) => parentPort.off(name, handler),
43+
addEventListener: (name, handler) => parentPort.on(name, wrapMsgHandler(handler)),
44+
removeEventListener: (name, handler) => parentPort.off(name, wrapMsgHandler(handler)),
3345
});
3446
}
3547
#endif // ENVIRONMENT_MAY_BE_NODE
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
#include <emscripten/emscripten.h>
3+
#include <emscripten/em_js.h>
4+
#include <stdio.h>
5+
6+
// Verify that `keepRuntimeAlive()` always returns true by default (i.e. when
7+
// EXIT_RUNTIME=0).
8+
9+
EM_JS_DEPS(deps, "$keepRuntimeAlive");
10+
11+
EM_JS(void, timeout_func, (), {
12+
console.log("timeout_func: keepRuntimeAlive() ->", keepRuntimeAlive());
13+
// once this timeout is done the node process should exit with 0
14+
});
15+
16+
int main() {
17+
int keep_alive = EM_ASM_INT({
18+
setTimeout(timeout_func);
19+
return keepRuntimeAlive();
20+
});
21+
printf("main done: %d\n", keep_alive);
22+
assert(keep_alive == 1);
23+
return 0;
24+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main done: 1
2+
timeout_func: keepRuntimeAlive() -> true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
53834
1+
53730

0 commit comments

Comments
 (0)