mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-05 11:17:45 +02:00
* Use GetUTF8StringFromArray
This commit is contained in:
parent
62c21d3823
commit
d0c597c68e
@ -202,6 +202,7 @@ type
|
||||
Destructor Destroy; override;
|
||||
function GetUTF8ByteLength(const AString: String): Integer;
|
||||
Function GetUTF8StringFromMem(aLoc, aLen : Longint) : String;
|
||||
function GetUTF8StringFromArray(aSourceArray: TJSUint8Array): String;
|
||||
// Write string as UTF8 string in memory at aLoc, with max aLen bytes.
|
||||
// Return number of bytes written, or -NeededLen if not enough room.
|
||||
function SetUTF8StringInMem(aLoc: TWasmMemoryLocation; aLen: Longint; AString: String): Integer;
|
||||
@ -1392,7 +1393,7 @@ Var
|
||||
|
||||
begin
|
||||
try
|
||||
S:=UTF8TextDecoder.decode(aBytes);
|
||||
S:=GetUTF8StringFromArray(aBytes);
|
||||
except
|
||||
// Depending on buffer size, FPC can do a flush mid-codepoint.
|
||||
// The resulting bytes will not form a complete codepoint at the end.
|
||||
@ -2316,6 +2317,27 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function TPas2JSWASIEnvironment.GetUTF8StringFromArray(aSourceArray:TJSUint8Array): String;
|
||||
|
||||
var
|
||||
src : TJSSharedArrayBuffer;
|
||||
tmpBuf: TJSAbstractArrayBuffer;
|
||||
SrcBytes,tmpBytes : TJSUint8Array;
|
||||
|
||||
begin
|
||||
if isDefined(Self_['SharedArrayBuffer']) and (aSourceArray.bufferObj is TJSSharedArrayBuffer) then
|
||||
begin
|
||||
src:=TJSSharedArrayBuffer(aSourceArray.bufferObj);
|
||||
SrcBytes:=TJSUint8Array.new(src);
|
||||
tmpBuf:=TJSArrayBuffer.new(Src.byteLength);
|
||||
tmpBytes:=TJSUint8Array.new(tmpBuf);
|
||||
tmpBytes._set(SrcBytes);
|
||||
Result:=UTF8TextDecoder.Decode(tmpBytes);
|
||||
end
|
||||
else
|
||||
Result:=UTF8TextDecoder.Decode(aSourceArray.Buffer);
|
||||
end;
|
||||
|
||||
function TPas2JSWASIEnvironment.GetUTF8StringFromMem(aLoc, aLen: Longint): String;
|
||||
|
||||
var
|
||||
|
Loading…
Reference in New Issue
Block a user