Skip to content

Commit

Permalink
lib: expose primordials object
Browse files Browse the repository at this point in the history
Expose the internal `primordials` object to help with Node.js core
development.

```console
$ node --expose-internals -r internal/test/binding lib/fs.js
(node:5299) internal/test/binding: These APIs are for internal testing
only. Do not use them.
(Use `node --trace-warnings ...` to show where the warning was created)
```

PR-URL: #36872
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aduh95 authored and targos committed May 25, 2021
1 parent 5c396d9 commit baa2d1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
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);

let debug = require('internal/util/debuglog').debuglog('module', (fn) => {
debug = fn;
Expand Down
7 changes: 6 additions & 1 deletion lib/internal/test/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ process.emitWarning(
'These APIs are for internal testing only. Do not use them.',
'internal/test/binding');

module.exports = { internalBinding };
if (module.isPreloading) {
globalThis.internalBinding = internalBinding;
globalThis.primordials = primordials;
}

module.exports = { internalBinding, primordials };

0 comments on commit baa2d1a

Please sign in to comment.