mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
3d09e579d3
This commit introduces an experimental implementation of the Web Storage API using SQLite as the backing data store. PR-URL: https://github.com/nodejs/node/pull/52435 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
'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 { resolve, toNamespacedPath } = require('path');
|
|
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) {
|
|
let location = getOptionValue('--localstorage-file');
|
|
|
|
if (location === '') {
|
|
throw new ERR_INVALID_ARG_VALUE('--localstorage-file',
|
|
location,
|
|
'is an invalid localStorage location');
|
|
}
|
|
|
|
location = toNamespacedPath(resolve(getValidatedPath(location)));
|
|
lazyLocalStorage = new Storage(kConstructorKey, location);
|
|
}
|
|
|
|
return lazyLocalStorage;
|
|
},
|
|
},
|
|
sessionStorage: {
|
|
__proto__: null,
|
|
configurable: true,
|
|
enumerable: true,
|
|
get() {
|
|
if (lazySessionStorage === undefined) {
|
|
lazySessionStorage = new Storage(kConstructorKey, kInMemoryPath);
|
|
}
|
|
|
|
return lazySessionStorage;
|
|
},
|
|
},
|
|
});
|