Skip to content

Commit 1a1c303

Browse files
authored
Simplify findWasmBinary() and reduce usage of isDataURI(). NFC (#23549)
The `findWasmBinary()` function only exists when SINGLE_FILE is not true. Also, the only time `WASM_BINARY_FILE` can be a data URL is in SINGLE_FILE mode.
1 parent b31dd92 commit 1a1c303

File tree

88 files changed

+99
-109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+99
-109
lines changed

src/base64Decode.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ function base64Decode(b64) {
6060
#endif // ~WASM2JS
6161

6262
#if !MINIMAL_RUNTIME
63+
// Prefix of data URIs emitted by SINGLE_FILE and related options.
64+
var dataURIPrefix = 'data:application/octet-stream;base64,';
65+
66+
/**
67+
* Indicates whether filename is a base64 data URI.
68+
*/
69+
var isDataURI = (uri) => uri.startsWith(dataURIPrefix);
70+
6371
// If filename is a base64 data URI, parses and returns data (Buffer on node,
6472
// Uint8Array otherwise). If filename is not a base64 data URI, returns undefined.
6573
function tryParseAsDataURI(filename) {

src/preamble.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,6 @@ var runtimeInitialized = false;
140140
var runtimeExited = false;
141141
#endif
142142

143-
// Prefix of data URIs emitted by SINGLE_FILE and related options.
144-
var dataURIPrefix = 'data:application/octet-stream;base64,';
145-
146-
/**
147-
* Indicates whether filename is a base64 data URI.
148-
* @noinline
149-
*/
150-
var isDataURI = (filename) => filename.startsWith(dataURIPrefix);
151-
152143
/**
153144
* Indicates whether filename is delivered via file protocol (as opposed to http/https)
154145
* @noinline
@@ -606,18 +597,13 @@ function findWasmBinary() {
606597
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET
607598
if (Module['locateFile']) {
608599
#endif
609-
var f = '{{{ WASM_BINARY_FILE }}}';
610-
#if !SINGLE_FILE
611-
if (!isDataURI(f)) {
612-
return locateFile(f);
613-
}
614-
#endif
615-
return f;
616-
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET // In single-file mode, repeating WASM_BINARY_FILE would emit the contents again. For an Audio Worklet, we cannot use `new URL()`.
600+
return locateFile('{{{ WASM_BINARY_FILE }}}');
601+
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET // For an Audio Worklet, we cannot use `new URL()`.
617602
}
618603
#if ENVIRONMENT_MAY_BE_SHELL
619-
if (ENVIRONMENT_IS_SHELL)
604+
if (ENVIRONMENT_IS_SHELL) {
620605
return '{{{ WASM_BINARY_FILE }}}';
606+
}
621607
#endif
622608
// Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too.
623609
return new URL('{{{ WASM_BINARY_FILE }}}', import.meta.url).href;
@@ -800,9 +786,7 @@ async function instantiateArrayBuffer(binaryFile, imports) {
800786

801787
async function instantiateAsync(binary, binaryFile, imports) {
802788
#if !SINGLE_FILE
803-
if (!binary &&
804-
typeof WebAssembly.instantiateStreaming == 'function' &&
805-
!isDataURI(binaryFile)
789+
if (!binary && typeof WebAssembly.instantiateStreaming == 'function'
806790
#if ENVIRONMENT_MAY_BE_WEBVIEW
807791
// Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
808792
&& !isFileURI(binaryFile)

src/source_map_support.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ WasmSourceMap.prototype.normalizeOffset = function (offset) {
9797
}
9898

9999
var wasmSourceMapFile = '{{{ WASM_BINARY_FILE }}}.map';
100-
if (!isDataURI(wasmSourceMapFile)) {
101-
wasmSourceMapFile = locateFile(wasmSourceMapFile);
102-
}
100+
wasmSourceMapFile = locateFile(wasmSourceMapFile);
103101

104102
function getSourceMap() {
105103
var buf = readBinary(wasmSourceMapFile);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4343
1+
4248
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8357
1+
8308
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20268
1+
20171
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8341
1+
8291
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20247
1+
20150
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9363
1+
9309
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24036
1+
23939

0 commit comments

Comments
 (0)