node/lib/internal/webstorage.js
Daniel M Brasil 3312e4e946
src: unflag --experimental-webstorage by default
PR-URL: https://github.com/nodejs/node/pull/57666
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-09-25 11:59:58 +00:00

70 lines
1.8 KiB
JavaScript

'use strict';
const {
ObjectDefineProperties,
Proxy,
} = primordials;
const { getOptionValue } = require('internal/options');
const { kConstructorKey, Storage } = internalBinding('webstorage');
const { getValidatedPath } = require('internal/fs/utils');
const kInMemoryPath = ':memory:';
module.exports = { Storage };
let lazyLocalStorage;
let lazySessionStorage;
ObjectDefineProperties(module.exports, {
__proto__: null,
localStorage: {
__proto__: null,
configurable: true,
enumerable: true,
get() {
if (lazyLocalStorage === undefined) {
const location = getOptionValue('--localstorage-file');
if (location === '') {
let warningEmitted = false;
const handler = {
__proto__: null,
get(target, prop) {
if (!warningEmitted) {
process.emitWarning('`--localstorage-file` was provided without a valid path');
warningEmitted = true;
}
return undefined;
},
set(target, prop, value) {
if (!warningEmitted) {
process.emitWarning('`--localstorage-file` was provided without a valid path');
warningEmitted = true;
}
return false;
},
};
lazyLocalStorage = new Proxy({}, handler);
} else {
lazyLocalStorage = new Storage(kConstructorKey, getValidatedPath(location));
}
}
return lazyLocalStorage;
},
},
sessionStorage: {
__proto__: null,
configurable: true,
enumerable: true,
get() {
if (lazySessionStorage === undefined) {
lazySessionStorage = new Storage(kConstructorKey, kInMemoryPath);
}
return lazySessionStorage;
},
},
});