Skip to content

Commit

Permalink
process: wrap process.binding for selective fallthrough
Browse files Browse the repository at this point in the history
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 15, 2018
1 parent a091fbe commit 0257fd7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/internal/bootstrap/node.js
Expand Up @@ -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() {
Expand Down
@@ -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.