diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index bdc328ae5eacad..b585b4af2e3db6 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -136,13 +136,18 @@ const legacyWrapperList = new SafeSet([ 'DEP0111'); } if (legacyWrapperList.has(module)) { - return nativeModuleRequire('internal/legacy/processbinding')[module](); + return bindingObj[module] ??= + nativeModuleRequire('internal/legacy/processbinding')[module](); } return internalBinding(module); } // eslint-disable-next-line no-restricted-syntax throw new Error(`No such module: ${module}`); }; +} + +{ + const bindingObj = ObjectCreate(null); process._linkedBinding = function _linkedBinding(module) { module = String(module); diff --git a/lib/internal/legacy/processbinding.js b/lib/internal/legacy/processbinding.js index 3d48e3c9882e58..9a0efb74c548d5 100644 --- a/lib/internal/legacy/processbinding.js +++ b/lib/internal/legacy/processbinding.js @@ -6,7 +6,7 @@ const { ObjectEntries, SafeArrayIterator, } = primordials; -const { types } = require('util'); +const types = require('internal/util/types'); module.exports = { util() { diff --git a/test/parallel/test-process-binding-util.js b/test/parallel/test-process-binding-util.js index d1e602de681cfa..b59f20ddffe8c5 100644 --- a/test/parallel/test-process-binding-util.js +++ b/test/parallel/test-process-binding-util.js @@ -28,3 +28,5 @@ assert.deepStrictEqual( for (const k of Object.keys(utilBinding)) { assert.strictEqual(utilBinding[k], util.types[k]); } + +assert.strictEqual(utilBinding, process.binding('util'));