Skip to content
This repository was archived by the owner on Apr 16, 2020. It is now read-only.

Commit fafd301

Browse files
gengjiawenMylesBorins
authored andcommitted
test: better output for test-report-uv-handles.js
PR-URL: nodejs/node#27479 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 97ee1c9 commit fafd301

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed

lib/internal/modules/esm/default_resolve.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const preserveSymlinks = getOptionValue('--preserve-symlinks');
1010
const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main');
1111
const experimentalJsonModules = getOptionValue('--experimental-json-modules');
1212
const typeFlag = getOptionValue('--input-type');
13-
13+
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
1414
const { resolve: moduleWrapResolve,
1515
getPackageType } = internalBinding('module_wrap');
1616
const { pathToFileURL, fileURLToPath } = require('internal/url');
@@ -44,6 +44,16 @@ const legacyExtensionFormatMap = {
4444
'.node': 'commonjs'
4545
};
4646

47+
if (experimentalWasmModules) {
48+
// This is a total hack
49+
Object.assign(extensionFormatMap, {
50+
'.wasm': 'wasm'
51+
});
52+
Object.assign(legacyExtensionFormatMap, {
53+
'.wasm': 'wasm'
54+
});
55+
}
56+
4757
if (experimentalJsonModules) {
4858
// This is a total hack
4959
Object.assign(extensionFormatMap, {

lib/internal/modules/esm/translators.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,24 @@ translators.set('json', async function jsonStrategy(url) {
141141
reflect.exports.default.set(module.exports);
142142
});
143143
});
144+
145+
// Strategy for loading a wasm module
146+
translators.set('wasm', async function(url) {
147+
const pathname = fileURLToPath(url);
148+
const buffer = await readFileAsync(pathname);
149+
debug(`Translating WASMModule ${url}`);
150+
let result, keys;
151+
try {
152+
WebAssembly.validate(buffer);
153+
result = await WebAssembly.instantiate(buffer, {});
154+
keys = Object.keys(result.instance.exports);
155+
} catch (err) {
156+
err.message = pathname + ': ' + err.message;
157+
throw err;
158+
}
159+
return createDynamicModule([...keys, 'default'], url, (reflect) => {
160+
for (const key of keys)
161+
reflect.exports[key].set(result.instance.exports[key]);
162+
reflect.exports.default.set(result.instance.exports);
163+
});
164+
});

src/node_options.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
264264
"experimental ES Module support and caching modules",
265265
&EnvironmentOptions::experimental_modules,
266266
kAllowedInEnvironment);
267+
AddOption("--experimental-wasm-modules",
268+
"experimental ES Module support for webassembly modules",
269+
&EnvironmentOptions::experimental_wasm_modules,
270+
kAllowedInEnvironment);
267271
AddOption("--experimental-policy",
268272
"use the specified file as a "
269273
"security policy",

src/node_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class EnvironmentOptions : public Options {
9494
bool experimental_json_modules = false;
9595
bool experimental_modules = false;
9696
std::string es_module_specifier_resolution;
97+
bool experimental_wasm_modules = false;
9798
std::string module_type;
9899
std::string experimental_policy;
99100
bool experimental_repl_await = false;

test/es-module/test-esm-wasm.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Flags: --experimental-modules --experimental-wasm-modules
2+
/* eslint-disable node-core/required-modules */
3+
import wasmMod from '../fixtures/simple.wasm'
4+
import {add} from '../fixtures/simple.wasm';
5+
import {strictEqual} from 'assert';
6+
7+
strictEqual(wasmMod.add(10, 20), 30);
8+
strictEqual(add(10, 20), 30);
9+
strictEqual(wasmMod.add, add);

test/report/test-report-uv-handles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ if (process.argv[2] === 'child') {
8585
const report_msg = 'Report files were written: unexpectedly';
8686
child.stdout.on('data', (chunk) => { stdout += chunk; });
8787
child.on('exit', common.mustCall((code, signal) => {
88-
assert.deepStrictEqual(code, 0, 'Process exited unexpectedly with code' +
88+
assert.deepStrictEqual(code, 0, 'Process exited unexpectedly with code: ' +
8989
`${code}`);
9090
assert.deepStrictEqual(signal, null, 'Process should have exited cleanly,' +
9191
` but did not: ${signal}`);

0 commit comments

Comments
 (0)