pass_all_globals_through_require.patch 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Sun, 27 Mar 2016 14:42:26 +0900
  4. Subject: Pass all globals through "require"
  5. (cherry picked from commit 7d015419cb7a0ecfe6728431a4ed2056cd411d62)
  6. diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
  7. index 451b7c2195e7ad3ab0bde95259e054dc431d7de9..d49941881e6cfd8647a6d44a57e0daaf1c874702 100644
  8. --- a/lib/internal/modules/cjs/loader.js
  9. +++ b/lib/internal/modules/cjs/loader.js
  10. @@ -182,6 +182,13 @@ const {
  11. CHAR_FORWARD_SLASH,
  12. } = require('internal/constants');
  13. +// Store the "global" variable from global scope into a local scope, so we can
  14. +// still reference it from this file even after we deleted the "global" variable
  15. +// from the global scope.
  16. +const localGlobal = (typeof global !== 'undefined') ? global : undefined;
  17. +// Do the same for "Buffer".
  18. +const localBuffer = (typeof Buffer !== 'undefined') ? Buffer : undefined;
  19. +
  20. const {
  21. isProxy,
  22. } = require('internal/util/types');
  23. @@ -1541,10 +1548,12 @@ Module.prototype._compile = function(content, filename, format) {
  24. this[kIsExecuting] = true;
  25. if (inspectorWrapper) {
  26. result = inspectorWrapper(compiledWrapper, thisValue, exports,
  27. - require, module, filename, dirname);
  28. + require, module, filename, dirname,
  29. + process, localGlobal, localBuffer);
  30. } else {
  31. result = ReflectApply(compiledWrapper, thisValue,
  32. - [exports, require, module, filename, dirname]);
  33. + [exports, require, module, filename,
  34. + dirname, process, localGlobal, localBuffer]);
  35. }
  36. this[kIsExecuting] = false;
  37. if (requireDepth === 0) { statCache = null; }