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 0b85bc8af1af275f05318bd315d9c6b9a5d3d6dd..5bebce776dc60052aa01422af29d7766033e7331 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -109,6 +109,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');
@@ -1058,10 +1065,12 @@ Module.prototype._compile = function(content, filename) {
   if (requireDepth === 0) statCache = new Map();
   if (inspectorWrapper) {
     result = inspectorWrapper(compiledWrapper, thisValue, exports,
-                              require, module, filename, dirname);
+                              require, module, filename, dirname,
+                              process, localGlobal, localBuffer);
   } else {
     result = compiledWrapper.call(thisValue, exports, require, module,
-                                  filename, dirname);
+                                  filename, dirname, process, localGlobal,
+                                  localBuffer);
   }
   hasLoadedAnyUserCJSModule = true;
   if (requireDepth === 0) statCache = null;