Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Corrected TextDecoder.decode() usage to run when its input references a SharedArrayBuffer. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | fiddle-opfs |
Files: | files | file ages | folders |
SHA3-256: |
d4d773405c579e7efd95be8d81fe14d7 |
User & Date: | stephan 2022-08-13 13:42:07.359 |
Context
2022-08-13
| ||
13:46 | wasm OO API #1: added DB.callInTransaction() and Stmt.stepFinalize(). (check-in: e37dddc1dd user: stephan tags: fiddle-opfs) | |
13:42 | Corrected TextDecoder.decode() usage to run when its input references a SharedArrayBuffer. (check-in: d4d773405c user: stephan tags: fiddle-opfs) | |
2022-08-12
| ||
18:54 | Use new -DSQLITE_DEFAULT_UNIX_VFS="unix-none" for fiddle build to bypass OPFS locking errors. (check-in: b3a93ec75a user: stephan tags: fiddle-opfs) | |
Changes
Changes to ext/wasm/common/whwasmutil.js.
︙ | ︙ | |||
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | target.cstrlen = function(ptr){ if(!ptr) return null; const h = heapWrappers().HEAP8U; let pos = ptr; for( ; h[pos] !== 0; ++pos ){} return pos - ptr; }; /** 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 function counts its byte length using cstrlen() then returns a JS-format string representing its contents. As a special case, if ptr is falsy, `null` is returned. */ target.cstringToJs = function(ptr){ const n = this.cstrlen(ptr); | > > > > > > > > > > > > < < < | < | 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | target.cstrlen = function(ptr){ if(!ptr) return null; const h = heapWrappers().HEAP8U; let pos = ptr; for( ; h[pos] !== 0; ++pos ){} 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 function counts its byte length using cstrlen() then returns a JS-format string representing its contents. As a special case, if ptr is falsy, `null` is returned. */ target.cstringToJs = function(ptr){ const n = this.cstrlen(ptr); return n ? __utf8Decode(heapWrappers().HEAP8U, ptr, ptr+n) : (null===n ? n : ""); }.bind(target); /** Given a JS string, this function returns its UTF-8 length in bytes. Returns null if str is not a string. */ target.jstrlen = function(str){ |
︙ | ︙ | |||
1066 1067 1068 1069 1070 1071 1072 | }; const __argcMismatch = (f,n)=>toss(f+"() requires",n,"argument(s)."); /** Looks up a WASM-exported function named fname from | | | | | 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 | }; const __argcMismatch = (f,n)=>toss(f+"() requires",n,"argument(s)."); /** Looks up a WASM-exported function named fname from 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. As a special case, if passed only 1 argument after the name and that argument in an Array, that array's entries become the function arguments. (This is not an ambiguous case because it's not legal to pass an Array object to a WASM function.) */ target.xCall = function(fname, ...args){ |
︙ | ︙ |
Changes to ext/wasm/jaccwabyt/jaccwabyt.js.
︙ | ︙ | |||
390 391 392 393 394 395 396 | const a = []; Object.keys(this.structInfo.members).forEach((k)=>a.push(this.memberKey(k))); return a; }); const __utf8Decoder = new TextDecoder('utf-8'); const __utf8Encoder = new TextEncoder(); | | > > > > > > > > > > | 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | const a = []; Object.keys(this.structInfo.members).forEach((k)=>a.push(this.memberKey(k))); return a; }); const __utf8Decoder = new TextDecoder('utf-8'); const __utf8Encoder = new TextEncoder(); /** 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 __utf8Decoder.decode( (arrayBuffer.buffer instanceof __SAB) ? arrayBuffer.slice(begin, end) : arrayBuffer.subarray(begin, end) ); }; /** Uses __lookupMember() to find the given obj.structInfo key. Returns that member if it is a string, else returns false. If the member is not found, throws if tossIfNotFound is true, else returns false. */ const __memberIsString = function(obj,memberName, tossIfNotFound=false){ |
︙ | ︙ | |||
433 434 435 436 437 438 439 | if(!addr) return null; let pos = addr; const mem = heap(); for( ; mem[pos]!==0; ++pos ) { //log("mem[",pos,"]",mem[pos]); }; //log("addr =",addr,"pos =",pos); | | < | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | if(!addr) return null; let pos = addr; const mem = heap(); for( ; mem[pos]!==0; ++pos ) { //log("mem[",pos,"]",mem[pos]); }; //log("addr =",addr,"pos =",pos); return (addr===pos) ? "" : __utf8Decode(mem, addr, pos); }; /** Adds value v to obj.ondispose, creating ondispose, or converting it to an array, if needed. */ const __addOnDispose = function(obj, v){ |
︙ | ︙ |