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-10-07 19:07:12 +00:00
|
|
|
index 9cacdc77237d3399f5c939d21f77f3c7d4e88a2f..768d13d018f75f12061f1d9e7d69fb47ddd3552d 100644
|
2019-07-16 17:23:04 +00:00
|
|
|
--- a/lib/internal/modules/cjs/loader.js
|
|
|
|
+++ b/lib/internal/modules/cjs/loader.js
|
2020-10-07 19:07:12 +00:00
|
|
|
@@ -110,6 +110,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;
|
|
|
|
+
|
2020-09-17 22:08:57 +00:00
|
|
|
const {
|
|
|
|
isProxy
|
|
|
|
} = require('internal/util/types');
|
2020-10-07 19:07:12 +00:00
|
|
|
@@ -1080,10 +1087,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);
|
2020-02-24 21:02:04 +00:00
|
|
|
+ require, module, filename, dirname,
|
|
|
|
+ process, localGlobal, localBuffer);
|
2019-07-16 17:23:04 +00:00
|
|
|
} else {
|
|
|
|
result = compiledWrapper.call(thisValue, exports, require, module,
|
|
|
|
- filename, dirname);
|
|
|
|
+ filename, dirname, process, localGlobal,
|
|
|
|
+ localBuffer);
|
|
|
|
}
|
2020-02-24 21:02:04 +00:00
|
|
|
hasLoadedAnyUserCJSModule = true;
|
2019-07-16 17:23:04 +00:00
|
|
|
if (requireDepth === 0) statCache = null;
|