diff options
Diffstat (limited to 'ext/wasm')
-rw-r--r-- | ext/wasm/api/sqlite3-api-worker1.c-pp.js | 13 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-wasm.c | 1 | ||||
-rw-r--r-- | ext/wasm/api/sqlite3-worker1-promiser.c-pp.js | 19 | ||||
-rw-r--r-- | ext/wasm/common/whwasmutil.js | 32 |
4 files changed, 40 insertions, 25 deletions
diff --git a/ext/wasm/api/sqlite3-api-worker1.c-pp.js b/ext/wasm/api/sqlite3-api-worker1.c-pp.js index 5e088f438..55ad16185 100644 --- a/ext/wasm/api/sqlite3-api-worker1.c-pp.js +++ b/ext/wasm/api/sqlite3-api-worker1.c-pp.js @@ -385,10 +385,19 @@ sqlite3.initWorker1API = function(){ const getDbId = function(db){ let id = wState.idMap.get(db); if(id) return id; - id = 'db#'+(++wState.idSeq)+'@'+db.pointer; + id = 'db#'+(++wState.idSeq)+':'+ + Math.floor(Math.random() * 100000000)+':'+ + Math.floor(Math.random() * 100000000); /** ^^^ can't simply use db.pointer b/c closing/opening may re-use the same address, which could map pending messages to a wrong - instance. */ + instance. + + 2025-07: https://github.com/sqlite/sqlite-wasm/issues/113 + demonstrates that two Worker1s can end up with the same IDs, + despite using different instances of the library, so we need + to add some randomness to the IDs instead of relying on the + pointer addresses. + */ wState.idMap.set(db, id); return id; }; diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index ee8a10209..574684ce9 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -939,6 +939,7 @@ const char * sqlite3__wasm_enum_json(void){ DefInt(SQLITE_INNOCUOUS); DefInt(SQLITE_SUBTYPE); DefInt(SQLITE_RESULT_SUBTYPE); + DefInt(SQLITE_SELFORDER1); } _DefGroup; DefGroup(version) { diff --git a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js index c043fd148..2edabe3e6 100644 --- a/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js +++ b/ext/wasm/api/sqlite3-worker1-promiser.c-pp.js @@ -130,12 +130,10 @@ Notable shortcomings: - - This API was not designed with ES6 modules in mind. Neither Firefox - nor Safari support, as of March 2023, the {type:"module"} flag to the - Worker constructor, so that particular usage is not something we're going - to target for the time being: - - https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker + - "v1" of this this API is not suitable for use as an ESM module + because ESM worker modules were not widely supported when it was + developed. For use as an ESM module, see the "v2" interface later + on in this file. */ globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){ // Inspired by: https://stackoverflow.com/a/52439530 @@ -296,7 +294,7 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = { after calling the original function and will reject if that function throws. */ -sqlite3Worker1Promiser.v2 = function(config){ +globalThis.sqlite3Worker1Promiser.v2 = function callee(config = callee.defaultConfig){ let oldFunc; if( 'function' == typeof config ){ oldFunc = config; @@ -326,11 +324,14 @@ sqlite3Worker1Promiser.v2 = function(config){ } return p; }.bind({ - /* We do this because clients are - recommended to delete globalThis.sqlite3Worker1Promiser. */ + /* We do this because clients are recommended to delete + globalThis.sqlite3Worker1Promiser. */ original: sqlite3Worker1Promiser }); +globalThis.sqlite3Worker1Promiser.v2.defaultConfig = + globalThis.sqlite3Worker1Promiser.defaultConfig; + //#if target=es6-module /** When built as a module, we export sqlite3Worker1Promiser.v2() diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index b4d8f691b..e85669579 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -1773,10 +1773,10 @@ globalThis.WhWasmUtilInstaller = function(target){ does not have a stable interface. */ xArg.FuncPtrAdapter.warnOnUse = false; - /** If true, convertArg() will FuncPtrAdapter.debugOut() when it - (un)installs a function binding to/from WASM. Note that - deinstallation of bindScope=transient bindings happens - via scopedAllocPop() so will not be output. */ + /** If true, convertArg() will call FuncPtrAdapter.debugOut() when + it (un)installs a function binding to/from WASM. Note that + deinstallation of bindScope=transient bindings happens via + scopedAllocPop() so will not be output. */ xArg.FuncPtrAdapter.debugFuncInstall = false; /** Function used for debug output. */ @@ -1827,9 +1827,8 @@ globalThis.WhWasmUtilInstaller = function(target){ The first argument must be one of: - A JavaScript function. - - The name of a WASM-exported function. In the latter case xGet() - is used to fetch the exported function, which throws if it's not - found. + - The name of a WASM-exported function. xGet() is used to fetch + the exported function, which throws if it's not found. - A pointer into the indirect function table. e.g. a pointer returned from target.installFunction(). @@ -1874,9 +1873,6 @@ globalThis.WhWasmUtilInstaller = function(target){ which convert their argument to an integer and truncate it to the given bit length. - - `N*` (args): a type name in the form `N*`, where N is a numeric - type name, is treated the same as WASM pointer. - - `*` and `pointer` (args): are assumed to be WASM pointer values and are returned coerced to an appropriately-sized pointer value (i32 or i64). Non-numeric values will coerce to 0 and @@ -1887,7 +1883,15 @@ globalThis.WhWasmUtilInstaller = function(target){ WASM pointer numeric type. - `**` (args): is simply a descriptive alias for the WASM pointer - type. It's primarily intended to mark output-pointer arguments. + type. It's primarily intended to mark output-pointer arguments, + noting that JS's view of WASM does not distinguish between + pointers and pointers-to-pointers, so all such interpretation + of `**`, as distinct from `*`, necessarily happens at the + client level. + + - `NumType*` (args): a type name in this form, where T is + the name of a numeric mapping, e.g. 'int16' or 'double', + is treated like `*`. - `i64` (args and results): passes the value to BigInt() to convert it to an int64. Only available if bigIntEnabled is @@ -1916,7 +1920,7 @@ globalThis.WhWasmUtilInstaller = function(target){ UTF-8-encoded C-string to pass to the exported function, cleaning it up before the wrapper returns. If a long-lived C-string pointer is required, that requires client-side code - to create the string, then pass its pointer to the function. + to create the string then pass its pointer to the function. - Else the arg is assumed to be a pointer to a string the client has already allocated and it's passed on as @@ -2091,8 +2095,8 @@ globalThis.WhWasmUtilInstaller = function(target){ easily convert, e.g., to C-strings, and have them cleaned up automatically before the wrapper returns to the caller. Likewise, if a _result_ adapter uses scoped allocation, the result will be - freed before because they would be freed before the wrapper - returns, leading to chaos and undefined behavior. + freed before the wrapper returns, leading to chaos and undefined + behavior. Except when called as a getter, this function returns itself. */ |