From 2f67daed797312309a5edb1af12a4d3225a5ae5f Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 17 Jan 2021 12:36:54 +0100 Subject: [PATCH] fixup! lib: expose primordials object --- lib/internal/bootstrap/loaders.js | 10 +--------- lib/internal/modules/cjs/helpers.js | 4 ++-- lib/internal/modules/cjs/loader.js | 8 ++++---- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 02bb99bf37d573..cae3200e677926 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -52,7 +52,6 @@ const { ObjectKeys, ObjectPrototypeHasOwnProperty, ReflectGet, - ReflectGetOwnPropertyDescriptor, SafeMap, SafeSet, String, @@ -217,19 +216,12 @@ class NativeModule { } // Used by user-land module loaders to compile and load builtins. - compileForPublicLoader(isPreloading) { + compileForPublicLoader() { if (!this.canBeRequiredByUsers) { // No code because this is an assertion against bugs // eslint-disable-next-line no-restricted-syntax throw new Error(`Should not compile ${this.id} for public use`); } - if (isPreloading) { - ObjectDefineProperty( - this, 'isPreloading', - ReflectGetOwnPropertyDescriptor( - nativeModuleRequire('internal/modules/cjs/loader').Module.prototype, - 'isPreloading')); - } this.compileForInternalLoader(); if (!this.exportKeys) { // When using --expose-internals, we do not want to reflect the named diff --git a/lib/internal/modules/cjs/helpers.js b/lib/internal/modules/cjs/helpers.js index 56c52dbe4349d7..163c854ac26d48 100644 --- a/lib/internal/modules/cjs/helpers.js +++ b/lib/internal/modules/cjs/helpers.js @@ -32,11 +32,11 @@ let debug = require('internal/util/debuglog').debuglog('module', (fn) => { // TODO: Use this set when resolving pkg#exports conditions in loader.js. const cjsConditions = new SafeSet(['require', 'node', ...userConditions]); -function loadNativeModule(filename, request, isPreloading) { +function loadNativeModule(filename, request) { const mod = NativeModule.map.get(filename); if (mod) { debug('load native module %s', request); - mod.compileForPublicLoader(isPreloading); + mod.compileForPublicLoader(); return mod; } } diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 06e90d43bd51cd..0c69d547d40b9a 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -233,9 +233,9 @@ ObjectDefineProperty(Module, 'wrapper', { } }); -ObjectDefineProperty(Module.prototype, 'isPreloading', { - get() { return isPreloading; } -}); +const isPreloadingDesc = { get() { return isPreloading; } }; +ObjectDefineProperty(Module.prototype, 'isPreloading', isPreloadingDesc); +ObjectDefineProperty(NativeModule.prototype, 'isPreloading', isPreloadingDesc); function getModuleParent() { return moduleParentCache.get(this); @@ -781,7 +781,7 @@ Module._load = function(request, parent, isMain) { } } - const mod = loadNativeModule(filename, request, isPreloading); + const mod = loadNativeModule(filename, request); if (mod && mod.canBeRequiredByUsers) return mod.exports; // Don't call updateChildren(), Module constructor already does.