Skip to content

Commit eee429a

Browse files
authored
Cleanup source map loading (#24967)
- Move LOAD_SOURCE_MAP to settings_internal. Its set whenever source maps are used with ASAN and really is only used internally. We have no tests that set it explicitly. - Move all code to `source_map_support.js` - Load `source_map_support.js` during postamble. This does run under `MINIMAL_RUNTIME`, but `LOAD_SOURCE_MAP` has always been no-op on `MINIMAL_RUNTIME` anyway.
1 parent b4a7e77 commit eee429a

File tree

8 files changed

+37
-50
lines changed

8 files changed

+37
-50
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ See docs/process.md for more on how version tagging works.
2020

2121
4.0.14 (in development)
2222
-----------------------
23+
- The `LOAD_SOURCE_MAP` setting was made an internal setting. This was always
24+
an internal detail of the sanitizers, which is enabled automatically when
25+
needed, so setting it explicitly should never be needed. (#24967)
2326
- The wasm offset converter was removed along with the `WASM_OFFSET_CONVERTER`
2427
setting. This feature only existed to work around an old v8 bug that was fixed
2528
back in 2019. (#24963)

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,16 +3053,6 @@ future release.
30533053

30543054
Default value: -1
30553055

3056-
.. _load_source_map:
3057-
3058-
LOAD_SOURCE_MAP
3059-
===============
3060-
3061-
Whether we should load the WASM source map at runtime.
3062-
This is enabled automatically when using -gsource-map with sanitizers.
3063-
3064-
Default value: false
3065-
30663056
.. _source_map_prefixes:
30673057

30683058
SOURCE_MAP_PREFIXES

src/postamble.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ if (ENVIRONMENT_IS_WORKER) {
1313
}
1414
#endif
1515

16+
#if LOAD_SOURCE_MAP
17+
#include "source_map_support.js"
18+
#endif
19+
1620
#if DETERMINISTIC
1721
#include "deterministic.js"
1822
#endif

src/preamble.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -410,25 +410,6 @@ function instrumentWasmTableWithAbort() {
410410
}
411411
#endif
412412

413-
#if LOAD_SOURCE_MAP
414-
function receiveSourceMapJSON(sourceMap) {
415-
wasmSourceMap = new WasmSourceMap(sourceMap);
416-
{{{ runIfMainThread("removeRunDependency('source-map');") }}}
417-
}
418-
#endif
419-
420-
#if (PTHREADS || WASM_WORKERS) && LOAD_SOURCE_MAP
421-
// When using postMessage to send an object, it is processed by the structured
422-
// clone algorithm. The prototype, and hence methods, on that object is then
423-
// lost. This function adds back the lost prototype. This does not work with
424-
// nested objects that has prototypes, but it suffices for WasmSourceMap and
425-
// WasmOffsetConverter.
426-
function resetPrototype(constructor, attrs) {
427-
var object = Object.create(constructor.prototype);
428-
return Object.assign(object, attrs);
429-
}
430-
#endif
431-
432413
#if !SOURCE_PHASE_IMPORTS && !WASM_ESM_INTEGRATION
433414
var wasmBinaryFile;
434415

@@ -557,9 +538,6 @@ function instantiateSync(file, info) {
557538
module = new WebAssembly.Module(binary);
558539
#endif // NODE_CODE_CACHING
559540
var instance = new WebAssembly.Instance(module, info);
560-
#if LOAD_SOURCE_MAP
561-
receiveSourceMapJSON(getSourceMap());
562-
#endif
563541
return [instance, module];
564542
}
565543
#endif
@@ -785,10 +763,6 @@ function getWasmImports() {
785763
addRunDependency('wasm-instantiate');
786764
#endif
787765

788-
#if LOAD_SOURCE_MAP
789-
{{{ runIfMainThread("addRunDependency('source-map');") }}}
790-
#endif
791-
792766
// Prefer streaming instantiation if available.
793767
#if WASM_ASYNC_COMPILATION
794768
#if ASSERTIONS
@@ -865,9 +839,6 @@ function getWasmImports() {
865839
#endif
866840
var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
867841
var exports = receiveInstantiationResult(result);
868-
#if LOAD_SOURCE_MAP
869-
receiveSourceMapJSON(await getSourceMapAsync());
870-
#endif
871842
return exports;
872843
#else // WASM_ASYNC_COMPILATION
873844
var result = instantiateSync(wasmBinaryFile, info);

src/runtime_common.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ if (ENVIRONMENT_IS_NODE && {{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) {
5555
#include "audio_worklet.js"
5656
#endif
5757

58-
#if LOAD_SOURCE_MAP
59-
var wasmSourceMap;
60-
#include "source_map_support.js"
61-
#endif
62-
6358
// Memory management
6459

6560
#if !WASM_ESM_INTEGRATION || IMPORTED_MEMORY

src/settings.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,10 +2006,6 @@ var MINIFY_HTML = true;
20062006
// [link]
20072007
var ASAN_SHADOW_SIZE = -1;
20082008

2009-
// Whether we should load the WASM source map at runtime.
2010-
// This is enabled automatically when using -gsource-map with sanitizers.
2011-
var LOAD_SOURCE_MAP = false;
2012-
20132009
// List of path substitutions to apply in the "sources" field of the source map.
20142010
// Corresponds to the ``--prefix`` option used in ``tools/wasm-sourcemap.py``.
20152011
// Must be used with ``-gsource-map``.

src/settings_internal.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,7 @@ var INCLUDE_WEBGL1_FALLBACK = true;
272272
var MINIFICATION_MAP = '';
273273

274274
var OUTPUT_FORMAT = '';
275+
276+
// Whether we should load the WASM source map at runtime.
277+
// This is enabled automatically when using -gsource-map with sanitizers.
278+
var LOAD_SOURCE_MAP = false;

src/source_map_support.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ class WasmSourceMap {
9090
}
9191
}
9292

93-
var wasmSourceMapFile = '{{{ WASM_BINARY_FILE }}}.map';
94-
wasmSourceMapFile = locateFile(wasmSourceMapFile);
93+
var wasmSourceMap;
94+
var wasmSourceMapFile = locateFile('{{{ WASM_BINARY_FILE }}}.map');
95+
96+
function receiveSourceMapJSON(sourceMap) {
97+
wasmSourceMap = new WasmSourceMap(sourceMap);
98+
}
9599

96100
function getSourceMap() {
97101
var buf = readBinary(wasmSourceMapFile);
@@ -109,3 +113,23 @@ async function getSourceMapAsync() {
109113
}
110114
return getSourceMap();
111115
}
116+
117+
118+
#if PTHREADS || WASM_WORKERS
119+
// Source map is received via postMessage on worker threads.
120+
if ({{{ ENVIRONMENT_IS_MAIN_THREAD() }}}) {
121+
#endif
122+
123+
#if WASM_ASYNC_COMPILATION
124+
addRunDependency('source-map');
125+
getSourceMapAsync().then((json) => {
126+
receiveSourceMapJSON(json);
127+
removeRunDependency('source-map');
128+
});
129+
#else
130+
receiveSourceMapJSON(getSourceMap());
131+
#endif
132+
133+
#if PTHREADS || WASM_WORKERS
134+
}
135+
#endif

0 commit comments

Comments
 (0)