From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Mon, 22 Apr 2019 13:23:37 -0700
Subject: refactor: allow embedder overriding of internal FS calls

We use this to allow node's 'fs' module to read from ASAR files as if they were
a real filesystem.

diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js
index 81b441a554e34556fc41066fc8761c713acb0ced..7dd89d5f134b09da2678dd54fa9139466fea179c 100644
--- a/lib/internal/bootstrap/node.js
+++ b/lib/internal/bootstrap/node.js
@@ -101,6 +101,10 @@ process.domain = null;
 }
 process._exiting = false;
 
+// NOTE: Electron deletes this references before user code runs so that
+// internalBinding is not leaked to user code.
+process.internalBinding = internalBinding;
+
 // TODO(@jasnell): Once this has gone through one full major
 // release cycle, remove the Proxy and setter and update the
 // getter to either return a read-only object or always return
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 9da60135ac79a2034a646c0a1380923f7fbfacab..207142322bba89e94f4e3052a22bef6ffebcdc39 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -94,7 +94,7 @@ const fs = require('fs');
 const internalFS = require('internal/fs/utils');
 const path = require('path');
 const { sep } = path;
-const { internalModuleStat } = internalBinding('fs');
+const internalFsBinding = internalBinding('fs');
 const packageJsonReader = require('internal/modules/package_json_reader');
 const { safeGetenv } = internalBinding('credentials');
 const {
@@ -171,7 +171,7 @@ function stat(filename) {
     const result = statCache.get(filename);
     if (result !== undefined) return result;
   }
-  const result = internalModuleStat(filename);
+  const result = internalFsBinding.internalModuleStat(filename);
   if (statCache !== null && result >= 0) {
     // Only set cache when `internalModuleStat(filename)` succeeds.
     statCache.set(filename, result);
diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js
index 09eb12bd1533bfed44d9cb62c068e2c880df8ba2..11a6e4b2edc0930049d7acecf2a6e94e51abeb1c 100644
--- a/lib/internal/modules/package_json_reader.js
+++ b/lib/internal/modules/package_json_reader.js
@@ -1,7 +1,7 @@
 'use strict';
 
 const { SafeMap } = primordials;
-const { internalModuleReadJSON } = internalBinding('fs');
+const internalFsBinding = internalBinding('fs');
 const { pathToFileURL } = require('url');
 const { toNamespacedPath } = require('path');
 
@@ -18,7 +18,7 @@ function read(jsonPath) {
     return cache.get(jsonPath);
   }
 
-  const { 0: string, 1: containsKeys } = internalModuleReadJSON(
+  const { 0: string, 1: containsKeys } = internalFsBinding.internalModuleReadJSON(
     toNamespacedPath(jsonPath)
   );
   const result = { string, containsKeys };
