diff options
author | stephan <stephan@noemail.net> | 2023-01-21 16:53:01 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2023-01-21 16:53:01 +0000 |
commit | 0bcded30e5139fd731cb00d43677f872fce485d8 (patch) | |
tree | d51fa331d353c8e6e11f4c6eb465b68475b0e55e /ext/wasm/api/sqlite3-api-prologue.js | |
parent | 3fdb05e883ce0a6fc610474eaa37d79fd7ac67e1 (diff) | |
download | sqlite-0bcded30e5139fd731cb00d43677f872fce485d8.tar.gz sqlite-0bcded30e5139fd731cb00d43677f872fce485d8.zip |
Minor API doc cleanups and JS code simplification.
FossilOrigin-Name: f608a3a45609693c1c0237f12c394275ec9a6225fa986e62345f21af763293a0
Diffstat (limited to 'ext/wasm/api/sqlite3-api-prologue.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-prologue.js | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js index 5dd37d303..137ab1ee7 100644 --- a/ext/wasm/api/sqlite3-api-prologue.js +++ b/ext/wasm/api/sqlite3-api-prologue.js @@ -12,12 +12,11 @@ This file is intended to be combined at build-time with other related code, most notably a header and footer which wraps this - whole file into an Emscripten Module.postRun() handler which has a - parameter named "Module" (the Emscripten Module object). The sqlite3 - JS API has no hard requirements on Emscripten, and does not expose + whole file into an Emscripten Module.postRun() handler. The sqlite3 + JS API has no hard requirements on Emscripten and does not expose any Emscripten APIs to clients. It is structured such that its build can be tweaked to include it in arbitrary WASM environments which - supply the necessary underlying features (e.g. a POSIX file I/O + can supply the necessary underlying features (e.g. a POSIX file I/O layer). Main project home page: https://sqlite.org @@ -42,8 +41,8 @@ Emscripten. (Note the default values for the config object!) The config object is only honored the first time this is called. Subsequent calls ignore the argument and return the same - (configured) object which gets initialized by the first call. - This function will throw if any of the required config options are + (configured) object which gets initialized by the first call. This + function will throw if any of the required config options are missing. The config object properties include: @@ -62,6 +61,8 @@ true if `self.BigInt64Array` is available, else false. Some APIs will throw exceptions if called without BigInt support, as BigInt is required for marshalling C-side int64 into and out of JS. + (Sidebar: it is technically possible to add int64 support via + marshalling of int32 pairs, but doing so is unduly invasive.) - `allocExportName`: the name of the function, in `exports`, of the `malloc(3)`-compatible routine for the WASM environment. Defaults @@ -69,7 +70,9 @@ sqlite3_malloc() may require care in certain client-side code regarding which allocator is uses. Notably, sqlite3_deserialize() and sqlite3_serialize() can only safely use memory from different - allocators under very specific conditions. + allocators under very specific conditions. The canonical builds + of this API guaranty that `sqlite3_malloc()` is the JS-side + allocator implementation. - `deallocExportName`: the name of the function, in `exports`, of the `free(3)`-compatible routine for the WASM @@ -84,9 +87,11 @@ in the WASMFS+OPFS combination. This option is currently ignored. [^1] = This property may optionally be a function, in which case this - function re-assigns it to the value returned from that function, + function re-assigns calls that function to fetch the value, enabling delayed evaluation. + The returned object is the top-level sqlite3 namespace object. + */ 'use strict'; self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( @@ -1008,7 +1013,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( space managed by Emscripten's stack-management, so does not collide with Emscripten-provided stack allocation APIs. The memory lives in the WASM heap and can be used with routines such - as wasm.poke() and any wasm.heap8u().slice(). + as wasm.poke() and wasm.heap8u().slice(). */ wasm.pstack = Object.assign(Object.create(null),{ /** @@ -1021,7 +1026,7 @@ 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 throws a WasmAllocError. The + to the memory. On error, throws a WasmAllocError. The memory must eventually be released using restore(). If n is a string, it must be a WASM "IR" value in the set @@ -1064,9 +1069,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap( const mem = wasm.pstack.alloc(n * sz); const rc = []; let i = 0, offset = 0; - for(; i < n; offset = (sz * ++i)){ - rc.push(mem + offset); - } + for(; i < n; ++i, offset += sz) rc.push(mem + offset); return rc; }, /** |