process: wrap process.binding for selective fallthrough

Selectively fallthrough `process.binding()` to `internalBinding()`

Refs: https://github.com/nodejs/node/pull/22163

PR-URL: https://github.com/nodejs/node/pull/22269
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
James M Snell 2018-08-11 09:54:41 -07:00
parent a091fbeb7f
commit 0257fd7ce9
2 changed files with 24 additions and 0 deletions

View File

@ -318,6 +318,21 @@
for (var i = 0; i < arguments.length; i++)
this.push(arguments[i]);
}
// Deprecated specific process.binding() modules, but not all, allow
// selective fallback to internalBinding for the deprecated ones.
const { SafeSet } = NativeModule.require('internal/safe_globals');
const processBinding = process.binding;
// internalBindingWhitelist contains the name of internalBinding modules
// that are whitelisted for access via process.binding()... this is used
// to provide a transition path for modules that are being moved over to
// internalBinding.
const internalBindingWhitelist = new SafeSet(['uv']);
process.binding = function binding(name) {
return internalBindingWhitelist.has(name) ?
internalBinding(name) :
processBinding(name);
};
}
function setupGlobalVariables() {

View File

@ -0,0 +1,9 @@
// Flags: --no-warnings
'use strict';
require('../common');
const assert = require('assert');
// Assert that whitelisted internalBinding modules are accessible via
// process.binding().
assert(process.binding('uv'));