aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/common/whwasmutil.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-09-24 07:36:45 +0000
committerstephan <stephan@noemail.net>2022-09-24 07:36:45 +0000
commit60d9aa7c59319948535b0ca4cce99b7f389ec447 (patch)
tree8c0eec3bce374d4f862611f22dcf622ef3097fb2 /ext/wasm/common/whwasmutil.js
parentf75c0c703697a2f1eea678e92f91982b56ca7cbf (diff)
downloadsqlite-60d9aa7c59319948535b0ca4cce99b7f389ec447.tar.gz
sqlite-60d9aa7c59319948535b0ca4cce99b7f389ec447.zip
Refactoring towards getting fiddle to support OPFS as a first-class citizen. Certain operations, e.g. import, export, and unlink, are not OPFS-aware.
FossilOrigin-Name: 1b923ed6438d7fef4508936e0c4bc026a368721698b1539961e3fb3140a185cb
Diffstat (limited to 'ext/wasm/common/whwasmutil.js')
-rw-r--r--ext/wasm/common/whwasmutil.js33
1 files changed, 23 insertions, 10 deletions
diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js
index 46cdf84bb..e9ab8c594 100644
--- a/ext/wasm/common/whwasmutil.js
+++ b/ext/wasm/common/whwasmutil.js
@@ -1030,6 +1030,22 @@ self.WhWasmUtilInstaller = function(target){
(jstr, returnWithLength=false)=>__allocCStr(jstr, returnWithLength,
target.scopedAlloc, 'scopedAllocCString()');
+ // impl for allocMainArgv() and scopedAllocMainArgv().
+ const __allocMainArgv = function(isScoped, list){
+ if(!list.length) toss("Cannot allocate empty array.");
+ const pList = target[
+ isScoped ? 'scopedAlloc' : 'alloc'
+ ](list.length * target.ptrSizeof);
+ let i = 0;
+ list.forEach((e)=>{
+ target.setPtrValue(pList + (target.ptrSizeof * i++),
+ target[
+ isScoped ? 'scopedAllocCString' : 'allocCString'
+ ](""+e));
+ });
+ return pList;
+ };
+
/**
Creates an array, using scopedAlloc(), suitable for passing to a
C-level main() routine. The input is a collection with a length
@@ -1042,16 +1058,13 @@ self.WhWasmUtilInstaller = function(target){
Throws if list.length is falsy or scopedAllocPush() is not active.
*/
- target.scopedAllocMainArgv = function(list){
- if(!list.length) toss("Cannot allocate empty array.");
- const pList = target.scopedAlloc(list.length * target.ptrSizeof);
- let i = 0;
- list.forEach((e)=>{
- target.setPtrValue(pList + (target.ptrSizeof * i++),
- target.scopedAllocCString(""+e));
- });
- return pList;
- };
+ target.scopedAllocMainArgv = (list)=>__allocMainArgv(true, list);
+
+ /**
+ Identical to scopedAllocMainArgv() but uses alloc() instead of
+ scopedAllocMainArgv
+ */
+ target.allocMainArgv = (list)=>__allocMainArgv(false, list);
/**
Wraps function call func() in a scopedAllocPush() and