Skip to content

Commit 204c3c6

Browse files
committed
squash: add WebAssembly nested objects to staging primordials
1 parent 7319470 commit 204c3c6

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

lib/internal/modules/esm/translators.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,14 @@ const wasmInstances = new SafeWeakMap();
554554
translators.set('wasm', function(url, translateContext) {
555555
const { source } = translateContext;
556556
// WebAssembly global is not available during snapshot building, so we need to get it lazily.
557-
const { WebAssembly } = primordialsStaging;
557+
const { WebAssemblyInstance, WebAssemblyLinkError, WebAssemblyModule } = primordialsStaging;
558558
assertBufferSource(source, false, 'load');
559559

560560
debug(`Translating WASMModule ${url}`, translateContext);
561561

562562
let compiled;
563563
try {
564-
compiled = new WebAssembly.Module(source, {
564+
compiled = new WebAssemblyModule(source, {
565565
builtins: ['js-string'],
566566
importedStringConstants: 'wasm:js/string-constants',
567567
});
@@ -572,28 +572,28 @@ translators.set('wasm', function(url, translateContext) {
572572

573573
const importsList = new SafeSet();
574574
const wasmGlobalImports = [];
575-
for (const impt of WebAssembly.Module.imports(compiled)) {
575+
for (const impt of WebAssemblyModule.imports(compiled)) {
576576
if (impt.kind === 'global') {
577577
ArrayPrototypePush(wasmGlobalImports, impt);
578578
}
579579
// Prefix reservations per https://webassembly.github.io/esm-integration/js-api/index.html#parse-a-webassembly-module.
580580
if (impt.module.startsWith('wasm-js:')) {
581-
throw new WebAssembly.LinkError(`Invalid Wasm import "${impt.module}" in ${url}`);
581+
throw new WebAssemblyLinkError(`Invalid Wasm import "${impt.module}" in ${url}`);
582582
}
583583
if (impt.name.startsWith('wasm:') || impt.name.startsWith('wasm-js:')) {
584-
throw new WebAssembly.LinkError(`Invalid Wasm import name "${impt.module}" in ${url}`);
584+
throw new WebAssemblyLinkError(`Invalid Wasm import name "${impt.module}" in ${url}`);
585585
}
586586
importsList.add(impt.module);
587587
}
588588

589589
const exportsList = new SafeSet();
590590
const wasmGlobalExports = new SafeSet();
591-
for (const expt of WebAssembly.Module.exports(compiled)) {
591+
for (const expt of WebAssemblyModule.exports(compiled)) {
592592
if (expt.kind === 'global') {
593593
wasmGlobalExports.add(expt.name);
594594
}
595595
if (expt.name.startsWith('wasm:') || expt.name.startsWith('wasm-js:')) {
596-
throw new WebAssembly.LinkError(`Invalid Wasm export name "${expt.name}" in ${url}`);
596+
throw new WebAssemblyLinkError(`Invalid Wasm export name "${expt.name}" in ${url}`);
597597
}
598598
exportsList.add(expt.name);
599599
}
@@ -620,7 +620,7 @@ translators.set('wasm', function(url, translateContext) {
620620
}
621621
// In cycles importing unexecuted Wasm, wasmInstance will be undefined, which will fail during
622622
// instantiation, since all bindings will be in the Temporal Deadzone (TDZ).
623-
const { exports } = new WebAssembly.Instance(compiled, reflect.imports);
623+
const { exports } = new WebAssemblyInstance(compiled, reflect.imports);
624624
wasmInstances.set(module.getNamespace(), exports);
625625
for (const expt of exportsList) {
626626
let val = exports[expt];

lib/internal/primordials_staging.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ let _TemporalInstant;
2222
let _Uint8ArrayFromHex;
2323
let _Uint8ArrayFromBase64;
2424
let _WebAssembly;
25+
let _WebAssemblyInstance;
26+
let _WebAssemblyLinkError;
27+
let _WebAssemblyModule;
2528

2629
module.exports = {
2730
get AsyncDisposableStack() {
@@ -60,6 +63,15 @@ module.exports = {
6063
get WebAssembly() {
6164
return _WebAssembly;
6265
},
66+
get WebAssemblyInstance() {
67+
return _WebAssemblyInstance;
68+
},
69+
get WebAssemblyLinkError() {
70+
return _WebAssemblyLinkError;
71+
},
72+
get WebAssemblyModule() {
73+
return _WebAssemblyModule;
74+
},
6375
_init({
6476
AsyncDisposableStack,
6577
DisposableStack,
@@ -87,6 +99,9 @@ module.exports = {
8799
_Uint8ArrayFromBase64 = fromBase64;
88100
_Uint8ArrayFromHex = fromHex;
89101
_WebAssembly = WebAssembly;
102+
_WebAssemblyInstance = WebAssembly?.Instance;
103+
_WebAssemblyLinkError = WebAssembly?.LinkError;
104+
_WebAssemblyModule = WebAssembly?.Module;
90105

91106
delete this._init;
92107
},

0 commit comments

Comments
 (0)