From d4a47c6729d801904426601dd2b61d34f9198829 Mon Sep 17 00:00:00 2001 From: briete Date: Mon, 13 Aug 2018 11:41:10 +0900 Subject: [PATCH 1/2] os: move process.binding('os') to internalBinding Refs: https://github.com/nodejs/node/issues/22160 --- lib/internal/bootstrap/node.js | 3 ++- lib/os.js | 3 ++- src/node_os.cc | 2 +- .../parallel/test-process-binding-internalbinding-whitelist.js | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 96b620d057c5ca..39d1de65f8e77a 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -359,7 +359,8 @@ 'contextify', 'tcp_wrap', 'tls_wrap', - 'async_wrap']); + 'async_wrap', + 'os']); process.binding = function binding(name) { return internalBindingWhitelist.has(name) ? internalBinding(name) : diff --git a/lib/os.js b/lib/os.js index 09a70d2f7b19e5..9e2c72af3ced95 100644 --- a/lib/os.js +++ b/lib/os.js @@ -24,6 +24,7 @@ const { pushValToArrayMax, safeGetenv } = process.binding('util'); const constants = process.binding('constants').os; const { deprecate } = require('internal/util'); +const { internalBinding } = require('internal/bootstrap/loaders'); const isWindows = process.platform === 'win32'; const { codes: { ERR_SYSTEM_ERROR } } = require('internal/errors'); @@ -44,7 +45,7 @@ const { getUptime, isBigEndian, setPriority: _setPriority -} = process.binding('os'); +} = internalBinding('os'); function getCheckedFunction(fn) { return function checkError(...args) { diff --git a/src/node_os.cc b/src/node_os.cc index d3e9460f473122..fb413eb22ae81b 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -470,4 +470,4 @@ void Initialize(Local target, } // namespace os } // namespace node -NODE_BUILTIN_MODULE_CONTEXT_AWARE(os, node::os::Initialize) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(os, node::os::Initialize) diff --git a/test/parallel/test-process-binding-internalbinding-whitelist.js b/test/parallel/test-process-binding-internalbinding-whitelist.js index 63ce002887db8a..825907b8f71658 100644 --- a/test/parallel/test-process-binding-internalbinding-whitelist.js +++ b/test/parallel/test-process-binding-internalbinding-whitelist.js @@ -12,3 +12,4 @@ assert(process.binding('v8')); assert(process.binding('stream_wrap')); assert(process.binding('signal_wrap')); assert(process.binding('contextify')); +assert(process.binding('os')); From ca7dad0abfe7463b3f9c843f2e2af33d73c98f82 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Wed, 29 Aug 2018 15:31:55 +0300 Subject: [PATCH 2/2] fixup! move test-os-checked-function to internalBinding --- test/parallel/test-os-checked-function.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-os-checked-function.js b/test/parallel/test-os-checked-function.js index 04c2c3a1f82ea3..d080b7561a1580 100644 --- a/test/parallel/test-os-checked-function.js +++ b/test/parallel/test-os-checked-function.js @@ -1,7 +1,11 @@ +// Flags: --expose-internals 'use strict'; + +const { internalBinding } = require('internal/test/binding'); + // Monkey patch the os binding before requiring any other modules, including // common, which requires the os module. -process.binding('os').getHomeDirectory = function(ctx) { +internalBinding('os').getHomeDirectory = function(ctx) { ctx.syscall = 'foo'; ctx.code = 'bar'; ctx.message = 'baz';