diff options
author | stephan <stephan@noemail.net> | 2022-12-14 14:40:36 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-12-14 14:40:36 +0000 |
commit | 8a5c032b0776576352c48c9dc9251e3537913bf3 (patch) | |
tree | 5288da05ef0eff09eb3f2b2f78aa417cbd3c07cf /ext/wasm/tester1.c-pp.js | |
parent | feb9123a8cc018fd0765ef47e1f5bad5b5b3f2aa (diff) | |
download | sqlite-8a5c032b0776576352c48c9dc9251e3537913bf3.tar.gz sqlite-8a5c032b0776576352c48c9dc9251e3537913bf3.zip |
Use the new peek/poke() variants throughout tester1.js.
FossilOrigin-Name: ef7b783552f7783a728837fcfc81e493b135a7aac59747397e7e3d28f4309f95
Diffstat (limited to 'ext/wasm/tester1.c-pp.js')
-rw-r--r-- | ext/wasm/tester1.c-pp.js | 93 |
1 files changed, 42 insertions, 51 deletions
diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 81593bc21..8b9efcb0a 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -472,13 +472,13 @@ self.sqlite3InitModule = sqlite3InitModule; m = w.allocFromTypedArray(u); for(let i = 0; i < u.length; ++i){ T.assert(u[i] === byteList[i]) - .assert(u[i] === w.peek(m + i, 'i8')); + .assert(u[i] === w.peek8(m + i)); } w.dealloc(m); m = w.allocFromTypedArray(u.buffer); for(let i = 0; i < u.length; ++i){ T.assert(u[i] === byteList[i]) - .assert(u[i] === w.peek(m + i, 'i8')); + .assert(u[i] === w.peek8(m + i)); } w.dealloc(m); @@ -577,14 +577,14 @@ self.sqlite3InitModule = sqlite3InitModule; let rc = w.cstrncpy(cpy, cStr, n+10); T.assert(n+1 === rc). assert("hello" === w.cstrToJs(cpy)). - assert(chr('o') === w.peek(cpy+n-1)). - assert(0 === w.peek(cpy+n)); + assert(chr('o') === w.peek8(cpy+n-1)). + assert(0 === w.peek8(cpy+n)); let cStr2 = w.scopedAllocCString("HI!!!"); rc = w.cstrncpy(cpy, cStr2, 3); T.assert(3===rc). assert("HI!lo" === w.cstrToJs(cpy)). - assert(chr('!') === w.peek(cpy+2)). - assert(chr('l') === w.peek(cpy+3)); + assert(chr('!') === w.peek8(cpy+2)). + assert(chr('l') === w.peek8(cpy+3)); }finally{ w.scopedAllocPop(scope); } @@ -607,8 +607,8 @@ self.sqlite3InitModule = sqlite3InitModule; const jstr = "hällo, world!"; const [cstr, n] = w.allocCString(jstr, true); T.assert(14 === n) - .assert(0===w.peek(cstr+n)) - .assert(chr('!')===w.peek(cstr+n-1)); + .assert(0===w.peek8(cstr+n)) + .assert(chr('!')===w.peek8(cstr+n-1)); w.dealloc(cstr); } @@ -644,8 +644,8 @@ self.sqlite3InitModule = sqlite3InitModule; const [z1, z2, z3] = w.scopedAllocPtr(3); T.assert('number'===typeof z1).assert(z2>z1).assert(z3>z2) - .assert(0===w.peek(z1,'i32'), 'allocPtr() must zero the targets') - .assert(0===w.peek(z3,'i32')); + .assert(0===w.peek32(z1), 'allocPtr() must zero the targets') + .assert(0===w.peek32(z3)); }finally{ // Pop them in "incorrect" order to make sure they behave: w.scopedAllocPop(asc); @@ -665,8 +665,8 @@ self.sqlite3InitModule = sqlite3InitModule; T.assert(1===w.scopedAlloc.level); const [cstr, n] = w.scopedAllocCString("hello, world", true); T.assert(12 === n) - .assert(0===w.peek(cstr+n)) - .assert(chr('d')===w.peek(cstr+n-1)); + .assert(0===w.peek8(cstr+n)) + .assert(chr('d')===w.peek8(cstr+n-1)); }); }/*scopedAlloc()*/ @@ -730,7 +730,7 @@ self.sqlite3InitModule = sqlite3InitModule; const pI1 = w.scopedAlloc(8), pI2 = pI1+4; w.pokePtr([pI1, pI2], 0); const f = w.xWrap('sqlite3_wasm_test_int64_minmax',undefined,['i64*','i64*']); - const [r1, r2] = w.peek([pI1, pI2], 'i64'); + const [r1, r2] = w.peek64([pI1, pI2]); T.assert(!Number.isSafeInteger(r1)).assert(!Number.isSafeInteger(r2)); }); } @@ -974,8 +974,8 @@ self.sqlite3InitModule = sqlite3InitModule; try{ const n = 520; const p = wasm.pstack.alloc(n); - T.assert(0===wasm.peek(p)) - .assert(0===wasm.peek(p+n-1)); + T.assert(0===wasm.peek8(p)) + .assert(0===wasm.peek8(p+n-1)); T.assert(undefined === capi.sqlite3_randomness(n - 10, p)); let j, check = 0; const heap = wasm.heap8u(); @@ -1096,7 +1096,7 @@ self.sqlite3InitModule = sqlite3InitModule; rc = capi.sqlite3_db_status(this.db, capi.SQLITE_DBSTATUS_LOOKASIDE_USED, pCur, pHi, 0); T.assert(0===rc); - if(wasm.peek(pCur, 'i32')){ + if(wasm.peek32(pCur)){ warn("Cannot test db_config(SQLITE_DBCONFIG_LOOKASIDE)", "while lookaside memory is in use."); }else{ @@ -1104,21 +1104,21 @@ self.sqlite3InitModule = sqlite3InitModule; 0, 4096, 12); T.assert(0 === rc); } - wasm.poke([pCur, pHi], 0, 'i32'); - let [vCur, vHi] = wasm.peek([pCur, pHi], 'i32'); + wasm.poke32([pCur, pHi], 0); + let [vCur, vHi] = wasm.peek32([pCur, pHi]); T.assert(0===vCur).assert(0===vHi); rc = capi.sqlite3_status(capi.SQLITE_STATUS_MEMORY_USED, pCur, pHi, 0); - [vCur, vHi] = wasm.peek([pCur, pHi], 'i32'); + [vCur, vHi] = wasm.peek32([pCur, pHi]); //console.warn("i32 vCur,vHi",vCur,vHi); T.assert(0 === rc).assert(vCur > 0).assert(vHi >= vCur); if(wasm.bigIntEnabled){ // Again in 64-bit. Recall that pCur and pHi are allocated // large enough to account for this re-use. - wasm.poke([pCur, pHi], 0, 'i64'); + wasm.poke64([pCur, pHi], 0); rc = capi.sqlite3_status64(capi.SQLITE_STATUS_MEMORY_USED, pCur, pHi, 0); - [vCur, vHi] = wasm.peek([pCur, pHi], 'i64'); + [vCur, vHi] = wasm.peek64([pCur, pHi]); //console.warn("i64 vCur,vHi",vCur,vHi); T.assert(0 === rc).assert(vCur > 0).assert(vHi >= vCur); } @@ -1346,9 +1346,9 @@ self.sqlite3InitModule = sqlite3InitModule; T.assert(0===rc) .assert("INTEGER"===wasm.cstrToJs(wasm.peekPtr(pzDT))) .assert("BINARY"===wasm.cstrToJs(wasm.peekPtr(pzColl))) - .assert(0===wasm.peek(pNotNull,'i32')) - .assert(1===wasm.peek(pPK,'i32')) - .assert(0===wasm.peek(pAuto,'i32')) + .assert(0===wasm.peek32(pNotNull)) + .assert(1===wasm.peek32(pPK)) + .assert(0===wasm.peek32(pAuto)) }finally{ wasm.pstack.restore(stack); } @@ -1495,11 +1495,11 @@ self.sqlite3InitModule = sqlite3InitModule; name: 'summer', xStep: (pCtx, n)=>{ const ac = sjac(pCtx, 4); - wasm.poke(ac, wasm.peek(ac,'i32') + Number(n), 'i32'); + wasm.poke32(ac, wasm.peek32(ac) + Number(n)); }, xFinal: (pCtx)=>{ const ac = sjac(pCtx, 0); - return ac ? wasm.peek(ac,'i32') : 0; + return ac ? wasm.peek32(ac) : 0; } }); let v = db.selectValue([ @@ -1518,13 +1518,13 @@ self.sqlite3InitModule = sqlite3InitModule; arity: -1, xStep: (pCtx, ...args)=>{ const ac = sjac(pCtx, 4); - let sum = wasm.peek(ac, 'i32'); + let sum = wasm.peek32(ac); for(const v of args) sum += Number(v); - wasm.poke(ac, sum, 'i32'); + wasm.poke32(ac, sum); }, xFinal: (pCtx)=>{ const ac = sjac(pCtx, 0); - capi.sqlite3_result_int( pCtx, ac ? wasm.peek(ac,'i32') : 0 ); + capi.sqlite3_result_int( pCtx, ac ? wasm.peek32(ac) : 0 ); // xFinal() may either return its value directly or call // sqlite3_result_xyz() and return undefined. Both are // functionally equivalent. @@ -1566,11 +1566,11 @@ self.sqlite3InitModule = sqlite3InitModule; name: 'summer64', xStep: (pCtx, n)=>{ const ac = sjac(pCtx, 8); - wasm.poke(ac, wasm.peek(ac,'i64') + BigInt(n), 'i64'); + wasm.poke64(ac, wasm.peek64(ac) + BigInt(n)); }, xFinal: (pCtx)=>{ const ac = sjac(pCtx, 0); - return ac ? wasm.peek(ac,'i64') : 0n; + return ac ? wasm.peek64(ac) : 0n; } }); let v = db.selectValue([ @@ -1593,11 +1593,11 @@ self.sqlite3InitModule = sqlite3InitModule; const sjac = (cx,n=4)=>capi.sqlite3_js_aggregate_context(cx,n); const xValueFinal = (pCtx)=>{ const ac = sjac(pCtx, 0); - return ac ? wasm.peek(ac,'i32') : 0; + return ac ? wasm.peek32(ac) : 0; }; const xStepInverse = (pCtx, n)=>{ const ac = sjac(pCtx); - wasm.poke(ac, wasm.peek(ac,'i32') + Number(n), 'i32'); + wasm.poke32(ac, wasm.peek32(ac) + Number(n)); }; db.createFunction({ name: 'winsumint', @@ -1716,35 +1716,26 @@ self.sqlite3InitModule = sqlite3InitModule; const stack = w.scopedAllocPush(); let ptrInt; const origValue = 512; - const ptrValType = 'i32'; try{ ptrInt = w.scopedAlloc(4); - w.poke(ptrInt,origValue, ptrValType); + w.poke32(ptrInt,origValue); const cf = w.xGet('sqlite3_wasm_test_intptr'); const oldPtrInt = ptrInt; - //log('ptrInt',ptrInt); - //log('peek(ptrInt)',w.peek(ptrInt)); - T.assert(origValue === w.peek(ptrInt, ptrValType)); + T.assert(origValue === w.peek32(ptrInt)); const rc = cf(ptrInt); - //log('cf(ptrInt)',rc); - //log('ptrInt',ptrInt); - //log('peek(ptrInt)',w.peek(ptrInt,ptrValType)); T.assert(2*origValue === rc). - assert(rc === w.peek(ptrInt,ptrValType)). + assert(rc === w.peek32(ptrInt)). assert(oldPtrInt === ptrInt); const pi64 = w.scopedAlloc(8)/*ptr to 64-bit integer*/; const o64 = 0x010203040506/*>32-bit integer*/; - const ptrType64 = 'i64'; if(w.bigIntEnabled){ - w.poke(pi64, o64, ptrType64); + w.poke64(pi64, o64); //log("pi64 =",pi64, "o64 = 0x",o64.toString(16), o64); - const v64 = ()=>w.peek(pi64,ptrType64) - //log("peek(pi64)",v64()); + const v64 = ()=>w.peek64(pi64) T.assert(v64() == o64); - //T.assert(o64 === w.peek(pi64, ptrType64)); + //T.assert(o64 === w.peek64(pi64)); const cf64w = w.xGet('sqlite3_wasm_test_int64ptr'); cf64w(pi64); - //log("peek(pi64)",v64()); T.assert(v64() == BigInt(2 * o64)); cf64w(pi64); T.assert(v64() == BigInt(4 * o64)); @@ -1756,8 +1747,8 @@ self.sqlite3InitModule = sqlite3InitModule; const pMin = w.scopedAlloc(16); const pMax = pMin + 8; - const g64 = (p)=>w.peek(p,ptrType64); - w.poke([pMin, pMax], 0, ptrType64); + const g64 = (p)=>w.peek64(p); + w.poke64([pMin, pMax], 0); const minMaxI64 = [ w.xCall('sqlite3_wasm_test_int64_min'), w.xCall('sqlite3_wasm_test_int64_max') @@ -1769,7 +1760,7 @@ self.sqlite3InitModule = sqlite3InitModule; T.assert(g64(pMin) === minMaxI64[0], "int64 mismatch"). assert(g64(pMax) === minMaxI64[1], "int64 mismatch"); //log("pMin",g64(pMin), "pMax",g64(pMax)); - w.poke(pMin, minMaxI64[0], ptrType64); + w.poke64(pMin, minMaxI64[0]); T.assert(g64(pMin) === minMaxI64[0]). assert(minMaxI64[0] === db.selectValue("select ?",g64(pMin))). assert(minMaxI64[1] === db.selectValue("select ?",g64(pMax))); |