Skip to content

Commit 7125c45

Browse files
authored
Add source map loading support to MINIMAL_RUNTIME. (#25324)
Fixes minimal0.test_ubsan_full_stack_trace_gsource_map
1 parent 637a1e1 commit 7125c45

File tree

6 files changed

+54
-12
lines changed

6 files changed

+54
-12
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ jobs:
751751
wasmfs.test_fs_llseek_rawfs
752752
wasmfs.test_freetype
753753
minimal0.test_utf
754+
minimal0.test_ubsan_full_stack_trace_gsource_map
754755
minimal0.test_static_variable
755756
minimal0.test_stack_overflow
756757
omitexports0.test_asyncify_longjmp

src/postamble.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if PROXY_TO_WORKER
1010
if (ENVIRONMENT_IS_WORKER) {
11-
#include "webGLWorker.js'
11+
#include "webGLWorker.js"
1212
#include "proxyWorker.js"
1313
}
1414
#endif

src/postamble_minimal.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7+
#if LOAD_SOURCE_MAP
8+
#include "source_map_support.js"
9+
#endif
10+
711
// === Auto-generated postamble setup entry stuff ===
812
#if HAS_MAIN // Only if user is exporting a C main(), we will generate a run() function that can be used to launch main.
913

@@ -267,16 +271,33 @@ WebAssembly.instantiate(Module['wasm'], imports).then(/** @suppress {missingProp
267271

268272
initRuntime(wasmExports);
269273

270-
#if PTHREADS && PTHREAD_POOL_SIZE
271-
var workersReady = PThread.loadWasmModuleToAllWorkers();
272-
#if PTHREAD_POOL_DELAY_LOAD
273-
ready();
274-
#else
275-
workersReady.then(ready);
276-
#endif
277-
#else
278-
ready();
274+
{{{ function waitOnStartupPromisesAndEmitReady() {
275+
var promises = [];
276+
if (PTHREADS && PTHREAD_POOL_SIZE) {
277+
promises.push('PThread.loadWasmModuleToAllWorkers()');
278+
}
279+
if (LOAD_SOURCE_MAP) {
280+
promises.push('getSourceMapAsync().then(json=>{receiveSourceMapJSON(json)})');
281+
}
282+
if (promises.length == 0) {
283+
return 'ready();'
284+
} else if (promises.length == 1) {
285+
return `${promises[0]}.then(ready);`;
286+
} else {
287+
return `Promise.all(${', '.join(promises)}).then(ready);`
288+
}
289+
}
290+
null;
291+
}}}
292+
293+
#if PTHREADS && PTHREAD_POOL_SIZE && PTHREAD_POOL_DELAY_LOAD
294+
// In PTHREAD_POOL_DELAY_LOAD mode, we kick off loading Wasm Module to all
295+
// PThread Workers, but do not wait on it.
296+
PThread.loadWasmModuleToAllWorkers();
279297
#endif
298+
299+
{{{ waitOnStartupPromisesAndEmitReady(); }}}
300+
280301
}
281302

282303
#if WASM == 2

src/shell_minimal.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,19 @@ function ready() {
130130
#endif
131131
}
132132

133+
#if ENVIRONMENT_MAY_BE_NODE
134+
var isFileURI = (filename) => filename.startsWith('file://');
135+
var readAsync, readBinary;
136+
#include "node_shell_read.js"
137+
#endif
138+
139+
#if ENVIRONMENT_MAY_BE_WORKER || PTHREADS
140+
var ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope;
141+
#endif
142+
133143
#if PTHREADS
134144
// MINIMAL_RUNTIME does not support --proxy-to-worker option, so Worker and Pthread environments
135145
// coincide.
136-
var ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope;
137146
var ENVIRONMENT_IS_PTHREAD = ENVIRONMENT_IS_WORKER && self.name?.startsWith('em-pthread');
138147

139148
#if !MODULARIZE

src/source_map_support.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ class WasmSourceMap {
9191
}
9292

9393
var wasmSourceMap;
94+
#if MINIMAL_RUNTIME
95+
var wasmSourceMapFile = '{{{ WASM_BINARY_FILE }}}.map';
96+
#else
9497
var wasmSourceMapFile = locateFile('{{{ WASM_BINARY_FILE }}}.map');
98+
#endif
9599

96100
function receiveSourceMapJSON(sourceMap) {
97101
wasmSourceMap = new WasmSourceMap(sourceMap);
@@ -103,7 +107,11 @@ function getSourceMap() {
103107
}
104108

105109
async function getSourceMapAsync() {
106-
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
110+
if (ENVIRONMENT_IS_WEB
111+
#if ENVIRONMENT_MAY_BE_WORKER
112+
|| ENVIRONMENT_IS_WORKER
113+
#endif
114+
) {
107115
try {
108116
var response = await fetch(wasmSourceMapFile, {{{ makeModuleReceiveExpr('fetchSettings', "{ credentials: 'same-origin' }") }}});
109117
return response.json();
@@ -120,6 +128,7 @@ async function getSourceMapAsync() {
120128
if ({{{ ENVIRONMENT_IS_MAIN_THREAD() }}}) {
121129
#endif
122130

131+
#if !MINIMAL_RUNTIME // MINIMAL_RUNTIME integrates source map loading into postamble_minimal.js
123132
#if WASM_ASYNC_COMPILATION
124133
addRunDependency('source-map');
125134
getSourceMapAsync().then((json) => {
@@ -129,6 +138,7 @@ getSourceMapAsync().then((json) => {
129138
#else
130139
receiveSourceMapJSON(getSourceMap());
131140
#endif
141+
#endif
132142

133143
#if PTHREADS || WASM_WORKERS
134144
}

test/test_other.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9953,6 +9953,7 @@ def test_check_sourcemapurl_default(self, *args):
99539953
source_mapping_url_content = webassembly.to_leb(len('sourceMappingURL')) + b'sourceMappingURL' + webassembly.to_leb(len('a.wasm.map')) + b'a.wasm.map'
99549954
self.assertIn(source_mapping_url_content, output)
99559955

9956+
@also_with_minimal_runtime
99569957
@parameterized({
99579958
'': ([], [], []),
99589959
'prefix_wildcard': ([], ['--prefix', '=wasm-src://'], []),

0 commit comments

Comments
 (0)