Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ module.exports = {
MessagePort: 'readable',
TextEncoder: 'readable',
TextDecoder: 'readable',
WebAssembly: 'readonly',
queueMicrotask: 'readable',
globalThis: 'readable',
btoa: 'readable',
Expand Down
1 change: 1 addition & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ rules:
into: Safe
- name: WeakSet
into: Safe
- name: WebAssembly
globals:
Intl: false
# Parameters passed to internal modules
Expand Down
23 changes: 15 additions & 8 deletions lib/internal/freeze_intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ const {
WeakRefPrototype,
WeakSet,
WeakSetPrototype,
WebAssembly,
WebAssemblyModulePrototype,
WebAssemblyInstancePrototype,
WebAssemblyTablePrototype,
WebAssemblyMemoryPrototype,
WebAssemblyCompileErrorPrototype,
WebAssemblyLinkErrorPrototype,
WebAssemblyRuntimeErrorPrototype,
decodeURI,
decodeURIComponent,
encodeURI,
Expand All @@ -129,7 +137,6 @@ const {
Atomics,
Intl,
SharedArrayBuffer,
WebAssembly
} = globalThis;

module.exports = function() {
Expand Down Expand Up @@ -217,13 +224,13 @@ module.exports = function() {

// Other APIs / Web Compatibility
console.Console.prototype,
WebAssembly.Module.prototype,
WebAssembly.Instance.prototype,
WebAssembly.Table.prototype,
WebAssembly.Memory.prototype,
WebAssembly.CompileError.prototype,
WebAssembly.LinkError.prototype,
WebAssembly.RuntimeError.prototype,
WebAssemblyModulePrototype,
WebAssemblyInstancePrototype,
WebAssemblyTablePrototype,
WebAssemblyMemoryPrototype,
WebAssemblyCompileErrorPrototype,
WebAssemblyLinkErrorPrototype,
WebAssemblyRuntimeErrorPrototype,
];
const intrinsics = [
// 10.2.4.1 ThrowTypeError
Expand Down
14 changes: 9 additions & 5 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const {
StringPrototypeSlice,
StringPrototypeStartsWith,
SyntaxErrorPrototype,
globalThis: { WebAssembly },
WebAssembly,
WebAssemblyCompile,
WebAssemblyInstance,
WebAssemblyModuleExports,
WebAssemblyModuleImports,
} = primordials;

let _TYPES = null;
Expand Down Expand Up @@ -345,21 +349,21 @@ translators.set('wasm', async function(url, source) {

let compiled;
try {
compiled = await WebAssembly.compile(source);
compiled = await WebAssemblyCompile(source);
} catch (err) {
err.message = errPath(url) + ': ' + err.message;
throw err;
}

const imports =
ArrayPrototypeMap(WebAssembly.Module.imports(compiled),
ArrayPrototypeMap(WebAssemblyModuleImports(compiled),
({ module }) => module);
const exports =
ArrayPrototypeMap(WebAssembly.Module.exports(compiled),
ArrayPrototypeMap(WebAssemblyModuleExports(compiled),
({ name }) => name);

return createDynamicModule(imports, exports, url, (reflect) => {
const { exports } = new WebAssembly.Instance(compiled, reflect.imports);
const { exports } = new WebAssemblyInstance(compiled, reflect.imports);
for (const expt of ObjectKeys(exports))
reflect.exports[expt].set(exports[expt]);
}).module;
Expand Down