-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
deps,doc,lib,src,test: add experimental web storage #50169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
'variables': { | ||
'sqlite3_sources': [ | ||
'sqlite3.c', | ||
], | ||
}, | ||
'targets': [ | ||
{ | ||
'target_name': 'sqlite3', | ||
'type': 'static_library', | ||
'include_dirs': ['.'], | ||
'sources': [ | ||
'<@(sqlite3_sources)', | ||
], | ||
'direct_dependent_settings': { | ||
'include_dirs': ['.'], | ||
}, | ||
}, | ||
], | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -560,6 +560,23 @@ changes: | |
|
||
A browser-compatible implementation of {Headers}. | ||
|
||
## `localStorage` | ||
|
||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
> Stability: 1 - Experimental. | ||
|
||
A browser-compatible implementation of [`localStorage`][]. Data is stored | ||
unencrypted in the current working directory, with a storage quota of 10 MB. | ||
The filename of the persisted storage is the basename of the main entrypoint, | ||
`process.argv[1]`, followed by a dot (`.`), a hash of the entrypoint's absolute | ||
path and a `.localstorage` extension. If Node.js is run without a file as the | ||
entrypoint, such as when running the REPL, then the executable's basename is | ||
used. Any modification of this data outside of the Web Storage API is not | ||
supported. Enable this API with the [`--experimental-webstorage`][] CLI flag. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a worker thread, does the |
||
|
||
## `MessageChannel` | ||
|
||
<!-- YAML | ||
|
@@ -855,6 +872,19 @@ changes: | |
|
||
A browser-compatible implementation of {Request}. | ||
|
||
## `sessionStorage` | ||
|
||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
> Stability: 1 - Experimental. | ||
|
||
A browser-compatible implementation of [`sessionStorage`][]. Data is stored in | ||
memory, with a storage quota of 10 MB. Any modification of this data outside of | ||
the Web Storage API is not supported. Enable this API with the | ||
[`--experimental-webstorage`][] CLI flag. | ||
|
||
## `setImmediate(callback[, ...args])` | ||
|
||
<!-- YAML | ||
|
@@ -885,6 +915,17 @@ added: v0.0.1 | |
|
||
[`setTimeout`][] is described in the [timers][] section. | ||
|
||
## Class: `Storage` | ||
|
||
<!-- YAML | ||
added: REPLACEME | ||
--> | ||
|
||
> Stability: 1 - Experimental. | ||
|
||
A browser-compatible implementation of [`Storage`][]. Enable this API with the | ||
[`--experimental-webstorage`][] CLI flag. | ||
|
||
## `structuredClone(value[, options])` | ||
|
||
<!-- YAML | ||
|
@@ -1064,6 +1105,7 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][]. | |
[Navigator API]: https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object | ||
[Web Crypto API]: webcrypto.md | ||
[`--experimental-websocket`]: cli.md#--experimental-websocket | ||
[`--experimental-webstorage`]: cli.md#--experimental-webstorage | ||
[`--no-experimental-global-customevent`]: cli.md#--no-experimental-global-customevent | ||
[`--no-experimental-global-webcrypto`]: cli.md#--no-experimental-global-webcrypto | ||
[`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController | ||
|
@@ -1089,6 +1131,7 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][]. | |
[`ReadableStreamDefaultController`]: webstreams.md#class-readablestreamdefaultcontroller | ||
[`ReadableStreamDefaultReader`]: webstreams.md#class-readablestreamdefaultreader | ||
[`ReadableStream`]: webstreams.md#class-readablestream | ||
[`Storage`]: https://developer.mozilla.org/en-US/docs/Web/API/Storage | ||
[`TextDecoderStream`]: webstreams.md#class-textdecoderstream | ||
[`TextDecoder`]: util.md#class-utiltextdecoder | ||
[`TextEncoderStream`]: webstreams.md#class-textencoderstream | ||
|
@@ -1113,11 +1156,13 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][]. | |
[`exports`]: modules.md#exports | ||
[`fetch()`]: https://developer.mozilla.org/en-US/docs/Web/API/fetch | ||
[`globalThis`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis | ||
[`localStorage`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage | ||
[`module`]: modules.md#module | ||
[`perf_hooks.performance`]: perf_hooks.md#perf_hooksperformance | ||
[`process.nextTick()`]: process.md#processnexttickcallback-args | ||
[`process` object]: process.md#process | ||
[`require()`]: modules.md#requireid | ||
[`sessionStorage`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage | ||
[`setImmediate`]: timers.md#setimmediatecallback-args | ||
[`setInterval`]: timers.md#setintervalcallback-delay-args | ||
[`setTimeout`]: timers.md#settimeoutcallback-delay-args | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
const { | ||
MathAbs, | ||
ObjectDefineProperty, | ||
StringPrototypeCharCodeAt, | ||
} = primordials; | ||
const { emitExperimentalWarning } = require('internal/util'); | ||
const { kConstructorKey, Storage } = internalBinding('webstorage'); | ||
const { basename, join } = require('path'); | ||
|
||
emitExperimentalWarning('Web storage'); | ||
|
||
module.exports = { Storage }; | ||
|
||
let lazyLocalStorage; | ||
let lazySessionStorage; | ||
|
||
ObjectDefineProperty(module.exports, 'localStorage', { | ||
cjihrig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
__proto__: null, | ||
configurable: true, | ||
enumerable: true, | ||
get() { | ||
if (lazyLocalStorage === undefined) { | ||
const entry = process.argv[1] ?? process.argv[0]; | ||
const base = basename(entry); | ||
const hash = hashCode(entry); | ||
const location = join(process.cwd(), `${base}.${hash}.localstorage`); | ||
|
||
lazyLocalStorage = new Storage(kConstructorKey, location); | ||
} | ||
|
||
return lazyLocalStorage; | ||
}, | ||
}); | ||
|
||
ObjectDefineProperty(module.exports, 'sessionStorage', { | ||
__proto__: null, | ||
configurable: true, | ||
enumerable: true, | ||
get() { | ||
if (lazySessionStorage === undefined) { | ||
lazySessionStorage = new Storage(kConstructorKey, ':memory:'); | ||
} | ||
|
||
return lazySessionStorage; | ||
}, | ||
}); | ||
|
||
function hashCode(s) { | ||
let h = 0; | ||
|
||
for (let i = 0; i < s.length; ++i) { | ||
h = (h << 5) - h + StringPrototypeCharCodeAt(s, i) | 0; | ||
} | ||
|
||
return MathAbs(h); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ | |
V(wasi) \ | ||
V(wasm_web_api) \ | ||
V(watchdog) \ | ||
V(webstorage) \ | ||
V(worker) \ | ||
V(zlib) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.