2019-07-16 17:23:04 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Cheng Zhao <zcbenz@gmail.com>
|
|
|
|
Date: Sun, 27 Mar 2016 14:42:26 +0900
|
|
|
|
Subject: Pass all globals through "require"
|
|
|
|
|
|
|
|
(cherry picked from commit 7d015419cb7a0ecfe6728431a4ed2056cd411d62)
|
|
|
|
|
|
|
|
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
|
2020-01-09 18:42:53 +00:00
|
|
|
index 4bd467849ccf98ba17e0f4615d1df5febf878173..112a35280391ac85665f119ded9c78e88f868542 100644
|
2019-07-16 17:23:04 +00:00
|
|
|
--- a/lib/internal/modules/cjs/loader.js
|
|
|
|
+++ b/lib/internal/modules/cjs/loader.js
|
2019-12-11 00:22:35 +00:00
|
|
|
@@ -83,6 +83,13 @@ const {
|
2019-07-16 17:23:04 +00:00
|
|
|
CHAR_COLON
|
|
|
|
} = require('internal/constants');
|
|
|
|
|
|
|
|
+// Store the "global" variable from global scope into a local scope, so we can
|
|
|
|
+// still reference it from this file even after we deleted the "global" variable
|
|
|
|
+// from the global scope.
|
|
|
|
+const localGlobal = global;
|
|
|
|
+// Do the same for "Buffer".
|
|
|
|
+const localBuffer = Buffer;
|
|
|
|
+
|
|
|
|
const isWindows = process.platform === 'win32';
|
|
|
|
|
|
|
|
const relativeResolveCache = Object.create(null);
|
2020-01-09 18:42:53 +00:00
|
|
|
@@ -950,10 +957,12 @@ Module.prototype._compile = function(content, filename) {
|
2019-07-16 17:23:04 +00:00
|
|
|
if (requireDepth === 0) statCache = new Map();
|
|
|
|
if (inspectorWrapper) {
|
|
|
|
result = inspectorWrapper(compiledWrapper, thisValue, exports,
|
|
|
|
- require, module, filename, dirname);
|
|
|
|
+ require, module, filename, dirname, process,
|
|
|
|
+ localGlobal, localBuffer);
|
|
|
|
} else {
|
|
|
|
result = compiledWrapper.call(thisValue, exports, require, module,
|
|
|
|
- filename, dirname);
|
|
|
|
+ filename, dirname, process, localGlobal,
|
|
|
|
+ localBuffer);
|
|
|
|
}
|
|
|
|
if (requireDepth === 0) statCache = null;
|
|
|
|
return result;
|