forked from electron/electron
/
refactor_allow_embedder_overriding_of_internal_fs_calls.patch
67 lines (60 loc) · 2.8 KB
/
refactor_allow_embedder_overriding_of_internal_fs_calls.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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 58f7396990dddb7dd4cf3d23fcdcc1d48f52623e..ef06d0563fa7452348754418867a56c9b8c6f4e1 100644
--- a/lib/internal/bootstrap/node.js
+++ b/lib/internal/bootstrap/node.js
@@ -62,6 +62,10 @@ setupBuffer();
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 nativeModule = internalBinding('native_module');
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 67eb7717f13379312721fc4da2e760bc08d8ed3a..05a62bb3c3852536001912cb0b69fe5578ace125 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -86,7 +86,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 {
@@ -161,7 +161,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 };