aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2024-06-12 22:15:25 +0000
committerstephan <stephan@noemail.net>2024-06-12 22:15:25 +0000
commit709cb313cf7b2da986ec2c0ca6510147ac702538 (patch)
treea3a64481a47cd27d79d6ac67aa1b87a4005c4fc9 /ext/wasm/api
parent063a2b338c8bf6c7dd4c156c629f26250c60ffe9 (diff)
downloadsqlite-709cb313cf7b2da986ec2c0ca6510147ac702538.tar.gz
sqlite-709cb313cf7b2da986ec2c0ca6510147ac702538.zip
Remove some dead JS code. Improve the exception-to-C-result-code conversion to account for the case of a file disappearing while the OPFS VFS is waiting to acquire a lock on it.
FossilOrigin-Name: 5bd9fd5f61e7cd1ed3b44c5cabc759c154c98eb40ad10d29e61f142aaa062ddf
Diffstat (limited to 'ext/wasm/api')
-rw-r--r--ext/wasm/api/sqlite3-opfs-async-proxy.js54
-rw-r--r--ext/wasm/api/sqlite3-vfs-opfs.c-pp.js1
2 files changed, 27 insertions, 28 deletions
diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js
index 48cddd7ef..a2c052d32 100644
--- a/ext/wasm/api/sqlite3-opfs-async-proxy.js
+++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js
@@ -265,23 +265,34 @@ const installAsyncProxy = function(){
this.name = 'GetSyncHandleError';
}
};
+
+ /**
+ Attempts to find a suitable SQLITE_xyz result code for Error
+ object e. Returns either such a translation or rc if if it does
+ not know how to translate the exception.
+ */
GetSyncHandleError.convertRc = (e,rc)=>{
- if(1){
- return (
- e instanceof GetSyncHandleError
- && ((e.cause.name==='NoModificationAllowedError')
- /* Inconsistent exception.name from Chrome/ium with the
- same exception.message text: */
- || (e.cause.name==='DOMException'
- && 0===e.cause.message.indexOf('Access Handles cannot')))
- ) ? (
- /*console.warn("SQLITE_BUSY",e),*/
- state.sq3Codes.SQLITE_BUSY
- ) : rc;
- }else{
- return rc;
+ if( e instanceof GetSyncHandleError ){
+ if( e.cause.name==='NoModificationAllowedError'
+ /* Inconsistent exception.name from Chrome/ium with the
+ same exception.message text: */
+ || (e.cause.name==='DOMException'
+ && 0===e.cause.message.indexOf('Access Handles cannot')) ){
+ return state.sq3Codes.SQLITE_BUSY;
+ }else if( 'NotFoundError'===e.cause.name ){
+ /**
+ Maintenance reminder: SQLITE_NOTFOUND, though it looks like
+ a good match, has different semantics than NotFoundError
+ and is not suitable here.
+ */
+ return state.sq3Codes.SQLITE_CANTOPEN;
+ }
+ }else if( 'NotFoundError'===e?.name ){
+ return state.sq3Codes.SQLITE_CANTOPEN;
}
- }
+ return rc;
+ };
+
/**
Returns the sync access handle associated with the given file
handle object (which must be a valid handle object, as created by
@@ -600,19 +611,6 @@ const installAsyncProxy = function(){
fh.releaseImplicitLocks =
(opfsFlags & state.opfsFlags.OPFS_UNLOCK_ASAP)
|| state.opfsFlags.defaultUnlockAsap;
- if(0 /* this block is modelled after something wa-sqlite
- does but it leads to immediate contention on journal files.
- Update: this approach reportedly only works for DELETE journal
- mode. */
- && (0===(flags & state.sq3Codes.SQLITE_OPEN_MAIN_DB))){
- /* sqlite does not lock these files, so go ahead and grab an OPFS
- lock. */
- fh.xLock = "xOpen"/* Truthy value to keep entry from getting
- flagged as auto-locked. String value so
- that we can easily distinguish is later
- if needed. */;
- await getSyncHandle(fh,'xOpen');
- }
__openFiles[fid] = fh;
storeAndNotify(opName, 0);
}catch(e){
diff --git a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
index 603a3e474..ee6937c69 100644
--- a/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
+++ b/ext/wasm/api/sqlite3-vfs-opfs.c-pp.js
@@ -390,6 +390,7 @@ const installOpfsVfs = function callee(options){
'SQLITE_ACCESS_EXISTS',
'SQLITE_ACCESS_READWRITE',
'SQLITE_BUSY',
+ 'SQLITE_CANTOPEN',
'SQLITE_ERROR',
'SQLITE_IOERR',
'SQLITE_IOERR_ACCESS',