summaryrefslogtreecommitdiff
path: root/lib/internal/modules/esm
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-01-05 06:02:33 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-01-12 22:56:02 +0800
commit92e95f17b64838d4cf77343c1a814d4ebd795217 (patch)
tree25aa45e582b5657505fff57ba78578e2f4dc248e /lib/internal/modules/esm
parent18d3aebb06903a0151bdecbad2b6b7077b965d03 (diff)
downloadandroid-node-v8-92e95f17b64838d4cf77343c1a814d4ebd795217.tar.gz
android-node-v8-92e95f17b64838d4cf77343c1a814d4ebd795217.tar.bz2
android-node-v8-92e95f17b64838d4cf77343c1a814d4ebd795217.zip
src: simplify NativeModule caching and remove redundant data
- Remove `NativeModule._source` - the compilation is now entirely done in C++ and `process.binding('natives')` is implemented directly in the binding loader so there is no need to store additional source code strings. - Instead of using an object as `NativeModule._cached` and insert into it after compilation of each native module, simply prebuild a JS map filled with all the native modules and infer the state of compilation through `mod.loading`/`mod.loaded`. - Rename `NativeModule.nonInternalExists` to `NativeModule.canBeRequiredByUsers` and precompute that property for all the native modules during bootstrap instead of branching in every require call during runtime. This also fixes the bug where `worker_threads` can be made available with `--expose-internals`. - Rename `NativeModule.requireForDeps` to `NativeModule.requireWithFallbackInDeps`. - Add a test to make sure we do not accidentally leak any module to the global namespace. PR-URL: https://github.com/nodejs/node/pull/25352 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/internal/modules/esm')
-rw-r--r--lib/internal/modules/esm/default_resolve.js2
-rw-r--r--lib/internal/modules/esm/translators.js2
2 files changed, 2 insertions, 2 deletions
diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js
index 9aa54d09a1..2cf9014a67 100644
--- a/lib/internal/modules/esm/default_resolve.js
+++ b/lib/internal/modules/esm/default_resolve.js
@@ -53,7 +53,7 @@ const extensionFormatMap = {
};
function resolve(specifier, parentURL) {
- if (NativeModule.nonInternalExists(specifier)) {
+ if (NativeModule.canBeRequiredByUsers(specifier)) {
return {
url: specifier,
format: 'builtin'
diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js
index 6bfc4c8a98..776b8d584d 100644
--- a/lib/internal/modules/esm/translators.js
+++ b/lib/internal/modules/esm/translators.js
@@ -81,7 +81,7 @@ translators.set('builtin', async (url) => {
// slice 'node:' scheme
const id = url.slice(5);
NativeModule.require(id);
- const module = NativeModule.getCached(id);
+ const module = NativeModule.map.get(id);
return createDynamicModule(
[...module.exportKeys, 'default'], url, (reflect) => {
debug(`Loading BuiltinModule ${url}`);