From 6d88f0fef7a3953e2e528fb4ed0cb151c4ab3a69 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Mon, 9 Sep 2019 12:20:16 -0500 Subject: [PATCH] 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 --- doc/api/errors.md | 10 +- doc/api/vm.md | 103 ++----- lib/internal/errors.js | 2 - lib/internal/modules/esm/loader.js | 4 +- lib/internal/vm/source_text_module.js | 284 +++++++++++------- lib/vm.js | 20 +- src/module_wrap.cc | 12 +- src/module_wrap.h | 2 +- test/parallel/test-internal-module-wrap.js | 2 +- test/parallel/test-util-inspect-namespace.js | 1 - test/parallel/test-util-types.js | 1 - test/parallel/test-vm-module-basic.js | 29 +- .../parallel/test-vm-module-dynamic-import.js | 4 - .../test-vm-module-dynamic-namespace.js | 17 +- test/parallel/test-vm-module-errors.js | 75 +---- test/parallel/test-vm-module-import-meta.js | 1 - test/parallel/test-vm-module-link.js | 35 +-- test/parallel/test-vm-module-reevaluate.js | 2 - 18 files changed, 269 insertions(+), 335 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 5783724774b600..f479d06f1456fb 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1976,11 +1976,6 @@ than the parent module. Linked modules must share the same context. The linker function returned a module for which linking has failed. - -### ERR_VM_MODULE_NOT_LINKED - -The module must be successfully linked before instantiation. - ### ERR_VM_MODULE_NOT_MODULE @@ -2267,6 +2262,11 @@ removed: v10.0.0 Used when a given value is out of the accepted range. + +### ERR_VM_MODULE_NOT_LINKED + +The module must be successfully linked before instantiation. + ### ERR_ZLIB_BINDING_CLOSED