diff options
author | stephan <stephan@noemail.net> | 2022-08-13 13:42:07 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-08-13 13:42:07 +0000 |
commit | 2cf599cff887bee309e0ac12eb68b487346474a3 (patch) | |
tree | e47fb6ac01b6a714993e89a9b5d904b6c89e1bcd /ext/wasm/common/whwasmutil.js | |
parent | 587f9a0a993b8140f99dcf0428d298e24b31d8ea (diff) | |
download | sqlite-2cf599cff887bee309e0ac12eb68b487346474a3.tar.gz sqlite-2cf599cff887bee309e0ac12eb68b487346474a3.zip |
Corrected TextDecoder.decode() usage to run when its input references a SharedArrayBuffer.
FossilOrigin-Name: d4d773405c579e7efd95be8d81fe14d71218e62e44c523d38e02f89424ba6ce8
Diffstat (limited to 'ext/wasm/common/whwasmutil.js')
-rw-r--r-- | ext/wasm/common/whwasmutil.js | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/ext/wasm/common/whwasmutil.js b/ext/wasm/common/whwasmutil.js index 5a1d425ca..e51f690e2 100644 --- a/ext/wasm/common/whwasmutil.js +++ b/ext/wasm/common/whwasmutil.js @@ -669,6 +669,18 @@ self.WhWasmUtilInstaller = function(target){ return pos - ptr; }; + /** Internal helper to use in operations which need to distinguish + between SharedArrayBuffer heap memory and non-shared heap. */ + const __SAB = ('undefined'===typeof SharedArrayBuffer) + ? function(){} : SharedArrayBuffer; + const __utf8Decode = function(arrayBuffer, begin, end){ + return cache.utf8Decoder.decode( + (arrayBuffer.buffer instanceof __SAB) + ? arrayBuffer.slice(begin, end) + : arrayBuffer.subarray(begin, end) + ); + }; + /** Expects ptr to be a pointer into the WASM heap memory which refers to a NUL-terminated C-style string encoded as UTF-8. This @@ -678,11 +690,7 @@ self.WhWasmUtilInstaller = function(target){ */ target.cstringToJs = function(ptr){ const n = this.cstrlen(ptr); - if(null===n) return n; - return n - ? cache.utf8Decoder.decode( - new Uint8Array(heapWrappers().HEAP8U.buffer, ptr, n) - ) : ""; + return n ? __utf8Decode(heapWrappers().HEAP8U, ptr, ptr+n) : (null===n ? n : ""); }.bind(target); /** @@ -1070,11 +1078,11 @@ self.WhWasmUtilInstaller = function(target){ /** Looks up a WASM-exported function named fname from - target.exports. If found, it is called, passed all remaining + target.exports. If found, it is called, passed all remaining arguments, and its return value is returned to xCall's caller. If not found, an exception is thrown. This function does no - conversion of argument or return types, but see xWrap() - and xCallWrapped() for variants which do. + conversion of argument or return types, but see xWrap() and + xCallWrapped() for variants which do. As a special case, if passed only 1 argument after the name and that argument in an Array, that array's entries become the |