From 8912caba647d9b2c9aca60f95cad6e99bed66575 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 15 Jan 2021 14:53:12 +0100 Subject: [PATCH] lib: expose primordials object 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: https://github.com/nodejs/node/pull/36872 Reviewed-By: Bradley Farias Reviewed-By: James M Snell --- lib/internal/modules/cjs/loader.js | 6 +++--- lib/internal/test/binding.js | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index b9dbf794511528..7929df8ae8479a 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); let debug = require('internal/util/debuglog').debuglog('module', (fn) => { debug = fn; diff --git a/lib/internal/test/binding.js b/lib/internal/test/binding.js index 882ea90093d039..063b9b5c900aad 100644 --- a/lib/internal/test/binding.js +++ b/lib/internal/test/binding.js @@ -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 };