aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/common/whwasmutil.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-25 20:25:44 +0000
committerstephan <stephan@noemail.net>2022-12-25 20:25:44 +0000
commit3caf13f1cbf3e502eb898959b3de3e42966e202e (patch)
treebec129ee03bbaf478f92fa373ca4292b0501ccc5 /ext/wasm/common/whwasmutil.js
parent7a5544b958e04f8cf99e27353aa3982b28728a5e (diff)
parent9d61db1944238d35ee00cefe0b4bfb7ac291e36b (diff)
downloadsqlite-3caf13f1cbf3e502eb898959b3de3e42966e202e.tar.gz
sqlite-3caf13f1cbf3e502eb898959b3de3e42966e202e.zip
Merge wasm-session-api branch into trunk, adding the session API to the JS/WASM components.
FossilOrigin-Name: dfb8b651fa4faef2d3307a05512cdc479398484c3a59715827179c363861a777
Diffstat (limited to 'ext/wasm/common/whwasmutil.js')
-rw-r--r--ext/wasm/common/whwasmutil.js39
1 files changed, 34 insertions, 5 deletions
diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js
index 7a7747ef3..bfe66dfb1 100644
--- a/ext/wasm/common/whwasmutil.js
+++ b/ext/wasm/common/whwasmutil.js
@@ -247,6 +247,25 @@ self.WhWasmUtilInstaller = function(target){
cache.utf8Encoder = new TextEncoder('utf-8');
/**
+ For the given IR-like string in the set ('i8', 'i16', 'i32',
+ 'f32', 'float', 'i64', 'f64', 'double', '*'), or any string value
+ ending in '*', returns the sizeof for that value
+ (target.ptrSizeof in the latter case). For any other value, it
+ returns the undefined value.
+ */
+ target.irSizeof = (n)=>{
+ switch(n){
+ case 'i8': return 1;
+ case 'i16': return 2;
+ case 'i32': case 'f32': case 'float': return 4;
+ case 'i64': case 'f64': case 'double': return 8;
+ case '*': return ptrSizeof;
+ default:
+ return (''+n).endsWith('*') ? ptrSizeof : undefined;
+ }
+ };
+
+ /**
If (cache.heapSize !== cache.memory.buffer.byteLength), i.e. if
the heap has grown since the last call, updates cache.HEAPxyz.
Returns the cache object.
@@ -447,7 +466,7 @@ self.WhWasmUtilInstaller = function(target){
type(s) of the given function signature, or throws if the
signature is invalid. */
/******** // only valid for use with the WebAssembly.Function ctor, which
- // is not yet documented on MDN.
+ // is not yet documented on MDN.
sigToWasm: function(sig){
const rc = {parameters:[], results: []};
if('v'!==sig[0]) rc.results.push(f.sigTypes(sig[0]));
@@ -1590,10 +1609,20 @@ self.WhWasmUtilInstaller = function(target){
not actually bind any functions. Its convertArg() method is
called via xWrap() to perform any bindings.
- Shortcomings: function pointers which include C-string arguments
- may still need a level of hand-written wrappers around them,
- depending on how they're used, in order to provide the client
- with JS strings.
+ Shortcomings:
+
+ - These "reverse" bindings, i.e. calling into a JS-defined
+ function from a WASM-defined function (the generated proxy
+ wrapper), lack all type conversion support. That means, for
+ example, that...
+
+ - Function pointers which include C-string arguments may still
+ need a level of hand-written wrappers around them, depending on
+ how they're used, in order to provide the client with JS
+ strings. Alternately, clients will need to perform such conversions
+ on their own, e.g. using cstrtojs(). Or maybe we can find a way
+ to perform such conversions here, via addition of an xWrap()-style
+ function signature to the options argument.
*/
xArg.FuncPtrAdapter = class FuncPtrAdapter extends AbstractArgAdapter {
constructor(opt) {