-
Notifications
You must be signed in to change notification settings - Fork 30.6k
/
Copy pathwebstorage.js
53 lines (45 loc) · 1.42 KB
/
webstorage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'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) {
const location = getOptionValue('--localstorage-file');
if (location === '') {
throw new ERR_INVALID_ARG_VALUE('--localstorage-file',
location,
'is an invalid localStorage location');
}
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;
},
},
});