Skip to content

Commit b54c27d

Browse files
committed
module: refactor to avoid unsafe array iteration
nodejs/node#36680
1 parent 4c2f376 commit b54c27d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

patches/node/refactor_allow_embedder_overriding_of_internal_fs_calls.patch

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js
1010
index 2705f8b50a658db0fc1ce6fba245792f6a567300..5aab40071b68affe602be16d451be598b246faa1 100644
1111
--- a/lib/internal/bootstrap/node.js
1212
+++ b/lib/internal/bootstrap/node.js
13-
@@ -57,6 +57,10 @@ setupBuffer();
13+
@@ -62,6 +62,10 @@ setupBuffer();
1414
process.domain = null;
1515
process._exiting = false;
1616

@@ -19,8 +19,9 @@ index 2705f8b50a658db0fc1ce6fba245792f6a567300..5aab40071b68affe602be16d451be598
1919
+process.internalBinding = internalBinding;
2020
+
2121
// process.config is serialized config.gypi
22-
process.config = JSONParse(internalBinding('native_module').config);
23-
require('internal/worker/js_transferable').setup();
22+
const nativeModule = internalBinding('native_module');
23+
24+
2425
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
2526
index ef52bf6486d8c827dce105e50b57c1129dcaf5a4..e2a205739ce89820fe5f1f24e609ff16b86afb04 100644
2627
--- a/lib/internal/modules/cjs/loader.js
@@ -34,15 +35,16 @@ index ef52bf6486d8c827dce105e50b57c1129dcaf5a4..e2a205739ce89820fe5f1f24e609ff16
3435
const packageJsonReader = require('internal/modules/package_json_reader');
3536
const { safeGetenv } = internalBinding('credentials');
3637
const {
37-
@@ -143,7 +143,7 @@ function stat(filename) {
38+
@@ -157,7 +157,7 @@ function stat(filename) {
3839
const result = statCache.get(filename);
3940
if (result !== undefined) return result;
4041
}
4142
- const result = internalModuleStat(filename);
4243
+ const result = internalFsBinding.internalModuleStat(filename);
43-
if (statCache !== null) statCache.set(filename, result);
44-
return result;
45-
}
44+
if (statCache !== null && result >= 0) {
45+
// Only set cache when `internalModuleStat(filename)` succeeds.
46+
statCache.set(filename, result);
47+
4648
diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js
4749
index 4a2b0e6ddb3ed8881f896c6f556c9debaf778b81..209df9033a26c29c6e60bd173f71055884a0db89 100644
4850
--- a/lib/internal/modules/package_json_reader.js
@@ -60,8 +62,8 @@ index 4a2b0e6ddb3ed8881f896c6f556c9debaf778b81..209df9033a26c29c6e60bd173f710558
6062
return cache.get(jsonPath);
6163
}
6264

63-
- const [string, containsKeys] = internalModuleReadJSON(
64-
+ const [string, containsKeys] = internalFsBinding.internalModuleReadJSON(
65+
- const { 0: string, 1: containsKeys } = internalModuleReadJSON(
66+
+ const { 0: string, 1: containsKeys } = internalFsBinding.internalModuleReadJSON(
6567
toNamespacedPath(jsonPath)
6668
);
6769
const result = { string, containsKeys };

0 commit comments

Comments
 (0)