mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
PR-URL: https://github.com/nodejs/node/pull/60351 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
'use strict';
|
|
const {
|
|
ObjectDefineProperties,
|
|
} = primordials;
|
|
const { getOptionValue } = require('internal/options');
|
|
const { lazyDOMException } = require('internal/util');
|
|
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) {
|
|
// For consistency with the web specification, throw from the accessor
|
|
// if the local storage path is not provided.
|
|
const location = getOptionValue('--localstorage-file');
|
|
if (location === '') {
|
|
throw lazyDOMException(
|
|
'Cannot initialize local storage without a `--localstorage-file` path',
|
|
'SecurityError',
|
|
);
|
|
}
|
|
|
|
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;
|
|
},
|
|
},
|
|
});
|