mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-10-01 03:19:07 +02:00
ZenFS expects null in case something does not exist
This commit is contained in:
parent
d2d95b7255
commit
1227e89c30
@ -64,7 +64,7 @@ begin
|
|||||||
lResult:=lStorage.Key(Integer(aCmd.Args[0]));
|
lResult:=lStorage.Key(Integer(aCmd.Args[0]));
|
||||||
if isNull(lResult) then
|
if isNull(lResult) then
|
||||||
begin
|
begin
|
||||||
lResultLen:=0;
|
lResultLen:=cNULLLength;
|
||||||
lResult:='';
|
lResult:='';
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -77,7 +77,7 @@ begin
|
|||||||
lResult:=lStorage.getItem(String(aCmd.Args[0]));
|
lResult:=lStorage.getItem(String(aCmd.Args[0]));
|
||||||
if isNull(lResult) then
|
if isNull(lResult) then
|
||||||
begin
|
begin
|
||||||
lResultLen:=0;
|
lResultLen:=cNULLLength;
|
||||||
lResult:='';
|
lResult:='';
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -18,7 +18,7 @@ const
|
|||||||
FNRemoveItem = 'remove_item';
|
FNRemoveItem = 'remove_item';
|
||||||
FNKey = 'key';
|
FNKey = 'key';
|
||||||
|
|
||||||
LocalStorageBufferSize = 1024*1024; // 1 mb
|
LocalStorageBufferSize = 4*1024*1024; // 4 mb
|
||||||
|
|
||||||
{
|
{
|
||||||
Result data:
|
Result data:
|
||||||
@ -35,6 +35,8 @@ const
|
|||||||
ESTORAGE_SUCCESS = 0;
|
ESTORAGE_SUCCESS = 0;
|
||||||
ESTORAGE_KIND = -1;
|
ESTORAGE_KIND = -1;
|
||||||
|
|
||||||
|
cNULLLength = -1;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
TStorageKind = (skLocal,skSession);
|
TStorageKind = (skLocal,skSession);
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ unit pas2js.storagebridge.worker;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, js, webworker, rtl.WorkerCommands, pas2js.storagebridge.shared;
|
types, js, weborworker, webworker, rtl.WorkerCommands, pas2js.storagebridge.shared;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
TMainThreadCallFunc = reference to function: Integer;
|
TMainThreadCallFunc = reference to function: Integer;
|
||||||
@ -19,6 +19,7 @@ Type
|
|||||||
Private
|
Private
|
||||||
FCallID : Integer;
|
FCallID : Integer;
|
||||||
FKind : TStorageKind;
|
FKind : TStorageKind;
|
||||||
|
FDecoder : TJSTextDecoder;
|
||||||
Protected
|
Protected
|
||||||
function DoMainThreadBlockingCall(const aFuncName: String; aArgs: array of JSValue): Integer;
|
function DoMainThreadBlockingCall(const aFuncName: String; aArgs: array of JSValue): Integer;
|
||||||
public
|
public
|
||||||
@ -30,8 +31,8 @@ Type
|
|||||||
public
|
public
|
||||||
constructor create(aKind : TStorageKind);
|
constructor create(aKind : TStorageKind);
|
||||||
class procedure init;
|
class procedure init;
|
||||||
function Key(aKey : Integer) : string;
|
function Key(aKey : Integer) : JSValue;
|
||||||
function GetItem(aKey : String) : String;
|
function GetItem(aKey : String) : JSValue;
|
||||||
procedure SetItem(aKey,aValue : String);
|
procedure SetItem(aKey,aValue : String);
|
||||||
procedure RemoveItem(aKey : String);
|
procedure RemoveItem(aKey : String);
|
||||||
function count : Integer;
|
function count : Integer;
|
||||||
@ -66,6 +67,7 @@ constructor TWorkerStorageBridge.create(aKind: TStorageKind);
|
|||||||
begin
|
begin
|
||||||
FKind:=aKind;
|
FKind:=aKind;
|
||||||
FResultData:=TJSInt32Array.New(_AtomicBuffer);
|
FResultData:=TJSInt32Array.New(_AtomicBuffer);
|
||||||
|
FDecoder:=TJSTextDecoder.New('utf-16');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TWorkerStorageBridge.clear;
|
procedure TWorkerStorageBridge.clear;
|
||||||
@ -91,32 +93,43 @@ begin
|
|||||||
DoMainThreadBlockingCall(FNRemoveItem,[aKey]);
|
DoMainThreadBlockingCall(FNRemoveItem,[aKey]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWorkerStorageBridge.Key(aKey: Integer): string;
|
function TWorkerStorageBridge.Key(aKey: Integer): JSValue;
|
||||||
var
|
var
|
||||||
lResultLen : integer;
|
lResultLen : integer;
|
||||||
lStringArray :TJSUint16Array;
|
lStringArray :TJSUint16Array;
|
||||||
begin
|
begin
|
||||||
if DoMainThreadBlockingCall(FNKey,[aKey])<>0 then
|
if DoMainThreadBlockingCall(FNKey,[aKey])<>0 then
|
||||||
Exit('');
|
Exit(null);
|
||||||
lResultLen:=Self.FResultData[CallResultLen];
|
lResultLen:=Self.FResultData[CallResultLen];
|
||||||
|
if lResultLen<=0 then
|
||||||
|
Exit(null);
|
||||||
if lResultLen<=0 then
|
if lResultLen<=0 then
|
||||||
Exit('');
|
Exit('');
|
||||||
|
|
||||||
lStringArray:=TJSUint16Array.new(_AtomicBuffer, CallResultData*4, lResultLen);
|
lStringArray:=TJSUint16Array.new(_AtomicBuffer, CallResultData*4, lResultLen);
|
||||||
Result := String(TJSFunction(@TJSString.fromCharCode).apply(nil, TJSValueDynArray(lStringArray)));
|
Result := FDecoder.Decode(lStringArray);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWorkerStorageBridge.GetItem(aKey: String): String;
|
function TWorkerStorageBridge.GetItem(aKey: String): JSValue;
|
||||||
var
|
var
|
||||||
lResultLen : integer;
|
lResultLen : integer;
|
||||||
lStringArray :TJSUint16Array;
|
lNew,lStringArray :TJSUint16Array;
|
||||||
|
lBuf : TJSArrayBuffer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if DoMainThreadBlockingCall(FNGetItem,[aKey])<>0 then
|
if DoMainThreadBlockingCall(FNGetItem,[aKey])<>0 then
|
||||||
Exit('');
|
Exit(null);
|
||||||
lResultLen:=Self.FResultData[CallResultLen];
|
lResultLen:=Self.FResultData[CallResultLen];
|
||||||
if lResultLen<=0 then
|
if lResultLen=-1 then
|
||||||
|
Exit(null);
|
||||||
|
if lResultLen=0 then
|
||||||
Exit('');
|
Exit('');
|
||||||
|
|
||||||
lStringArray:=TJSUint16Array.new(_AtomicBuffer, CallResultData*4, lResultLen);
|
lStringArray:=TJSUint16Array.new(_AtomicBuffer, CallResultData*4, lResultLen);
|
||||||
Result := String(TJSFunction(@TJSString.fromCharCode).apply(nil, TJSValueDynArray(lStringArray)));
|
lBuf:=TJSArrayBuffer.new(lResultLen*2);
|
||||||
|
lNew:=TJSUint16Array.new(lbuf);
|
||||||
|
lnew._set(lStringArray);
|
||||||
|
Result := FDecoder.Decode(lNew);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TWorkerStorageBridge.init;
|
class procedure TWorkerStorageBridge.init;
|
||||||
|
Loading…
Reference in New Issue
Block a user