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 d42e766555a83ec7421b13c2bf75bfd28f086102..57125a271394dda0d3aa3a261ba087c978582c29 100644
--- a/lib/internal/bootstrap/node.js
+++ b/lib/internal/bootstrap/node.js
@@ -134,6 +134,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;
+
 // process.config is serialized config.gypi
 const binding = internalBinding('builtins');
 
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 276ab42c22b796ee07ce66744187adca6a8b8da4..155485dbab0d46bb225fa40e99f555d805659c4f 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -102,7 +102,7 @@ const {
 const assert = require('internal/assert');
 const fs = require('fs');
 const path = require('path');
-const { internalModuleStat } = internalBinding('fs');
+const internalFsBinding = internalBinding('fs');
 const { safeGetenv } = internalBinding('credentials');
 const {
   privateSymbols: {
@@ -196,7 +196,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 88c079d10d116107aa34dc9281f64c799c48c0b5..069f922612777f226127dc44f4091eed30416925 100644
--- a/lib/internal/modules/package_json_reader.js
+++ b/lib/internal/modules/package_json_reader.js
@@ -12,7 +12,7 @@ const {
 const {
   ERR_INVALID_PACKAGE_CONFIG,
 } = require('internal/errors').codes;
-const { internalModuleReadJSON } = internalBinding('fs');
+const internalFsBinding = internalBinding('fs');
 const { resolve, sep, toNamespacedPath } = require('path');
 const permission = require('internal/process/permission');
 const { kEmptyObject } = require('internal/util');
@@ -53,7 +53,7 @@ function read(jsonPath, { base, specifier, isESM } = kEmptyObject) {
   const {
     0: string,
     1: containsKeys,
-  } = internalModuleReadJSON(
+  } = internalFsBinding.internalModuleReadJSON(
     toNamespacedPath(jsonPath),
   );
   const result = {
