Skip to content

Commit aaa5f68

Browse files
committed
Avoid repeating wasm data in SINGLE_FILE mode with closure. NFC
This change removes the `wasmBinaryFile` global in SINGLE_FILE mode. Instead the `wasmBinaryFile` is inlined into the `createWasm` function. As part of this change we now also use the same embedding method as is used in `MINIMAL_RUNTIME`, avoiding the need for the `tryParseAsDataURI` helper. Fixes: #23938
1 parent a14f471 commit aaa5f68

File tree

81 files changed

+91
-123
lines changed

Some content is hidden

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

81 files changed

+91
-123
lines changed

src/lib/libbase64.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,4 @@ addToLibrary({
4343
}
4444
return output;
4545
},
46-
47-
// Prefix of data URIs emitted by SINGLE_FILE and related options.
48-
// Double quotes here needed, othersise jsifier will not include any in the
49-
// output.
50-
$dataURIPrefix: "'data:application/octet-stream;base64,'",
51-
52-
/**
53-
* Indicates whether filename is a base64 data URI.
54-
*/
55-
$isDataURI: (filename) => filename.startsWith(dataURIPrefix),
56-
57-
// If filename is a base64 data URI, parses and returns data (Buffer on node,
58-
// Uint8Array otherwise). If filename is not a base64 data URI, returns
59-
// undefined.
60-
$tryParseAsDataURI__deps: ['$base64Decode', '$isDataURI', '$dataURIPrefix'],
61-
$tryParseAsDataURI: (filename) => {
62-
if (isDataURI(filename)) {
63-
return base64Decode(filename.slice(dataURIPrefix.length));
64-
}
65-
},
6646
});

src/preamble.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -578,13 +578,12 @@ function resetPrototype(constructor, attrs) {
578578
#endif
579579

580580
#if !SOURCE_PHASE_IMPORTS
581-
#if SINGLE_FILE
582-
// In SINGLE_FILE mode the wasm binary is encoded inline here as a data: URL.
583-
var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}';
584-
#else
585581
var wasmBinaryFile;
586582

587583
function findWasmBinary() {
584+
#if SINGLE_FILE && WASM == 1 && !WASM2JS
585+
return base64Decode('<<< WASM_BINARY_DATA >>>');
586+
#else
588587
#if EXPORT_ES6 && !AUDIO_WORKLET
589588
if (Module['locateFile']) {
590589
#endif
@@ -599,18 +598,19 @@ function findWasmBinary() {
599598
// Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too.
600599
return new URL('{{{ WASM_BINARY_FILE }}}', import.meta.url).href;
601600
#endif
602-
}
603601
#endif
602+
}
604603

605604
function getBinarySync(file) {
605+
#if SINGLE_FILE && WASM == 1 && !WASM2JS
606+
if (ArrayBuffer.isView(file)) {
607+
return file;
608+
}
609+
#endif
610+
#if expectToReceiveOnModule('wasmBinary') || MAYBE_WASM2JS
606611
if (file == wasmBinaryFile && wasmBinary) {
607612
return new Uint8Array(wasmBinary);
608613
}
609-
#if SUPPORT_BASE64_EMBEDDING
610-
var binary = tryParseAsDataURI(file);
611-
if (binary) {
612-
return binary;
613-
}
614614
#endif
615615
if (readBinary) {
616616
return readBinary(file);
@@ -1024,9 +1024,7 @@ function getWasmImports() {
10241024
var exports = receiveInstantiationResult({instance, 'module':wasmModule});
10251025
return exports;
10261026
#else
1027-
#if !SINGLE_FILE
10281027
wasmBinaryFile ??= findWasmBinary();
1029-
#endif
10301028
#if WASM_ASYNC_COMPILATION
10311029
#if RUNTIME_DEBUG
10321030
dbg('asynchronously preparing wasm');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4133
1+
4131
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19983
1+
19981
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19961
1+
19959
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9240
1+
9241
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
23720
1+
23718
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19875
1+
19873
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19875
1+
19873
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20057
1+
20055

0 commit comments

Comments
 (0)