From 5e7946fe79193633e9a78aae48548635cbc11023 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Mon, 9 Sep 2019 12:20:16 -0500 Subject: vm: refactor SourceTextModule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 PR-URL: https://github.com/nodejs/node/pull/29776 Reviewed-By: James M Snell Reviewed-By: Michaël Zasso Reviewed-By: Minwoo Jung --- lib/vm.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'lib/vm.js') diff --git a/lib/vm.js b/lib/vm.js index ec6614e661..90f332c775 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -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), + }); } } -- cgit v1.2.3