electron/patches/node/pass_all_globals_through_require.patch
2021-06-28 18:05:38 +02:00

40 lines
1.7 KiB
Diff

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
index 51bcfe1a4130e5c95f86daad2b2543f9a6fec0a3..9a304f05cf4e09038531007efff28c4f57218c1d 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -121,6 +121,13 @@ const {
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 {
isProxy
} = require('internal/util/types');
@@ -1090,10 +1097,12 @@ Module.prototype._compile = function(content, filename) {
if (requireDepth === 0) statCache = new SafeMap();
if (inspectorWrapper) {
result = inspectorWrapper(compiledWrapper, thisValue, exports,
- require, module, filename, dirname);
+ require, module, filename, dirname,
+ process, localGlobal, localBuffer);
} else {
result = ReflectApply(compiledWrapper, thisValue,
- [exports, require, module, filename, dirname]);
+ [exports, require, module, filename,
+ dirname, process, localGlobal, localBuffer]);
}
hasLoadedAnyUserCJSModule = true;
if (requireDepth === 0) statCache = null;