@@ -64,11 +64,14 @@ const installAsyncProxy = function (self) {
64
64
toss ( 'This API requires navigator.storage.getDirectory.' ) ;
65
65
}
66
66
67
- /** Will hold state copied to this object from the syncronous side of this API. */
67
+ /**
68
+ * Will hold state copied to this object from the syncronous side of
69
+ * this API.
70
+ */
68
71
const state = Object . create ( null ) ;
69
72
70
73
/**
71
- * Verbose :
74
+ * verbose :
72
75
*
73
76
* 0 = no logging output
74
77
* 1 = only errors
@@ -132,20 +135,20 @@ const installAsyncProxy = function (self) {
132
135
} ;
133
136
134
137
/**
135
- * __openFiles is a map of sqlite3_file pointers (integers) to metadata
136
- * related to a given OPFS file handles. The pointers are, in this side of the
137
- * interface, opaque file handle IDs provided by the synchronous part of this
138
- * constellation. Each value is an object with a structure demonstrated in the
139
- * xOpen() impl.
138
+ * __openFiles is a map of sqlite3_file pointers (integers) to
139
+ * metadata related to a given OPFS file handles. The pointers are, in
140
+ * this side of the interface, opaque file handle IDs provided by the
141
+ * synchronous part of this constellation. Each value is an object
142
+ * with a structure demonstrated in the xOpen() impl.
140
143
*/
141
144
const __openFiles = Object . create ( null ) ;
142
145
/**
143
146
* __implicitLocks is a Set of sqlite3_file pointers (integers) which were
144
- * "auto-locked". i.e. those for which we obtained a sync access handle
145
- * without an explicit xLock() call. Such locks will be released during db
146
- * connection idle time, whereas a sync access handle obtained via xLock(), or
147
- * subsequently xLock()'d after auto-acquisition, will not be released until
148
- * xUnlock() is called.
147
+ * "auto-locked". i.e. those for which we obtained a sync access
148
+ * handle without an explicit xLock() call. Such locks will be
149
+ * released during db connection idle time, whereas a sync access
150
+ * handle obtained via xLock(), or subsequently xLock()'d after
151
+ * auto-acquisition, will not be released until xUnlock() is called.
149
152
*
150
153
* Maintenance reminder: if we relinquish auto-locks at the end of the
151
154
* operation which acquires them, we pay a massive performance
@@ -155,21 +158,21 @@ const installAsyncProxy = function (self) {
155
158
const __implicitLocks = new Set ( ) ;
156
159
157
160
/**
158
- * Expects an OPFS file path. It gets resolved, such that ".." components are
159
- * properly expanded, and returned. If the 2nd arg is true, the result is
160
- * returned as an array of path elements, else an absolute path string is
161
- * returned.
161
+ * Expects an OPFS file path. It gets resolved, such that ".."
162
+ * components are properly expanded, and returned. If the 2nd arg is
163
+ * true, the result is returned as an array of path elements, else an
164
+ * absolute path string is returned.
162
165
*/
163
166
const getResolvedPath = function ( filename , splitIt ) {
164
167
const p = new URL ( filename , 'file://irrelevant' ) . pathname ;
165
168
return splitIt ? p . split ( '/' ) . filter ( ( v ) => ! ! v ) : p ;
166
169
} ;
167
170
168
171
/**
169
- * Takes the absolute path to a filesystem element. Returns an array of
170
- * [handleOfContainingDir, filename]. If the 2nd argument is truthy then each
171
- * directory element leading to the file is created along the way. Throws if
172
- * any creation or resolution fails.
172
+ * Takes the absolute path to a filesystem element. Returns an array
173
+ * of [handleOfContainingDir, filename]. If the 2nd argument is truthy
174
+ * then each directory element leading to the file is created along
175
+ * the way. Throws if any creation or resolution fails.
173
176
*/
174
177
const getDirForFilename = async function f ( absFilename , createDirs = false ) {
175
178
const path = getResolvedPath ( absFilename , true ) ;
@@ -184,14 +187,14 @@ const installAsyncProxy = function (self) {
184
187
} ;
185
188
186
189
/**
187
- * If the given file-holding object has a sync handle attached to it, that
188
- * handle is remove and asynchronously closed. Though it may sound sensible to
189
- * continue work as soon as the close() returns (noting that it's
190
- * asynchronous), doing so can cause operations performed soon afterwards,
191
- * e.g. a call to getSyncHandle() to fail because they may happen out of order
192
- * from the close(). OPFS does not guaranty that the actual order of
193
- * operations is retained in such cases. i.e. always "await" on the result of
194
- * this function.
190
+ * If the given file-holding object has a sync handle attached to it,
191
+ * that handle is remove and asynchronously closed. Though it may
192
+ * sound sensible to continue work as soon as the close() returns
193
+ * (noting that it's asynchronous), doing so can cause operations
194
+ * performed soon afterwards, e.g. a call to getSyncHandle() to fail
195
+ * because they may happen out of order from the close(). OPFS does
196
+ * not guaranty that the actual order of operations is retained in
197
+ * such cases. i.e. always "await" on the result of this function.
195
198
*/
196
199
const closeSyncHandle = async ( fh ) => {
197
200
if ( fh . syncHandle ) {
@@ -236,9 +239,9 @@ const installAsyncProxy = function (self) {
236
239
} ;
237
240
238
241
/**
239
- * An experiment in improving concurrency by freeing up implicit locks sooner.
240
- * This is known to impact performance dramatically but it has also shown to
241
- * improve concurrency considerably.
242
+ * An experiment in improving concurrency by freeing up implicit locks
243
+ * sooner. This is known to impact performance dramatically but it has
244
+ * also shown to improve concurrency considerably.
242
245
*
243
246
* If fh.releaseImplicitLocks is truthy and fh is in __implicitLocks,
244
247
* this routine returns closeSyncHandleNoThrow(), else it is a no-op.
@@ -250,11 +253,11 @@ const installAsyncProxy = function (self) {
250
253
} ;
251
254
252
255
/**
253
- * An error class specifically for use with getSyncHandle(), the goal of which
254
- * is to eventually be able to distinguish unambiguously between
255
- * locking-related failures and other types, noting that we cannot currently
256
- * do so because createSyncAccessHandle() does not define its exceptions in
257
- * the required level of detail.
256
+ * An error class specifically for use with getSyncHandle(), the goal
257
+ * of which is to eventually be able to distinguish unambiguously
258
+ * between locking-related failures and other types, noting that we
259
+ * cannot currently do so because createSyncAccessHandle() does not
260
+ * define its exceptions in the required level of detail.
258
261
*
259
262
* 2022-11-29: according to:
260
263
*
@@ -294,9 +297,9 @@ const installAsyncProxy = function (self) {
294
297
}
295
298
} ;
296
299
/**
297
- * Returns the sync access handle associated with the given file handle object
298
- * (which must be a valid handle object, as created by xOpen()), lazily
299
- * opening it if needed.
300
+ * Returns the sync access handle associated with the given file
301
+ * handle object (which must be a valid handle object, as created by
302
+ * xOpen()), lazily opening it if needed.
300
303
*
301
304
* In order to help alleviate cross-tab contention for a dabase, if
302
305
* an exception is thrown while acquiring the handle, this routine
@@ -365,7 +368,7 @@ const installAsyncProxy = function (self) {
365
368
366
369
/**
367
370
* Stores the given value at state.sabOPView[state.opIds.rc] and then
368
- * Atomics.notify()'s it.
371
+ * Atomics.notify()'s it.
369
372
*/
370
373
const storeAndNotify = ( opName , value ) => {
371
374
log ( opName + '() => notify(' , value , ')' ) ;
@@ -379,11 +382,11 @@ const installAsyncProxy = function (self) {
379
382
} ;
380
383
381
384
/**
382
- * We track 2 different timers: the "metrics" timer records how much time we
383
- * spend performing work. The "wait" timer records how much time we spend
384
- * waiting on the underlying OPFS timer. See the calls to mTimeStart(),
385
- * mTimeEnd(), wTimeStart(), and wTimeEnd() throughout this file to see how
386
- * they're used.
385
+ * We track 2 different timers: the "metrics" timer records how much
386
+ * time we spend performing work. The "wait" timer records how much
387
+ * time we spend waiting on the underlying OPFS timer. See the calls
388
+ * to mTimeStart(), mTimeEnd(), wTimeStart(), and wTimeEnd()
389
+ * throughout this file to see how they're used.
387
390
*/
388
391
const __mTimer = Object . create ( null ) ;
389
392
__mTimer . op = undefined ;
@@ -408,17 +411,17 @@ const installAsyncProxy = function (self) {
408
411
( metrics [ __wTimer . op ] . wait += performance . now ( ) - __wTimer . start ) ;
409
412
410
413
/**
411
- * Gets set to true by the 'opfs-async-shutdown' command to quit the wait
412
- * loop. This is only intended for debugging purposes: we cannot inspect this
413
- * file's state while the tight waitLoop() is running and need a way to stop
414
- * that loop for introspection purposes.
414
+ * Gets set to true by the 'opfs-async-shutdown' command to quit the
415
+ * wait loop. This is only intended for debugging purposes: we cannot
416
+ * inspect this file's state while the tight waitLoop() is running and
417
+ * need a way to stop that loop for introspection purposes.
415
418
*/
416
419
let flagAsyncShutdown = false ;
417
420
418
421
/**
419
- * Asynchronous wrappers for sqlite3_vfs and sqlite3_io_methods methods, as
420
- * well as helpers like mkdir(). Maintenance reminder: members are in
421
- * alphabetical order to simplify finding them.
422
+ * Asynchronous wrappers for sqlite3_vfs and sqlite3_io_methods
423
+ * methods, as well as helpers like mkdir(). Maintenance reminder:
424
+ * members are in alphabetical order to simplify finding them.
422
425
*/
423
426
const vfsAsyncImpls = {
424
427
'opfs-async-metrics' : async ( ) => {
@@ -757,8 +760,8 @@ const installAsyncProxy = function (self) {
757
760
758
761
const initS11n = ( ) => {
759
762
/**
760
- * ACHTUNG: this code is 100% duplicated in the other half of this proxy!
761
- * The documentation is maintained in the "synchronous half".
763
+ * ACHTUNG: this code is 100% duplicated in the other half of this
764
+ * proxy! The documentation is maintained in the "synchronous half".
762
765
*/
763
766
if ( state . s11n ) return state . s11n ;
764
767
const textDecoder = new TextDecoder ( ) ,
0 commit comments