Permalink
Browse files

process: wrap process.binding for selective fallthrough

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

Refs: #22163

PR-URL: #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>
  • Loading branch information...
jasnell committed Aug 11, 2018
1 parent a091fbe commit 0257fd7ce91660b1f85b1a90a7d7acf0b90384ce
Showing with 24 additions and 0 deletions.
  1. +15 −0 lib/internal/bootstrap/node.js
  2. +9 −0 test/parallel/test-process-binding-internalbinding-whitelist.js
@@ -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() {
@@ -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'));

0 comments on commit 0257fd7

Please sign in to comment.