From 882dcdaab57ff1f22cb7389ada1c28a970e4442b Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Tue, 30 Apr 2019 00:27:20 +0800 Subject: [PATCH 1/8] test: better output for test-report-uv-handles.js PR-URL: https://github.com/nodejs/node/pull/27479 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig --- lib/internal/modules/esm/default_resolve.js | 12 +++++++++++- lib/internal/modules/esm/translators.js | 21 +++++++++++++++++++++ src/node_options.cc | 4 ++++ src/node_options.h | 1 + test/es-module/test-esm-wasm.mjs | 9 +++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/es-module/test-esm-wasm.mjs diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index a83cf9c675..f17316a708 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -10,7 +10,7 @@ const preserveSymlinks = getOptionValue('--preserve-symlinks'); const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main'); const experimentalJsonModules = getOptionValue('--experimental-json-modules'); const typeFlag = getOptionValue('--input-type'); - +const experimentalWasmModules = getOptionValue('--experimental-wasm-modules'); const { resolve: moduleWrapResolve, getPackageType } = internalBinding('module_wrap'); const { pathToFileURL, fileURLToPath } = require('internal/url'); @@ -44,6 +44,16 @@ const legacyExtensionFormatMap = { '.node': 'commonjs' }; +if (experimentalWasmModules) { + // This is a total hack + Object.assign(extensionFormatMap, { + '.wasm': 'wasm' + }); + Object.assign(legacyExtensionFormatMap, { + '.wasm': 'wasm' + }); +} + if (experimentalJsonModules) { // This is a total hack Object.assign(extensionFormatMap, { diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 72350fb2b2..b03037630b 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -141,3 +141,24 @@ translators.set('json', async function jsonStrategy(url) { reflect.exports.default.set(module.exports); }); }); + +// Strategy for loading a wasm module +translators.set('wasm', async function(url) { + const pathname = fileURLToPath(url); + const buffer = await readFileAsync(pathname); + debug(`Translating WASMModule ${url}`); + let result, keys; + try { + WebAssembly.validate(buffer); + result = await WebAssembly.instantiate(buffer, {}); + keys = Object.keys(result.instance.exports); + } catch (err) { + err.message = pathname + ': ' + err.message; + throw err; + } + return createDynamicModule([...keys, 'default'], url, (reflect) => { + for (const key of keys) + reflect.exports[key].set(result.instance.exports[key]); + reflect.exports.default.set(result.instance.exports); + }); +}); diff --git a/src/node_options.cc b/src/node_options.cc index b2f14d2056..000ec45598 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -269,6 +269,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "experimental ES Module support and caching modules", &EnvironmentOptions::experimental_modules, kAllowedInEnvironment); + AddOption("--experimental-wasm-modules", + "experimental ES Module support for webassembly modules", + &EnvironmentOptions::experimental_wasm_modules, + kAllowedInEnvironment); AddOption("--experimental-policy", "use the specified file as a " "security policy", diff --git a/src/node_options.h b/src/node_options.h index 2aca1f327c..4ddd97f966 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -94,6 +94,7 @@ class EnvironmentOptions : public Options { bool experimental_json_modules = false; bool experimental_modules = false; std::string es_module_specifier_resolution; + bool experimental_wasm_modules = false; std::string module_type; std::string experimental_policy; bool experimental_repl_await = false; diff --git a/test/es-module/test-esm-wasm.mjs b/test/es-module/test-esm-wasm.mjs new file mode 100644 index 0000000000..76a43c708a --- /dev/null +++ b/test/es-module/test-esm-wasm.mjs @@ -0,0 +1,9 @@ +// Flags: --experimental-modules --experimental-wasm-modules +/* eslint-disable node-core/required-modules */ +import wasmMod from '../fixtures/simple.wasm' +import {add} from '../fixtures/simple.wasm'; +import {strictEqual} from 'assert'; + +strictEqual(wasmMod.add(10, 20), 30); +strictEqual(add(10, 20), 30); +strictEqual(wasmMod.add, add); From 10a96618e6ce78627f8c3a135e4265ced8fbe36a Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sun, 5 May 2019 19:41:33 +0200 Subject: [PATCH 2/8] support wasm imports --- lib/internal/modules/esm/translators.js | 33 ++++++++++++++++-------- test/es-module/test-esm-wasm.mjs | 10 +++---- test/fixtures/es-modules/simple.wasm | Bin 0 -> 98 bytes test/fixtures/es-modules/wasm-dep.mjs | 3 +++ 4 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 test/fixtures/es-modules/simple.wasm create mode 100644 test/fixtures/es-modules/wasm-dep.mjs diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index b03037630b..8b8f27d156 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -1,9 +1,12 @@ 'use strict'; +/* global WebAssembly */ + const { + JSON, + Object, SafeMap, - StringPrototype, - JSON + StringPrototype } = primordials; const { NativeModule } = require('internal/bootstrap/loaders'); @@ -147,18 +150,26 @@ translators.set('wasm', async function(url) { const pathname = fileURLToPath(url); const buffer = await readFileAsync(pathname); debug(`Translating WASMModule ${url}`); - let result, keys; try { - WebAssembly.validate(buffer); - result = await WebAssembly.instantiate(buffer, {}); - keys = Object.keys(result.instance.exports); + const compiled = await WebAssembly.compile(buffer); + // Note: This approach executes dependencies early, and will + // deadlock in cycles, both of which will be resolved when + // top-level await support lands. + const loader = await esmLoader.loaderPromise; + const imports = Object.create(null); + await Promise.all( + WebAssembly.Module.imports(compiled).map(async (impt) => { + imports[impt.module] = await loader.import(impt.module, url); + }) + ); + const { exports } = await WebAssembly.instantiate(compiled, imports); + const exportNames = Object.keys(exports); + return createDynamicModule(exportNames, url, (reflect) => { + for (const name of exportNames) + reflect.exports[name].set(exports[name]); + }); } catch (err) { err.message = pathname + ': ' + err.message; throw err; } - return createDynamicModule([...keys, 'default'], url, (reflect) => { - for (const key of keys) - reflect.exports[key].set(result.instance.exports[key]); - reflect.exports.default.set(result.instance.exports); - }); }); diff --git a/test/es-module/test-esm-wasm.mjs b/test/es-module/test-esm-wasm.mjs index 76a43c708a..62154bbf3c 100644 --- a/test/es-module/test-esm-wasm.mjs +++ b/test/es-module/test-esm-wasm.mjs @@ -1,9 +1,9 @@ // Flags: --experimental-modules --experimental-wasm-modules /* eslint-disable node-core/required-modules */ -import wasmMod from '../fixtures/simple.wasm' -import {add} from '../fixtures/simple.wasm'; -import {strictEqual} from 'assert'; +import { add, addImported } from '../fixtures/es-modules/simple.wasm'; +import { strictEqual } from 'assert'; -strictEqual(wasmMod.add(10, 20), 30); strictEqual(add(10, 20), 30); -strictEqual(wasmMod.add, add); + +strictEqual(addImported(0), 42); +strictEqual(addImported(1), 43); diff --git a/test/fixtures/es-modules/simple.wasm b/test/fixtures/es-modules/simple.wasm new file mode 100644 index 0000000000000000000000000000000000000000..889c1a5865f6b9852aefe87743cb203a330a54af GIT binary patch literal 98 zcmWm3K?;B%6h+bZzk!etHi)KeAlpUIE);YkSdu|Qx1LST9bCAQ2moneLDh1tO=|E= sgW2BpS0A!Tv2?NQCm;k9%ZY{a9;BK_%Gdn_5AH{nSg=r3e>I}|018?YeE Date: Mon, 6 May 2019 09:53:20 -0500 Subject: [PATCH 3/8] Update translators.js --- lib/internal/modules/esm/translators.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 8b8f27d156..033fb781cc 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -162,11 +162,13 @@ translators.set('wasm', async function(url) { imports[impt.module] = await loader.import(impt.module, url); }) ); - const { exports } = await WebAssembly.instantiate(compiled, imports); - const exportNames = Object.keys(exports); + const exportNames = WebAssembly.Module.exports(compiled) + .map((i) => i.name); return createDynamicModule(exportNames, url, (reflect) => { - for (const name of exportNames) + const { exports } = new WebAssembly.Instance(compiled, imports); + exportNames.forEach((name) => { reflect.exports[name].set(exports[name]); + }); }); } catch (err) { err.message = pathname + ': ' + err.message; From b702e110aa9a97af1419ec3274a31b0139c3a66e Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Mon, 6 May 2019 09:55:21 -0500 Subject: [PATCH 4/8] Update translators.js --- lib/internal/modules/esm/translators.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 033fb781cc..b33e97ee2d 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -165,6 +165,9 @@ translators.set('wasm', async function(url) { const exportNames = WebAssembly.Module.exports(compiled) .map((i) => i.name); return createDynamicModule(exportNames, url, (reflect) => { + // Creating a wasm instance with the JS api will automatically + // run the wasm start function, so this must be done inside the + // dynamic module callback. const { exports } = new WebAssembly.Instance(compiled, imports); exportNames.forEach((name) => { reflect.exports[name].set(exports[name]); From dcd8a464163615e2e6d482b006b32be1ea78bbfa Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 7 May 2019 02:40:10 +0200 Subject: [PATCH 5/8] support exact import semantics --- .../modules/esm/create_wasm_module.js | 47 +++++++++++++++++++ lib/internal/modules/esm/translators.js | 25 ++-------- node.gyp | 1 + 3 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 lib/internal/modules/esm/create_wasm_module.js diff --git a/lib/internal/modules/esm/create_wasm_module.js b/lib/internal/modules/esm/create_wasm_module.js new file mode 100644 index 0000000000..0de8c44d76 --- /dev/null +++ b/lib/internal/modules/esm/create_wasm_module.js @@ -0,0 +1,47 @@ +'use strict'; + +const { JSON } = primordials; +const debug = require('internal/util/debuglog').debuglog('esm'); + +/* global WebAssembly */ + +module.exports = function createWASMModule(module, url) { + debug('creating WASM facade for %s with exports: %j', url, exports); + + const imports = WebAssembly.Module.imports(module); + const importModules = new Set(); + imports.forEach(({ module }) => importModules.add(module)); + + const source = `const imports = Object.create(null); +${[...importModules].map((module) => { + const specifierStr = JSON.stringify(module); + const importNames = new Set( + imports + .filter(({ module: m }) => m === module) + .map(({ name }) => name) + ); + const impts = + [...importNames].map((name) => `${name} as $${name}`).join(', '); + const defs = [...importNames].map((name) => `${name}: $${name}`).join(', '); + return `import { ${impts} } from ${specifierStr}; + imports[${specifierStr}] = { ${defs} };`; + }).join('\n')} +const { exports } = new WebAssembly.Instance(import.meta.module, imports); +${WebAssembly.Module.exports(module) + .map(({ name }) => `export const ${name} = exports.${name};`).join('\n')} + `; + + const { ModuleWrap, callbackMap } = internalBinding('module_wrap'); + const m = new ModuleWrap(source, `${url}`); + + callbackMap.set(m, { + initializeImportMeta: (meta, wrap) => { + meta.module = module; + }, + }); + + return { + module: m, + reflect: undefined + }; +}; diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index b33e97ee2d..4d780db563 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -4,7 +4,6 @@ const { JSON, - Object, SafeMap, StringPrototype } = primordials; @@ -18,6 +17,8 @@ const CJSModule = require('internal/modules/cjs/loader'); const internalURLModule = require('internal/url'); const createDynamicModule = require( 'internal/modules/esm/create_dynamic_module'); +const createWASMModule = require( + 'internal/modules/esm/create_wasm_module'); const fs = require('fs'); const { fileURLToPath, URL } = require('url'); const { debuglog } = require('internal/util/debuglog'); @@ -152,27 +153,7 @@ translators.set('wasm', async function(url) { debug(`Translating WASMModule ${url}`); try { const compiled = await WebAssembly.compile(buffer); - // Note: This approach executes dependencies early, and will - // deadlock in cycles, both of which will be resolved when - // top-level await support lands. - const loader = await esmLoader.loaderPromise; - const imports = Object.create(null); - await Promise.all( - WebAssembly.Module.imports(compiled).map(async (impt) => { - imports[impt.module] = await loader.import(impt.module, url); - }) - ); - const exportNames = WebAssembly.Module.exports(compiled) - .map((i) => i.name); - return createDynamicModule(exportNames, url, (reflect) => { - // Creating a wasm instance with the JS api will automatically - // run the wasm start function, so this must be done inside the - // dynamic module callback. - const { exports } = new WebAssembly.Instance(compiled, imports); - exportNames.forEach((name) => { - reflect.exports[name].set(exports[name]); - }); - }); + return createWASMModule(compiled, url); } catch (err) { err.message = pathname + ': ' + err.message; throw err; diff --git a/node.gyp b/node.gyp index 1ab6b15d73..33de4b61ef 100644 --- a/node.gyp +++ b/node.gyp @@ -149,6 +149,7 @@ 'lib/internal/modules/cjs/loader.js', 'lib/internal/modules/esm/loader.js', 'lib/internal/modules/esm/create_dynamic_module.js', + 'lib/internal/modules/esm/create_wasm_module.js', 'lib/internal/modules/esm/default_resolve.js', 'lib/internal/modules/esm/module_job.js', 'lib/internal/modules/esm/module_map.js', From 398979cb087e536d606ec4c887c8f2cc914167cc Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 8 May 2019 17:33:57 +0200 Subject: [PATCH 6/8] wasm modules as dynamic modules with import support --- lib/internal/modules/cjs/loader.js | 2 +- .../modules/esm/create_dynamic_module.js | 18 ++++--- .../modules/esm/create_wasm_module.js | 47 ------------------- lib/internal/modules/esm/loader.js | 2 +- lib/internal/modules/esm/translators.js | 27 +++++++---- node.gyp | 1 - 6 files changed, 32 insertions(+), 65 deletions(-) delete mode 100644 lib/internal/modules/esm/create_wasm_module.js diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 91b89860e7..29dce8c0a7 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -643,7 +643,7 @@ Module.prototype.load = function(filename) { url, new ModuleJob(ESMLoader, url, async () => { return createDynamicModule( - ['default'], url, (reflect) => { + [], ['default'], url, (reflect) => { reflect.exports.default.set(exports); }); }) diff --git a/lib/internal/modules/esm/create_dynamic_module.js b/lib/internal/modules/esm/create_dynamic_module.js index eea01bed31..45f964d5ad 100644 --- a/lib/internal/modules/esm/create_dynamic_module.js +++ b/lib/internal/modules/esm/create_dynamic_module.js @@ -1,14 +1,18 @@ 'use strict'; -const { ArrayPrototype } = primordials; +const { ArrayPrototype, JSON, Object } = primordials; const debug = require('internal/util/debuglog').debuglog('esm'); -const createDynamicModule = (exports, url = '', evaluate) => { +const createDynamicModule = (imports, exports, url = '', evaluate) => { debug('creating ESM facade for %s with exports: %j', url, exports); const names = ArrayPrototype.map(exports, (name) => `${name}`); const source = ` +${ArrayPrototype.join(ArrayPrototype.map(imports, (impt, index) => + `import * as $import_${index} from ${JSON.stringify(impt)}; +import.meta.imports[${JSON.stringify(impt)}] = $import_${index};`), '\n') +} ${ArrayPrototype.join(ArrayPrototype.map(names, (name) => `let $${name}; export { $${name} as ${name} }; @@ -22,19 +26,21 @@ import.meta.done(); `; const { ModuleWrap, callbackMap } = internalBinding('module_wrap'); const m = new ModuleWrap(source, `${url}`); - m.link(() => 0); - m.instantiate(); const readyfns = new Set(); const reflect = { - namespace: m.namespace(), - exports: {}, + exports: Object.create(null), onReady: (cb) => { readyfns.add(cb); }, }; + if (imports.length) + reflect.imports = Object.create(null); + callbackMap.set(m, { initializeImportMeta: (meta, wrap) => { meta.exports = reflect.exports; + if (reflect.imports) + meta.imports = reflect.imports; meta.done = () => { evaluate(reflect); reflect.onReady = (cb) => cb(reflect); diff --git a/lib/internal/modules/esm/create_wasm_module.js b/lib/internal/modules/esm/create_wasm_module.js deleted file mode 100644 index 0de8c44d76..0000000000 --- a/lib/internal/modules/esm/create_wasm_module.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -const { JSON } = primordials; -const debug = require('internal/util/debuglog').debuglog('esm'); - -/* global WebAssembly */ - -module.exports = function createWASMModule(module, url) { - debug('creating WASM facade for %s with exports: %j', url, exports); - - const imports = WebAssembly.Module.imports(module); - const importModules = new Set(); - imports.forEach(({ module }) => importModules.add(module)); - - const source = `const imports = Object.create(null); -${[...importModules].map((module) => { - const specifierStr = JSON.stringify(module); - const importNames = new Set( - imports - .filter(({ module: m }) => m === module) - .map(({ name }) => name) - ); - const impts = - [...importNames].map((name) => `${name} as $${name}`).join(', '); - const defs = [...importNames].map((name) => `${name}: $${name}`).join(', '); - return `import { ${impts} } from ${specifierStr}; - imports[${specifierStr}] = { ${defs} };`; - }).join('\n')} -const { exports } = new WebAssembly.Instance(import.meta.module, imports); -${WebAssembly.Module.exports(module) - .map(({ name }) => `export const ${name} = exports.${name};`).join('\n')} - `; - - const { ModuleWrap, callbackMap } = internalBinding('module_wrap'); - const m = new ModuleWrap(source, `${url}`); - - callbackMap.set(m, { - initializeImportMeta: (meta, wrap) => { - meta.module = module; - }, - }); - - return { - module: m, - reflect: undefined - }; -}; diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index f752550d12..0ea1e6f4e5 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -153,7 +153,7 @@ class Loader { loaderInstance = async (url) => { debug(`Translating dynamic ${url}`); const { exports, execute } = await this._dynamicInstantiate(url); - return createDynamicModule(exports, url, (reflect) => { + return createDynamicModule([], exports, url, (reflect) => { debug(`Loading dynamic ${url}`); execute(reflect.exports); }); diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 4d780db563..4ca9be4d62 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -4,6 +4,7 @@ const { JSON, + Object, SafeMap, StringPrototype } = primordials; @@ -17,8 +18,6 @@ const CJSModule = require('internal/modules/cjs/loader'); const internalURLModule = require('internal/url'); const createDynamicModule = require( 'internal/modules/esm/create_dynamic_module'); -const createWASMModule = require( - 'internal/modules/esm/create_wasm_module'); const fs = require('fs'); const { fileURLToPath, URL } = require('url'); const { debuglog } = require('internal/util/debuglog'); @@ -76,11 +75,11 @@ translators.set('commonjs', async function commonjsStrategy(url, isMain) { ]; if (module && module.loaded) { const exports = module.exports; - return createDynamicModule(['default'], url, (reflect) => { + return createDynamicModule([], ['default'], url, (reflect) => { reflect.exports.default.set(exports); }); } - return createDynamicModule(['default'], url, () => { + return createDynamicModule([], ['default'], url, () => { debug(`Loading CJSModule ${url}`); // We don't care about the return val of _load here because Module#load // will handle it for us by checking the loader registry and filling the @@ -101,7 +100,7 @@ translators.set('builtin', async function builtinStrategy(url) { } module.compileForPublicLoader(true); return createDynamicModule( - [...module.exportKeys, 'default'], url, (reflect) => { + [], [...module.exportKeys, 'default'], url, (reflect) => { debug(`Loading BuiltinModule ${url}`); module.reflect = reflect; for (const key of module.exportKeys) @@ -120,7 +119,7 @@ translators.set('json', async function jsonStrategy(url) { let module = CJSModule._cache[modulePath]; if (module && module.loaded) { const exports = module.exports; - return createDynamicModule(['default'], url, (reflect) => { + return createDynamicModule([], ['default'], url, (reflect) => { reflect.exports.default.set(exports); }); } @@ -140,7 +139,7 @@ translators.set('json', async function jsonStrategy(url) { throw err; } CJSModule._cache[modulePath] = module; - return createDynamicModule(['default'], url, (reflect) => { + return createDynamicModule([], ['default'], url, (reflect) => { debug(`Parsing JSONModule ${url}`); reflect.exports.default.set(module.exports); }); @@ -151,11 +150,21 @@ translators.set('wasm', async function(url) { const pathname = fileURLToPath(url); const buffer = await readFileAsync(pathname); debug(`Translating WASMModule ${url}`); + let compiled; try { - const compiled = await WebAssembly.compile(buffer); - return createWASMModule(compiled, url); + compiled = await WebAssembly.compile(buffer); } catch (err) { err.message = pathname + ': ' + err.message; throw err; } + + const imports = + WebAssembly.Module.imports(compiled).map(({ module }) => module); + const exports = WebAssembly.Module.exports(compiled).map(({ name }) => name); + + return createDynamicModule(imports, exports, url, (reflect) => { + const { exports } = new WebAssembly.Instance(compiled, reflect.imports); + for (const expt of Object.keys(exports)) + reflect.exports[expt].set(exports[expt]); + }); }); diff --git a/node.gyp b/node.gyp index 33de4b61ef..1ab6b15d73 100644 --- a/node.gyp +++ b/node.gyp @@ -149,7 +149,6 @@ 'lib/internal/modules/cjs/loader.js', 'lib/internal/modules/esm/loader.js', 'lib/internal/modules/esm/create_dynamic_module.js', - 'lib/internal/modules/esm/create_wasm_module.js', 'lib/internal/modules/esm/default_resolve.js', 'lib/internal/modules/esm/module_job.js', 'lib/internal/modules/esm/module_map.js', From 58e5cd4b282db1c90fab31fcf2946115c7bf4be7 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 8 May 2019 17:43:12 +0200 Subject: [PATCH 7/8] it was not a hack --- lib/internal/modules/esm/default_resolve.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index f17316a708..e7e731b31e 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -45,7 +45,6 @@ const legacyExtensionFormatMap = { }; if (experimentalWasmModules) { - // This is a total hack Object.assign(extensionFormatMap, { '.wasm': 'wasm' }); From f7fba4a81588429ffa15f03bfa3a5d009fdabd76 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 8 May 2019 17:56:13 +0200 Subject: [PATCH 8/8] it was a hack --- lib/internal/modules/esm/default_resolve.js | 26 ++++----------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index e7e731b31e..67b8db716c 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -17,10 +17,7 @@ const { pathToFileURL, fileURLToPath } = require('internal/url'); const { ERR_INPUT_TYPE_NOT_ALLOWED, ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes; -const { - Object, - SafeMap -} = primordials; +const { SafeMap } = primordials; const realpathCache = new SafeMap(); @@ -44,24 +41,11 @@ const legacyExtensionFormatMap = { '.node': 'commonjs' }; -if (experimentalWasmModules) { - Object.assign(extensionFormatMap, { - '.wasm': 'wasm' - }); - Object.assign(legacyExtensionFormatMap, { - '.wasm': 'wasm' - }); -} +if (experimentalWasmModules) + extensionFormatMap['.wasm'] = legacyExtensionFormatMap['.wasm'] = 'wasm'; -if (experimentalJsonModules) { - // This is a total hack - Object.assign(extensionFormatMap, { - '.json': 'json' - }); - Object.assign(legacyExtensionFormatMap, { - '.json': 'json' - }); -} +if (experimentalJsonModules) + extensionFormatMap['.json'] = legacyExtensionFormatMap['.json'] = 'json'; function resolve(specifier, parentURL) { if (NativeModule.canBeRequiredByUsers(specifier)) {