Skip to content

os: move process.binding('os') to internalBinding #22292

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
3 changes: 2 additions & 1 deletion lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -44,7 +45,7 @@ const {
getUptime,
isBigEndian,
setPriority: _setPriority
} = process.binding('os');
} = internalBinding('os');

function getCheckedFunction(fn) {
return function checkError(...args) {
Expand Down
2 changes: 1 addition & 1 deletion src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,4 @@ void Initialize(Local<Object> target,
} // namespace os
} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(os, node::os::Initialize)
NODE_MODULE_CONTEXT_AWARE_INTERNAL(os, node::os::Initialize)
6 changes: 5 additions & 1 deletion test/parallel/test-os-checked-function.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));