aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-prologue.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2023-08-30 13:07:35 +0000
committerstephan <stephan@noemail.net>2023-08-30 13:07:35 +0000
commit24c32c2e390de4116ba9e768cff9bcd3ad4f5dc6 (patch)
tree9561e6297623c6a2afa457483632fdf06e42be5b /ext/wasm/api/sqlite3-api-prologue.js
parenta910f3f1c5b8d2e131949719b2985ed3f17e6e1d (diff)
parente621556724c044aa09e7c4fdab4e8407df83d216 (diff)
downloadsqlite-24c32c2e390de4116ba9e768cff9bcd3ad4f5dc6.tar.gz
sqlite-24c32c2e390de4116ba9e768cff9bcd3ad4f5dc6.zip
Add a JS implementation of Java's SQLTester.
FossilOrigin-Name: b530792a514d95c4e8f93cf2170d9fc4de367055fa1704fc171551c946024fa9
Diffstat (limited to 'ext/wasm/api/sqlite3-api-prologue.js')
-rw-r--r--ext/wasm/api/sqlite3-api-prologue.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js
index 5abb13b99..ef1154f6b 100644
--- a/ext/wasm/api/sqlite3-api-prologue.js
+++ b/ext/wasm/api/sqlite3-api-prologue.js
@@ -1135,7 +1135,23 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
return 1===n
? wasm.pstack.alloc(safePtrSize ? 8 : wasm.ptrSizeof)
: wasm.pstack.allocChunks(n, safePtrSize ? 8 : wasm.ptrSizeof);
+ },
+
+ /**
+ Records the current pstack position, calls the given function,
+ passing it the sqlite3 object, then restores the pstack
+ regardless of whether the function throws. Returns the result
+ of the call or propagates an exception on error.
+
+ Added in 3.44.
+ */
+ call: function(f){
+ const stackPos = wasm.pstack.pointer;
+ try{ return f(sqlite3) } finally{
+ wasm.pstack.restore(stackPos);
+ }
}
+
})/*wasm.pstack*/;
Object.defineProperties(wasm.pstack, {
/**
@@ -1543,6 +1559,26 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
}
};
+ /**
+ Converts SQL input from a variety of convenient formats
+ to plain strings.
+
+ If v is a string, it is returned as-is. If it is-a Array, its
+ join("") result is returned. If is is a Uint8Array, Int8Array,
+ or ArrayBuffer, it is assumed to hold UTF-8-encoded text and is
+ decoded to a string. If it looks like a WASM pointer,
+ wasm.cstrToJs(sql) is returned. Else undefined is returned.
+
+ Added in 3.44
+ */
+ capi.sqlite3_js_sql_to_string = (sql)=>{
+ if('string' === typeof sql){
+ return sql;
+ }
+ const x = flexibleString(v);
+ return x===v ? undefined : x;
+ }
+
if( util.isUIThread() ){
/* Features specific to the main window thread... */