diff options
author | stephan <stephan@noemail.net> | 2022-12-23 18:14:36 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-12-23 18:14:36 +0000 |
commit | b5915699d0404bcd3b502e18af3d889d0bf581dc (patch) | |
tree | f63587528651df8df3f430207766331bddfee608 /ext/wasm/tester1.c-pp.js | |
parent | 0f29f17bf6ea1044d4daa7bbc00283a026a1c514 (diff) | |
download | sqlite-b5915699d0404bcd3b502e18af3d889d0bf581dc.tar.gz sqlite-b5915699d0404bcd3b502e18af3d889d0bf581dc.zip |
Internal cleanups and minor speed optimizations in the sqlite3.wasm.xWrap() infrastructure.
FossilOrigin-Name: c4dab53b8ea3401abd57671b8f3cb39fa4431b864d4c4e14ae24592f8d4cba0a
Diffstat (limited to 'ext/wasm/tester1.c-pp.js')
-rw-r--r-- | ext/wasm/tester1.c-pp.js | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index bef34a0ba..eb014d7b5 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -539,7 +539,7 @@ self.sqlite3InitModule = sqlite3InitModule; } w.dealloc(m); } - + // isPtr32() { const ip = w.isPtr32; @@ -743,6 +743,65 @@ self.sqlite3InitModule = sqlite3InitModule; .assert('HI' === cj(new Uint8Array([72, 73]))); }); + // jsFuncToWasm() + { + const fsum3 = (x,y,z)=>x+y+z; + fw = w.jsFuncToWasm('i(iii)', fsum3); + T.assert(fw instanceof Function) + .assert( fsum3 !== fw ) + .assert( 3 === fw.length ) + .assert( 6 === fw(1,2,3) ); + T.mustThrowMatching( ()=>w.jsFuncToWasm('x()', function(){}), + 'Invalid signature letter: x'); + } + + // xWrap(Function,...) + { + let fp; + try { + const fmy = function fmy(i,s,d){ + if(fmy.debug) log("fmy(",...arguments,")"); + T.assert( 3 === i ) + .assert( w.isPtr(s) ) + .assert( w.cstrToJs(s) === 'a string' ) + .assert( T.eqApprox(1.2, d) ); + return w.allocCString("hi"); + }; + fmy.debug = false; + const xwArgs = ['string:dealloc', ['i32', 'string', 'f64']]; + fw = w.xWrap(fmy, ...xwArgs); + const fmyArgs = [3, 'a string', 1.2]; + let rc = fw(...fmyArgs); + T.assert( 'hi' === rc ); + if(0){ + /* Retain this as a "reminder to self"... + + This extra level of indirection does not work: the + string argument is ending up as a null in fmy() but + the numeric arguments are making their ways through + + What's happening is: installFunction() is creating a + WASM-compatible function instance. When we pass a JS string + into there it's getting coerced into `null` before being passed + on to the lower-level wrapper. + */ + fmy.debug = true; + fp = wasm.installFunction('i(isd)', fw); + fw = w.functionEntry(fp); + rc = fw(...fmyArgs); + log("rc =",rc); + T.assert( 'hi' === rc ); + // Similarly, this does not work: + //let fpw = w.xWrap(fp, null, [null,null,null]); + //rc = fpw(...fmyArgs); + //log("rc =",rc); + //T.assert( 'hi' === rc ); + } + }finally{ + wasm.uninstallFunction(fp); + } + } + if(haveWasmCTests()){ if(!sqlite3.config.useStdAlloc){ fw = w.xWrap('sqlite3_wasm_test_str_hello', 'utf8:dealloc',['i32']); @@ -768,7 +827,7 @@ self.sqlite3InitModule = sqlite3InitModule; }); } } - } + }/*xWrap()*/ }/*WhWasmUtil*/) //////////////////////////////////////////////////////////////////// @@ -997,7 +1056,6 @@ self.sqlite3InitModule = sqlite3InitModule; P.restore(stack); } }/*pstack tests*/) - //////////////////////////////////////////////////////////////////// ;/*end of C/WASM utils checks*/ |