diff options
author | stephan <stephan@noemail.net> | 2022-09-20 16:10:39 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-09-20 16:10:39 +0000 |
commit | fa5aac7475494695dbae52e0c60718167597e721 (patch) | |
tree | 47cb0de1f08daae78c45a695c55e141283dfbe91 /ext/wasm/api/sqlite3-api-oo1.js | |
parent | 89071030db862b7b9b26f214c3508e607b9b430d (diff) | |
parent | c3b6fdaead863709e532832c1341f1bebce504f2 (diff) | |
download | sqlite-fa5aac7475494695dbae52e0c60718167597e721.tar.gz sqlite-fa5aac7475494695dbae52e0c60718167597e721.zip |
Merge kv-vfs-magic-names branch into fiddle-opfs branch and make some kvvfs-relevant tweaks.
FossilOrigin-Name: e3d36dcdd37e59f17a07d3611d08744eb86f439fab82a648490dd608bcaa3185
Diffstat (limited to 'ext/wasm/api/sqlite3-api-oo1.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-oo1.js | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index fb01e9871..25ca34dda 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -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') |