Skip to content

Commit 6d9d7d4

Browse files
authored
Use function for ptrToString library function (#26470)
This function is referenced *very* early on in some configurations (e.g WASM_WORKERS + RUNTIME_DEBUG) so we explictly use a function here rather than an arrow function in so that is gets hoisted to the top of the scope.
1 parent f19d29c commit 6d9d7d4

File tree

8 files changed

+31
-16
lines changed

8 files changed

+31
-16
lines changed

src/lib/libcore.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ addToLibrary({
4545
// purposes in cases where new functions are created at runtime.
4646
$createNamedFunction: (name, func) => Object.defineProperty(func, 'name', { value: name }),
4747

48-
$ptrToString: (ptr) => {
48+
// This function is referenced *very* early on in some configurations
49+
// (e.g WASM_WORKERS + RUNTIME_DEBUG) so we explictly use a function here
50+
// rather than an arrow function so that it gets hoisted to the top of the
51+
// scope.
52+
$ptrToString: function(ptr) {
4953
#if ASSERTIONS
5054
assert(typeof ptr === 'number', `ptrToString expects a number, got ${typeof ptr}`);
5155
#endif

src/lib/libwasm_worker.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ if (ENVIRONMENT_IS_WASM_WORKER
219219
/** @suppress {checkTypes} */
220220
worker.on('message', (msg) => worker.onmessage({ data: msg }));
221221
}
222+
#endif
223+
#if RUNTIME_DEBUG
224+
dbg("done _emscripten_create_wasm_worker", _wasmWorkersID)
222225
#endif
223226
return _wasmWorkersID++;
224227
},

test/codesize/test_codesize_hello_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 24263,
3-
"a.out.js.gz": 8725,
2+
"a.out.js": 24271,
3+
"a.out.js.gz": 8730,
44
"a.out.nodebug.wasm": 15139,
55
"a.out.nodebug.wasm.gz": 7458,
6-
"total": 39402,
7-
"total_gz": 16183,
6+
"total": 39410,
7+
"total_gz": 16188,
88
"sent": [
99
"fd_write"
1010
],

test/codesize/test_codesize_minimal_O0.expected.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,12 +815,12 @@ async function createWasm() {
815815
}
816816
}
817817

818-
var ptrToString = (ptr) => {
818+
function ptrToString(ptr) {
819819
assert(typeof ptr === 'number', `ptrToString expects a number, got ${typeof ptr}`);
820820
// Convert to 32-bit unsigned value
821821
ptr >>>= 0;
822822
return '0x' + ptr.toString(16).padStart(8, '0');
823-
};
823+
}
824824

825825

826826

test/codesize/test_codesize_minimal_O0.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 19449,
3-
"a.out.js.gz": 7006,
2+
"a.out.js": 19457,
3+
"a.out.js.gz": 7005,
44
"a.out.nodebug.wasm": 1136,
55
"a.out.nodebug.wasm.gz": 656,
6-
"total": 20585,
7-
"total_gz": 7662,
6+
"total": 20593,
7+
"total_gz": 7661,
88
"sent": [],
99
"imports": [],
1010
"exports": [
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
2-
"hello_world.js": 57007,
3-
"hello_world.js.gz": 17736,
2+
"hello_world.js": 57005,
3+
"hello_world.js.gz": 17733,
44
"hello_world.wasm": 15139,
55
"hello_world.wasm.gz": 7458,
66
"no_asserts.js": 26576,
77
"no_asserts.js.gz": 8881,
88
"no_asserts.wasm": 12188,
99
"no_asserts.wasm.gz": 5986,
10-
"strict.js": 54825,
10+
"strict.js": 54823,
1111
"strict.js.gz": 17039,
1212
"strict.wasm": 15139,
1313
"strict.wasm.gz": 7453,
14-
"total": 180874,
15-
"total_gz": 64553
14+
"total": 180870,
15+
"total_gz": 64550
1616
}

test/test_core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9690,6 +9690,12 @@ def test_wasm_worker_hello(self):
96909690
def test_wasm_worker_malloc(self):
96919691
self.do_run_in_out_file_test('wasm_worker/malloc_wasm_worker.c', cflags=['-sWASM_WORKERS'])
96929692

9693+
@requires_pthreads
9694+
@no_sanitize('sanitizers do not support WASM_WORKERS')
9695+
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with WASM_WORKERS')
9696+
def test_wasm_worker_runtime_debug(self):
9697+
self.do_runf('wasm_worker/hello_wasm_worker.c', 'wasm worker starting ...', cflags=['-sWASM_WORKERS', '-sRUNTIME_DEBUG'])
9698+
96939699
@requires_pthreads
96949700
@no_sanitize('sanitizers do not support WASM_WORKERS')
96959701
@no_esm_integration('WASM_ESM_INTEGRATION is not compatible with WASM_WORKERS')

test/wasm_worker/hello_wasm_worker.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ void run_in_worker() {
2121
}
2222

2323
int main() {
24+
emscripten_out("in main");
2425
assert(emscripten_is_main_runtime_thread());
2526
emscripten_wasm_worker_t worker = emscripten_malloc_wasm_worker(/*stack size: */1024);
2627
assert(worker);
2728
emscripten_wasm_worker_post_function_v(worker, run_in_worker);
2829
emscripten_exit_with_live_runtime();
30+
assert(false && "should never get here");
2931
}

0 commit comments

Comments
 (0)