diff options
author | stephan <stephan@noemail.net> | 2022-12-06 08:39:17 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-12-06 08:39:17 +0000 |
commit | 671386c6376b00363ef24fe8732d9e8de1078a7d (patch) | |
tree | b24b6488324b1bfad88d8b83a3c5365285be8f85 /ext/wasm/common/whwasmutil.js | |
parent | b849832a79271c8743ddcd455d6bfcaca88433d0 (diff) | |
download | sqlite-671386c6376b00363ef24fe8732d9e8de1078a7d.tar.gz sqlite-671386c6376b00363ef24fe8732d9e8de1078a7d.zip |
Add wasm.cArgvToJs() to support sqlite3_module::xConnect().
FossilOrigin-Name: c3ebdccf94d5e63c229bf91056c08052d78732e663334070ef3b0ef6fb4bfb8f
Diffstat (limited to 'ext/wasm/common/whwasmutil.js')
-rw-r--r-- | ext/wasm/common/whwasmutil.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index ea344c6ea..571486912 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -1132,6 +1132,27 @@ self.WhWasmUtilInstaller = function(target){ target.allocMainArgv = (list)=>__allocMainArgv(false, list); /** + Expects to be given a C-style string array and its length. It + returns a JS array of strings and/or nulls: any entry in the + pArgv array which is NULL results in a null entry in the result + array. If argc is 0 then an empty array is returned. + + Results are undefined if any entry in the first argc entries of + pArgv are neither 0 (NULL) nor legal UTF-format C strings. + + To be clear, the expected C-style arguments to be passed to this + function are `(int, char **)` (optionally const-qualified). + */ + target.cArgvToJs = (argc, pArgv)=>{ + const list = []; + for(let i = 0; i < argc; ++i){ + const arg = target.getPtrValue(pArgv + (target.ptrSizeof * i)); + list.push( arg ? target.cstringToJs(arg) : null ); + } + return list; + }; + + /** Wraps function call func() in a scopedAllocPush() and scopedAllocPop() block, such that all calls to scopedAlloc() and friends from within that call will have their memory freed |