lib: pass internalBinding more implicitly
Modify passing of the `internalBinding` function so that it’s easier for core modules to adopt, and also not even accessible through `--expose-internals`. This also splits the module wrapper into a separate version for internal bindings and for CJS modules, which seems like a good idea given the different semantics. PR-URL: https://github.com/nodejs/node/pull/16218 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
b3f9b38174
commit
e6dfd59be0
@ -197,3 +197,4 @@ globals:
|
|||||||
LTTNG_HTTP_SERVER_RESPONSE: false
|
LTTNG_HTTP_SERVER_RESPONSE: false
|
||||||
LTTNG_NET_SERVER_CONNECTION: false
|
LTTNG_NET_SERVER_CONNECTION: false
|
||||||
LTTNG_NET_STREAM_END: false
|
LTTNG_NET_STREAM_END: false
|
||||||
|
internalBinding: false
|
||||||
|
8
lib/internal/bootstrap_node.js
vendored
8
lib/internal/bootstrap_node.js
vendored
@ -8,6 +8,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(function(process) {
|
(function(process) {
|
||||||
|
let internalBinding;
|
||||||
|
|
||||||
function startup() {
|
function startup() {
|
||||||
const EventEmitter = NativeModule.require('events');
|
const EventEmitter = NativeModule.require('events');
|
||||||
@ -20,6 +21,9 @@
|
|||||||
|
|
||||||
setupProcessObject();
|
setupProcessObject();
|
||||||
|
|
||||||
|
internalBinding = process._internalBinding;
|
||||||
|
delete process._internalBinding;
|
||||||
|
|
||||||
// do this good and early, since it handles errors.
|
// do this good and early, since it handles errors.
|
||||||
setupProcessFatal();
|
setupProcessFatal();
|
||||||
|
|
||||||
@ -574,7 +578,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
NativeModule.wrapper = [
|
NativeModule.wrapper = [
|
||||||
'(function (exports, require, module, __filename, __dirname) { ',
|
'(function (exports, require, module, internalBinding) {',
|
||||||
'\n});'
|
'\n});'
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -590,7 +594,7 @@
|
|||||||
lineOffset: 0,
|
lineOffset: 0,
|
||||||
displayErrors: true
|
displayErrors: true
|
||||||
});
|
});
|
||||||
fn(this.exports, NativeModule.require, this, this.filename);
|
fn(this.exports, NativeModule.require, this, internalBinding);
|
||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { ModuleWrap } =
|
const { ModuleWrap } = internalBinding('module_wrap');
|
||||||
require('internal/process').internalBinding('module_wrap');
|
|
||||||
const debug = require('util').debuglog('esm');
|
const debug = require('util').debuglog('esm');
|
||||||
const ArrayJoin = Function.call.bind(Array.prototype.join);
|
const ArrayJoin = Function.call.bind(Array.prototype.join);
|
||||||
const ArrayMap = Function.call.bind(Array.prototype.map);
|
const ArrayMap = Function.call.bind(Array.prototype.map);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const { URL } = require('url');
|
const { URL } = require('url');
|
||||||
const CJSmodule = require('module');
|
const CJSmodule = require('module');
|
||||||
const errors = require('internal/errors');
|
const errors = require('internal/errors');
|
||||||
const { resolve } = require('internal/process').internalBinding('module_wrap');
|
const { resolve } = internalBinding('module_wrap');
|
||||||
|
|
||||||
module.exports = (target, base) => {
|
module.exports = (target, base) => {
|
||||||
if (base === undefined) {
|
if (base === undefined) {
|
||||||
|
@ -4,9 +4,6 @@ const errors = require('internal/errors');
|
|||||||
const util = require('util');
|
const util = require('util');
|
||||||
const constants = process.binding('constants').os.signals;
|
const constants = process.binding('constants').os.signals;
|
||||||
|
|
||||||
const internalBinding = process._internalBinding;
|
|
||||||
delete process._internalBinding;
|
|
||||||
|
|
||||||
const assert = process.assert = function(x, msg) {
|
const assert = process.assert = function(x, msg) {
|
||||||
if (!x) throw new errors.Error('ERR_ASSERTION', msg || 'assertion error');
|
if (!x) throw new errors.Error('ERR_ASSERTION', msg || 'assertion error');
|
||||||
};
|
};
|
||||||
@ -259,6 +256,5 @@ module.exports = {
|
|||||||
setupKillAndExit,
|
setupKillAndExit,
|
||||||
setupSignalHandlers,
|
setupSignalHandlers,
|
||||||
setupChannel,
|
setupChannel,
|
||||||
setupRawDebug,
|
setupRawDebug
|
||||||
internalBinding
|
|
||||||
};
|
};
|
||||||
|
@ -80,8 +80,14 @@ Module._extensions = Object.create(null);
|
|||||||
var modulePaths = [];
|
var modulePaths = [];
|
||||||
Module.globalPaths = [];
|
Module.globalPaths = [];
|
||||||
|
|
||||||
Module.wrapper = NativeModule.wrapper;
|
Module.wrap = function(script) {
|
||||||
Module.wrap = NativeModule.wrap;
|
return Module.wrapper[0] + script + Module.wrapper[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
Module.wrapper = [
|
||||||
|
'(function (exports, require, module, __filename, __dirname) { ',
|
||||||
|
'\n});'
|
||||||
|
];
|
||||||
|
|
||||||
const debug = util.debuglog('module');
|
const debug = util.debuglog('module');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user