diff options
author | Gus Caplan <me@gus.host> | 2019-09-09 12:20:16 -0500 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-10-02 15:54:35 -0700 |
commit | 5e7946fe79193633e9a78aae48548635cbc11023 (patch) | |
tree | 4ef3ab236df6aa8d570e22453dbe56b37487ad63 /lib/vm.js | |
parent | 6ba9471f6fcaaf377f22621c4d193d30e3877566 (diff) | |
download | node-new-5e7946fe79193633e9a78aae48548635cbc11023.tar.gz |
vm: refactor SourceTextModule
- Removes redundant `instantiate` method
- Refactors `link` to match the spec linking steps more accurately
- Removes URL validation from SourceTextModule specifiers
- DRYs some dynamic import logic
Closes: https://github.com/nodejs/node/issues/29030
Co-Authored-By: Michaël Zasso <targos@protonmail.com>
PR-URL: https://github.com/nodejs/node/pull/29776
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Diffstat (limited to 'lib/vm.js')
-rw-r--r-- | lib/vm.js | 20 |
1 files changed, 5 insertions, 15 deletions
@@ -31,10 +31,8 @@ const { } = internalBinding('contextify'); const { ERR_INVALID_ARG_TYPE, - ERR_VM_MODULE_NOT_MODULE, } = require('internal/errors').codes; const { - isModuleNamespaceObject, isArrayBufferView, } = require('internal/util/types'); const { @@ -100,21 +98,13 @@ class Script extends ContextifyScript { 'function', importModuleDynamically); } - const { wrapMap, linkingStatusMap } = + const { importModuleDynamicallyWrap } = require('internal/vm/source_text_module'); const { callbackMap } = internalBinding('module_wrap'); - callbackMap.set(this, { importModuleDynamically: async (...args) => { - const m = await importModuleDynamically(...args); - if (isModuleNamespaceObject(m)) { - return m; - } - if (!m || !wrapMap.has(m)) - throw new ERR_VM_MODULE_NOT_MODULE(); - const childLinkingStatus = linkingStatusMap.get(m); - if (childLinkingStatus === 'errored') - throw m.error; - return m.namespace; - } }); + callbackMap.set(this, { + importModuleDynamically: + importModuleDynamicallyWrap(importModuleDynamically), + }); } } |