1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Merge kv-vfs-magic-names branch into fiddle-opfs branch and make some kvvfs-relevant tweaks.

FossilOrigin-Name: e3d36dcdd37e59f17a07d3611d08744eb86f439fab82a648490dd608bcaa3185
This commit is contained in:
stephan
2022-09-20 16:10:39 +00:00
7 changed files with 48 additions and 22 deletions

View File

@ -104,12 +104,24 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
*/
const dbCtorHelper = function ctor(...args){
if(!ctor._name2vfs){
// Map special filenames which we handle here (instead of in C)
// to some helpful metadata...
/**
Map special filenames which we handle here (instead of in C)
to some helpful metadata...
As of 2022-09-20, the C API supports the names :localStorage:
and :sessionStorage: for kvvfs. However, C code cannot
determine (without embedded JS code, e.g. via Emscripten's
EM_JS()) whether the kvvfs is legal in the current browser
context (namely the main UI thread). In order to help client
code fail early on, instead of it being delayed until they
try to read or write a kvvfs-backed db, we'll check for those
names here and throw if they're not legal in the current
context.
*/
ctor._name2vfs = Object.create(null);
const isWorkerThread = (self.window===self /*===running in main window*/)
? false
: (n)=>toss3("The VFS for",n,"is only available in the main window thread.")
const isWorkerThread = ('function'===typeof importScripts/*===running in worker thread*/)
? (n)=>toss3("The VFS for",n,"is only available in the main window thread.")
: false;
ctor._name2vfs[':localStorage:'] = {
vfs: 'kvvfs',
filename: isWorkerThread || (()=>'local')