Skip to content

Commit 8abbca3

Browse files
ryuhei shimaryuhei shima
authored andcommitted
guard webstorage inspector hook behind hasInspector
1 parent 37e22ff commit 8abbca3

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/internal/webstorage.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,31 @@
22
const {
33
ObjectDefineProperties,
44
} = primordials;
5+
const { hasInspector } = internalBinding('config');
56
const { getOptionValue } = require('internal/options');
67
const { kConstructorKey, Storage } = internalBinding('webstorage');
78
const { getValidatedPath } = require('internal/fs/utils');
8-
const { InspectorLocalStorage, InspectorSessionStorage } = require('internal/inspector/webstorage');
99
const kInMemoryPath = ':memory:';
1010

1111
module.exports = { Storage };
1212

1313
let lazyLocalStorage;
1414
let lazySessionStorage;
15+
let lazyInspectorStorage;
1516
let localStorageWarned = false;
1617

1718
// Check at load time if localStorage file is provided to determine enumerability.
1819
// If not provided, localStorage is non-enumerable to avoid breaking {...globalThis}.
1920
const localStorageLocation = getOptionValue('--localstorage-file');
21+
const experimentalStorageInspection =
22+
hasInspector && getOptionValue('--experimental-storage-inspection');
23+
24+
function getInspectorStorage() {
25+
if (lazyInspectorStorage === undefined) {
26+
lazyInspectorStorage = require('internal/inspector/webstorage');
27+
}
28+
return lazyInspectorStorage;
29+
}
2030

2131
ObjectDefineProperties(module.exports, {
2232
__proto__: null,
@@ -37,7 +47,8 @@ ObjectDefineProperties(module.exports, {
3747
return undefined;
3848
}
3949

40-
if (getOptionValue('--experimental-storage-inspection')) {
50+
if (experimentalStorageInspection) {
51+
const { InspectorLocalStorage } = getInspectorStorage();
4152
lazyLocalStorage = new InspectorLocalStorage(kConstructorKey, getValidatedPath(localStorageLocation), true);
4253
} else {
4354
lazyLocalStorage = new Storage(kConstructorKey, getValidatedPath(localStorageLocation));
@@ -52,7 +63,8 @@ ObjectDefineProperties(module.exports, {
5263
enumerable: true,
5364
get() {
5465
if (lazySessionStorage === undefined) {
55-
if (getOptionValue('--experimental-storage-inspection')) {
66+
if (experimentalStorageInspection) {
67+
const { InspectorSessionStorage } = getInspectorStorage();
5668
lazySessionStorage = new InspectorSessionStorage(kConstructorKey, kInMemoryPath, false);
5769
} else {
5870
lazySessionStorage = new Storage(kConstructorKey, kInMemoryPath);

src/node_builtins.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
121121
"internal/inspector/network", "internal/inspector/network_http",
122122
"internal/inspector/network_http2", "internal/inspector/network_undici",
123123
"internal/inspector_async_hook", "internal/inspector_network_tracking",
124+
"internal/inspector/webstorage",
124125
#endif // !HAVE_INSPECTOR
125126

126127
#if !NODE_USE_V8_PLATFORM || !defined(NODE_HAVE_I18N_SUPPORT)

0 commit comments

Comments
 (0)