aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-opfs-async-proxy.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-11-02 11:53:31 +0000
committerstephan <stephan@noemail.net>2022-11-02 11:53:31 +0000
commitf45c33701dde9412e6aeab464a8148ab112bb033 (patch)
treee001384725393439c7f820dc5d21b3eecd90072e /ext/wasm/api/sqlite3-opfs-async-proxy.js
parentfaff0410dc6de77edb727eac65c570e604599a83 (diff)
downloadsqlite-f45c33701dde9412e6aeab464a8148ab112bb033.tar.gz
sqlite-f45c33701dde9412e6aeab464a8148ab112bb033.zip
Add sqlite3_wasm_vfs_create_file() to replace Emscripten's FS.createDataFile() in a (mostly) VFS-agnostic way. Add a test for worker1's export (to bytearray) support. Re-add worker1 open-from-bytearray using sqlite3_wasm_vfs_create_file() but it's untested (requires a new interactive test app or maybe reconsideration).
FossilOrigin-Name: b35e1225c91a3cadc0d25af1e4e790237256d194990faa13190e343ed03e11c5
Diffstat (limited to 'ext/wasm/api/sqlite3-opfs-async-proxy.js')
-rw-r--r--ext/wasm/api/sqlite3-opfs-async-proxy.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js
index e3c3b8214..86276910a 100644
--- a/ext/wasm/api/sqlite3-opfs-async-proxy.js
+++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js
@@ -230,6 +230,16 @@ const storeAndNotify = (opName, value)=>{
const affirmNotRO = function(opName,fh){
if(fh.readOnly) toss(opName+"(): File is read-only: "+fh.filenameAbs);
};
+const affirmLocked = function(opName,fh){
+ //if(!fh.syncHandle) toss(opName+"(): File does not have a lock: "+fh.filenameAbs);
+ /**
+ Currently a no-op, as speedtest1 triggers xRead() without a
+ lock (that seems like a bug but it's currently uninvestigated).
+ This means, however, that some OPFS VFS routines may trigger
+ acquisition of a lock but never let it go until xUnlock() is
+ called (which it likely won't be if xLock() was not called).
+ */
+};
/**
We track 2 different timers: the "metrics" timer records how much
@@ -395,6 +405,7 @@ const vfsAsyncImpls = {
let rc;
wTimeStart('xFileSize');
try{
+ affirmLocked('xFileSize',fh);
rc = await (await getSyncHandle(fh)).getSize();
state.s11n.serialize(Number(rc));
rc = 0;
@@ -473,6 +484,7 @@ const vfsAsyncImpls = {
let rc = 0, nRead;
const fh = __openFiles[fid];
try{
+ affirmLocked('xRead',fh);
wTimeStart('xRead');
nRead = (await getSyncHandle(fh)).read(
fh.sabView.subarray(0, n),
@@ -515,6 +527,7 @@ const vfsAsyncImpls = {
const fh = __openFiles[fid];
wTimeStart('xTruncate');
try{
+ affirmLocked('xTruncate',fh);
affirmNotRO('xTruncate', fh);
await (await getSyncHandle(fh)).truncate(size);
}catch(e){
@@ -547,9 +560,10 @@ const vfsAsyncImpls = {
xWrite: async function(fid/*sqlite3_file pointer*/,n,offset64){
mTimeStart('xWrite');
let rc;
+ const fh = __openFiles[fid];
wTimeStart('xWrite');
try{
- const fh = __openFiles[fid];
+ affirmLocked('xWrite',fh);
affirmNotRO('xWrite', fh);
rc = (
n === (await getSyncHandle(fh))