[v25.x] lib: do not provide an empty Proxy from localStorage getter by Renegade334 · Pull Request #60776 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 8 additions & 27 deletions lib/internal/webstorage.js
14 changes: 13 additions & 1 deletion test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const hasSQLite = Boolean(process.versions.sqlite);

const hasQuic = hasCrypto && !!process.features.quic;

const hasLocalStorage = hasSQLite &&
process.execArgv.find((arg) => arg.startsWith('--localstorage-file=')) !== undefined;

/**
* Parse test metadata from the specified file.
* @param {string} filename - The name of the file to parse.
Expand Down Expand Up @@ -351,7 +354,6 @@ const knownGlobals = new Set([
'CompressionStream',
'DecompressionStream',
'Storage',
'localStorage',
'sessionStorage',
].forEach((i) => {
if (globalThis[i] !== undefined) {
Expand All @@ -366,6 +368,10 @@ if (hasCrypto) {
knownGlobals.add(globalThis.SubtleCrypto);
}

if (hasLocalStorage) {
knownGlobals.add(globalThis.localStorage);
}

const { Worker } = require('node:worker_threads');
knownGlobals.add(Worker);

Expand All @@ -390,6 +396,11 @@ if (process.env.NODE_TEST_KNOWN_GLOBALS !== '0') {
if (val === 'crypto' && !hasCrypto) {
continue;
}
// globalThis.localStorage is a getter that warns if Node.js was
// executed without a --localstorage-file path.
if (val === 'localStorage' && !hasLocalStorage) {
continue;
}
if (!knownGlobals.has(globalThis[val])) {
leaked.push(val);
}
Expand Down Expand Up @@ -940,6 +951,7 @@ const common = {
hasQuic,
hasInspector,
hasSQLite,
hasLocalStorage,
invalidArgTypeHelper,
isAlive,
isASan,
Expand Down
2 changes: 2 additions & 0 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
hasQuic,
hasInspector,
hasSQLite,
hasLocalStorage,
hasIntl,
hasIPv6,
isAIX,
Expand Down Expand Up @@ -72,6 +73,7 @@ export {
hasQuic,
hasInspector,
hasSQLite,
hasLocalStorage,
hasIntl,
hasIPv6,
isAIX,
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-assert-checktag.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const { hasCrypto } = require('../common');
const { hasCrypto, hasLocalStorage } = require('../common');
const { test } = require('node:test');
const assert = require('assert');

Expand All @@ -12,7 +12,7 @@ const assert = require('assert');
if (process.stdout.isTTY)
process.env.NODE_DISABLE_COLORS = '1';

test('', { skip: !hasCrypto }, () => {
test({ skip: !hasCrypto || !hasLocalStorage }, () => {
// See https://github.com/nodejs/node/issues/10258
{
const date = new Date('2016');
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-webstorage.js
Loading