12345678910111213141516171819202122232425262728293031323334353637383940 |
- From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
- From: Cheng Zhao <[email protected]>
- 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 19a7d7e671f5abfa55b62290dcf3796a2c4e9013..3161afa33889f1682a1689e76fbcadc397f4b01c 100644
- --- a/lib/internal/modules/cjs/loader.js
- +++ b/lib/internal/modules/cjs/loader.js
- @@ -142,6 +142,13 @@ const {
- CHAR_FORWARD_SLASH,
- } = 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');
- @@ -1236,10 +1243,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;
|