aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/common/whwasmutil.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-05 11:30:39 +0000
committerstephan <stephan@noemail.net>2022-12-05 11:30:39 +0000
commit0adef0937451b9c93688c00e26a792915361af5d (patch)
treefc308f640ba6a2b065e1f4dfb6ae9131ba0abc2c /ext/wasm/common/whwasmutil.js
parent08fc64ea04d7b8ce458ba13608502159a2727738 (diff)
downloadsqlite-0adef0937451b9c93688c00e26a792915361af5d.tar.gz
sqlite-0adef0937451b9c93688c00e26a792915361af5d.zip
Export sqlite3_bind/value/result_pointer() to wasm. Add 'static-string' argument converter to support the lifetime requirements of bind/result_pointer()'s string argument. Correct an endless loop in wasm.cstrlen() when passed a non-C-string argument.
FossilOrigin-Name: a94552434a657376d5ce1831de05c1b15fb153020848cd825fb0df413c3baa70
Diffstat (limited to 'ext/wasm/common/whwasmutil.js')
-rw-r--r--ext/wasm/common/whwasmutil.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js
index 84d829dab..9bce82f1a 100644
--- a/ext/wasm/common/whwasmutil.js
+++ b/ext/wasm/common/whwasmutil.js
@@ -725,11 +725,12 @@ self.WhWasmUtilInstaller = function(target){
Expects ptr to be a pointer into the WASM heap memory which
refers to a NUL-terminated C-style string encoded as UTF-8.
Returns the length, in bytes, of the string, as for `strlen(3)`.
- As a special case, if !ptr then it it returns `null`. Throws if
- ptr is out of range for target.heap8u().
+ As a special case, if !ptr or if it's not a pointer then it
+ returns `null`. Throws if ptr is out of range for
+ target.heap8u().
*/
target.cstrlen = function(ptr){
- if(!ptr) return null;
+ if(!ptr || !target.isPtr(ptr)) return null;
const h = heapWrappers().HEAP8U;
let pos = ptr;
for( ; h[pos] !== 0; ++pos ){}
@@ -753,7 +754,7 @@ self.WhWasmUtilInstaller = function(target){
refers to a NUL-terminated C-style string encoded as UTF-8. This
function counts its byte length using cstrlen() then returns a
JS-format string representing its contents. As a special case, if
- ptr is falsy, `null` is returned.
+ ptr is falsy or not a pointer, `null` is returned.
*/
target.cstringToJs = function(ptr){
const n = target.cstrlen(ptr);