Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit b46c288

Browse files
zcbenzdeepak1556
authored andcommitted
Pass all globals through "require"
(cherry picked from commit 7d01541)
1 parent 7c45c46 commit b46c288

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

lib/internal/modules/cjs/loader.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ const {
8181
CHAR_9,
8282
} = require('internal/constants');
8383

84+
// Store the "global" variable from global scope into a local scope, so we can
85+
// still reference it from this file even after we deleted the "global" variable
86+
// from the global scope.
87+
const localGlobal = global;
88+
// Do the same for "Buffer".
89+
const localBuffer = Buffer;
90+
8491
const isWindows = process.platform === 'win32';
8592

8693
function stat(filename) {
@@ -131,8 +138,9 @@ Module.wrap = function(script) {
131138
};
132139

133140
Module.wrapper = [
134-
'(function (exports, require, module, __filename, __dirname) { ',
135-
'\n});'
141+
'(function (exports, require, module, __filename, __dirname, process, global, Buffer) { ' +
142+
'return function (exports, require, module, __filename, __dirname) { ',
143+
'\n}.call(this, exports, require, module, __filename, __dirname); });'
136144
];
137145

138146
const debug = util.debuglog('module');
@@ -715,10 +723,12 @@ Module.prototype._compile = function(content, filename) {
715723
var result;
716724
if (inspectorWrapper) {
717725
result = inspectorWrapper(compiledWrapper, this.exports, this.exports,
718-
require, this, filename, dirname);
726+
require, this, filename, dirname, process,
727+
localGlobal, localBuffer);
719728
} else {
720729
result = compiledWrapper.call(this.exports, this.exports, require, this,
721-
filename, dirname);
730+
filename, dirname, process, localGlobal,
731+
localBuffer);
722732
}
723733
if (depth === 0) stat.cache = null;
724734
return result;

0 commit comments

Comments
 (0)