Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: pass internalBinding more implicitly #16218

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,4 @@ globals:
LTTNG_HTTP_SERVER_RESPONSE: false
LTTNG_NET_SERVER_CONNECTION: false
LTTNG_NET_STREAM_END: false
internalBinding: false
8 changes: 6 additions & 2 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'use strict';

(function(process) {
let internalBinding;

function startup() {
const EventEmitter = NativeModule.require('events');
Expand All @@ -20,6 +21,9 @@

setupProcessObject();

internalBinding = process._internalBinding;
delete process._internalBinding;

// do this good and early, since it handles errors.
setupProcessFatal();

Expand Down Expand Up @@ -574,7 +578,7 @@
};

NativeModule.wrapper = [
'(function (exports, require, module, __filename, __dirname) { ',
'(function (exports, require, module, internalBinding) {',
'\n});'
];

Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/loader/ModuleWrap.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/loader/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions lib/internal/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Expand Down Expand Up @@ -259,6 +256,5 @@ module.exports = {
setupKillAndExit,
setupSignalHandlers,
setupChannel,
setupRawDebug,
internalBinding
setupRawDebug
};
10 changes: 8 additions & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,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');

Expand Down