Skip to content

Commit 5788f16

Browse files
ExE-Bossaduh95
andcommitted
lib: add WebAssembly to primordials
Co-authored-by: Antoine du Hamel <[email protected]>
1 parent 92ecd9f commit 5788f16

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ module.exports = {
359359
MessagePort: 'readable',
360360
TextEncoder: 'readable',
361361
TextDecoder: 'readable',
362+
WebAssembly: 'readonly',
362363
queueMicrotask: 'readable',
363364
globalThis: 'readable',
364365
btoa: 'readable',

lib/.eslintrc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ rules:
152152
into: Safe
153153
- name: WeakSet
154154
into: Safe
155+
- name: WebAssembly
155156
globals:
156157
Intl: false
157158
# Parameters passed to internal modules

lib/internal/freeze_intrinsics.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ const {
118118
WeakRefPrototype,
119119
WeakSet,
120120
WeakSetPrototype,
121+
WebAssembly,
122+
WebAssemblyModulePrototype,
123+
WebAssemblyInstancePrototype,
124+
WebAssemblyTablePrototype,
125+
WebAssemblyMemoryPrototype,
126+
WebAssemblyCompileErrorPrototype,
127+
WebAssemblyLinkErrorPrototype,
128+
WebAssemblyRuntimeErrorPrototype,
121129
decodeURI,
122130
decodeURIComponent,
123131
encodeURI,
@@ -129,7 +137,6 @@ const {
129137
Atomics,
130138
Intl,
131139
SharedArrayBuffer,
132-
WebAssembly
133140
} = globalThis;
134141

135142
module.exports = function() {
@@ -217,13 +224,13 @@ module.exports = function() {
217224

218225
// Other APIs / Web Compatibility
219226
console.Console.prototype,
220-
WebAssembly.Module.prototype,
221-
WebAssembly.Instance.prototype,
222-
WebAssembly.Table.prototype,
223-
WebAssembly.Memory.prototype,
224-
WebAssembly.CompileError.prototype,
225-
WebAssembly.LinkError.prototype,
226-
WebAssembly.RuntimeError.prototype,
227+
WebAssemblyModulePrototype,
228+
WebAssemblyInstancePrototype,
229+
WebAssemblyTablePrototype,
230+
WebAssemblyMemoryPrototype,
231+
WebAssemblyCompileErrorPrototype,
232+
WebAssemblyLinkErrorPrototype,
233+
WebAssemblyRuntimeErrorPrototype,
227234
];
228235
const intrinsics = [
229236
// 10.2.4.1 ThrowTypeError

lib/internal/modules/esm/translators.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ const {
1717
StringPrototypeSlice,
1818
StringPrototypeStartsWith,
1919
SyntaxErrorPrototype,
20-
globalThis: { WebAssembly },
20+
WebAssembly,
21+
WebAssemblyCompile,
22+
WebAssemblyInstance,
23+
WebAssemblyModuleExports,
24+
WebAssemblyModuleImports,
2125
} = primordials;
2226

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

346350
let compiled;
347351
try {
348-
compiled = await WebAssembly.compile(source);
352+
compiled = await WebAssemblyCompile(source);
349353
} catch (err) {
350354
err.message = errPath(url) + ': ' + err.message;
351355
throw err;
352356
}
353357

354358
const imports =
355-
ArrayPrototypeMap(WebAssembly.Module.imports(compiled),
359+
ArrayPrototypeMap(WebAssemblyModuleImports(compiled),
356360
({ module }) => module);
357361
const exports =
358-
ArrayPrototypeMap(WebAssembly.Module.exports(compiled),
362+
ArrayPrototypeMap(WebAssemblyModuleExports(compiled),
359363
({ name }) => name);
360364

361365
return createDynamicModule(imports, exports, url, (reflect) => {
362-
const { exports } = new WebAssembly.Instance(compiled, reflect.imports);
366+
const { exports } = new WebAssemblyInstance(compiled, reflect.imports);
363367
for (const expt of ObjectKeys(exports))
364368
reflect.exports[expt].set(exports[expt]);
365369
}).module;

0 commit comments

Comments
 (0)