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
|
2024-05-13 15:43:14 +00:00
|
|
|
index 7bbd59e16330b59f6c71aa8e6ff59659e42f6cee..276ab42c22b796ee07ce66744187adca6a8b8da4 100644
|
2019-07-16 17:23:04 +00:00
|
|
|
--- a/lib/internal/modules/cjs/loader.js
|
|
|
|
+++ b/lib/internal/modules/cjs/loader.js
|
2024-05-13 15:43:14 +00:00
|
|
|
@@ -148,6 +148,13 @@ const {
|
2023-01-11 10:33:48 +00:00
|
|
|
CHAR_FORWARD_SLASH,
|
2019-07-16 17:23:04 +00:00
|
|
|
} = 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.
|
2024-01-18 21:16:45 +00:00
|
|
|
+const localGlobal = (typeof global !== 'undefined') ? global : undefined;
|
2019-07-16 17:23:04 +00:00
|
|
|
+// Do the same for "Buffer".
|
2024-01-18 21:16:45 +00:00
|
|
|
+const localBuffer = (typeof Buffer !== 'undefined') ? Buffer : undefined;
|
2019-07-16 17:23:04 +00:00
|
|
|
+
|
2020-09-17 22:08:57 +00:00
|
|
|
const {
|
2023-04-18 20:23:11 +00:00
|
|
|
isProxy,
|
2020-09-17 22:08:57 +00:00
|
|
|
} = require('internal/util/types');
|
2024-05-13 15:43:14 +00:00
|
|
|
@@ -1353,10 +1360,12 @@ Module.prototype._compile = function(content, filename) {
|
2024-04-17 16:39:13 +00:00
|
|
|
setHasStartedUserCJSExecution();
|
2019-07-16 17:23:04 +00:00
|
|
|
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 {
|
2021-06-17 06:50:56 +00:00
|
|
|
result = ReflectApply(compiledWrapper, thisValue,
|
|
|
|
- [exports, require, module, filename, dirname]);
|
|
|
|
+ [exports, require, module, filename,
|
|
|
|
+ dirname, process, localGlobal, localBuffer]);
|
2019-07-16 17:23:04 +00:00
|
|
|
}
|
2023-12-11 20:09:50 +00:00
|
|
|
if (requireDepth === 0) { statCache = null; }
|
2024-04-17 16:39:13 +00:00
|
|
|
return result;
|