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_NET_SERVER_CONNECTION: 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';
|
||||
|
||||
(function(process) {
|
||||
let internalBinding;
|
||||
|
||||
function startup() {
|
||||
const EventEmitter = NativeModule.require('events');
|
||||
@ -20,6 +21,9 @@
|
||||
|
||||
setupProcessObject();
|
||||
|
||||
internalBinding = process._internalBinding;
|
||||
delete process._internalBinding;
|
||||
|
||||
// do this good and early, since it handles errors.
|
||||
setupProcessFatal();
|
||||
|
||||
@ -574,7 +578,7 @@
|
||||
};
|
||||
|
||||
NativeModule.wrapper = [
|
||||
'(function (exports, require, module, __filename, __dirname) { ',
|
||||
'(function (exports, require, module, internalBinding) {',
|
||||
'\n});'
|
||||
];
|
||||
|
||||
@ -590,7 +594,7 @@
|
||||
lineOffset: 0,
|
||||
displayErrors: true
|
||||
});
|
||||
fn(this.exports, NativeModule.require, this, this.filename);
|
||||
fn(this.exports, NativeModule.require, this, internalBinding);
|
||||
|
||||
this.loaded = true;
|
||||
} finally {
|
||||
|
@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { ModuleWrap } =
|
||||
require('internal/process').internalBinding('module_wrap');
|
||||
const { ModuleWrap } = internalBinding('module_wrap');
|
||||
const debug = require('util').debuglog('esm');
|
||||
const ArrayJoin = Function.call.bind(Array.prototype.join);
|
||||
const ArrayMap = Function.call.bind(Array.prototype.map);
|
||||
|
@ -3,7 +3,7 @@
|
||||
const { URL } = require('url');
|
||||
const CJSmodule = require('module');
|
||||
const errors = require('internal/errors');
|
||||
const { resolve } = require('internal/process').internalBinding('module_wrap');
|
||||
const { resolve } = internalBinding('module_wrap');
|
||||
|
||||
module.exports = (target, base) => {
|
||||
if (base === undefined) {
|
||||
|
@ -4,9 +4,6 @@ const errors = require('internal/errors');
|
||||
const util = require('util');
|
||||
const constants = process.binding('constants').os.signals;
|
||||
|
||||
const internalBinding = process._internalBinding;
|
||||
delete process._internalBinding;
|
||||
|
||||
const assert = process.assert = function(x, msg) {
|
||||
if (!x) throw new errors.Error('ERR_ASSERTION', msg || 'assertion error');
|
||||
};
|
||||
@ -259,6 +256,5 @@ module.exports = {
|
||||
setupKillAndExit,
|
||||
setupSignalHandlers,
|
||||
setupChannel,
|
||||
setupRawDebug,
|
||||
internalBinding
|
||||
setupRawDebug
|
||||
};
|
||||
|
@ -80,8 +80,14 @@ Module._extensions = Object.create(null);
|
||||
var modulePaths = [];
|
||||
Module.globalPaths = [];
|
||||
|
||||
Module.wrapper = NativeModule.wrapper;
|
||||
Module.wrap = NativeModule.wrap;
|
||||
Module.wrap = function(script) {
|
||||
return Module.wrapper[0] + script + Module.wrapper[1];
|
||||
};
|
||||
|
||||
Module.wrapper = [
|
||||
'(function (exports, require, module, __filename, __dirname) { ',
|
||||
'\n});'
|
||||
];
|
||||
|
||||
const debug = util.debuglog('module');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user