Skip to content

Commit

Permalink
fixup! lib: expose primordials object
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jan 17, 2021
1 parent b74793f commit 2f67dae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
10 changes: 1 addition & 9 deletions lib/internal/bootstrap/loaders.js
Expand Up @@ -52,7 +52,6 @@ const {
ObjectKeys,
ObjectPrototypeHasOwnProperty,
ReflectGet,
ReflectGetOwnPropertyDescriptor,
SafeMap,
SafeSet,
String,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/modules/cjs/helpers.js
Expand Up @@ -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;
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/modules/cjs/loader.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2f67dae

Please sign in to comment.