2023-09-15 14:32:14 +00:00
|
|
|
'use strict';
|
|
|
|
const {
|
|
|
|
ObjectDefineProperties,
|
|
|
|
} = primordials;
|
|
|
|
const { ERR_INVALID_ARG_VALUE } = require('internal/errors').codes;
|
|
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
const { emitExperimentalWarning } = require('internal/util');
|
|
|
|
const { kConstructorKey, Storage } = internalBinding('webstorage');
|
|
|
|
const { getValidatedPath } = require('internal/fs/utils');
|
|
|
|
const kInMemoryPath = ':memory:';
|
|
|
|
|
|
|
|
emitExperimentalWarning('Web Storage');
|
|
|
|
|
|
|
|
module.exports = { Storage };
|
|
|
|
|
|
|
|
let lazyLocalStorage;
|
|
|
|
let lazySessionStorage;
|
|
|
|
|
|
|
|
ObjectDefineProperties(module.exports, {
|
|
|
|
__proto__: null,
|
|
|
|
localStorage: {
|
|
|
|
__proto__: null,
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
get() {
|
|
|
|
if (lazyLocalStorage === undefined) {
|
2024-07-21 20:49:10 +00:00
|
|
|
const location = getOptionValue('--localstorage-file');
|
2023-09-15 14:32:14 +00:00
|
|
|
|
|
|
|
if (location === '') {
|
|
|
|
throw new ERR_INVALID_ARG_VALUE('--localstorage-file',
|
|
|
|
location,
|
|
|
|
'is an invalid localStorage location');
|
|
|
|
}
|
|
|
|
|
2024-07-21 20:49:10 +00:00
|
|
|
lazyLocalStorage = new Storage(kConstructorKey, getValidatedPath(location));
|
2023-09-15 14:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return lazyLocalStorage;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sessionStorage: {
|
|
|
|
__proto__: null,
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
get() {
|
|
|
|
if (lazySessionStorage === undefined) {
|
|
|
|
lazySessionStorage = new Storage(kConstructorKey, kInMemoryPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return lazySessionStorage;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|