diff options
author | stephan <stephan@noemail.net> | 2022-10-02 03:11:13 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-10-02 03:11:13 +0000 |
commit | 63e9ec2f9c7042fc8fb3f858144ee9ebe5408f69 (patch) | |
tree | 1e85e4eef656f867b1a220388cf0563f715223ac /ext/wasm/api/sqlite3-api-prologue.js | |
parent | 6479c5a359e932a76225a903f1a6655cda8c277d (diff) | |
download | sqlite-63e9ec2f9c7042fc8fb3f858144ee9ebe5408f69.tar.gz sqlite-63e9ec2f9c7042fc8fb3f858144ee9ebe5408f69.zip |
More fleshing out of sqlite3.capi.wasm.pstack.
FossilOrigin-Name: eb5726677a727a958df11f1fba078d30c7c0ba2a9bdb158e8641b35b5f971af3
Diffstat (limited to 'ext/wasm/api/sqlite3-api-prologue.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-prologue.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 97376be6c..59533815f 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -265,6 +265,9 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( this.name = 'WasmAllocError'; } }; + WasmAllocError.toss = (...args)=>{ + throw new WasmAllocError(args.join(' ')); + }; /** The main sqlite3 binding API gets installed into this object, @@ -733,6 +736,9 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( Functions which are intended solely for API-internal use by the WASM components, not client code. These get installed into capi.wasm. + + TODO: get rid of sqlite3_wasm_vfs_unlink(). It is ill-conceived + and only rarely actually useful. */ capi.wasm.bindingSignatures.wasm = [ ["sqlite3_wasm_vfs_unlink", "int", "string"] @@ -781,15 +787,21 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( Attempts to allocate the given number of bytes from the pstack. On success, it zeroes out a block of memory of the given size, adjusts the pstack pointer, and returns a pointer - to the memory. On error, returns 0. The memory must eventually - be released using restore(). + to the memory. On error, returns throws a WasmAllocError. The + memory must eventually be released using restore(). This method always adjusts the given value to be a multiple of 8 bytes because failing to do so can lead to incorrect results when reading and writing 64-bit values from/to the WASM heap. */ - alloc: capi.wasm.exports.sqlite3_wasm_pstack_alloc + alloc: (n)=>{ + return capi.wasm.exports.sqlite3_wasm_pstack_alloc(n) + || WasmAllocError.toss("Could not allocate",n, + "bytes from the pstack."); + } + // More methods get added after the capi.wasm object is populated + // by WhWasmUtilInstaller. }); /** sqlite3.capi.wasm.pstack.pointer resolves to the current pstack @@ -828,7 +840,9 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( this.name = 'SQLite3Error'; } }; - + SQLite3Error.toss = (...args)=>{ + throw new SQLite3Error(args.join(' ')); + }; /** State for sqlite3_wasmfs_opfs_dir(). */ let __persistentDir = undefined; |