|
@@ -173,7 +173,7 @@ type
|
|
function GetLongInt: longint;
|
|
function GetLongInt: longint;
|
|
function GetMaxInt: int64;
|
|
function GetMaxInt: int64;
|
|
function GetArray : TJSArray;
|
|
function GetArray : TJSArray;
|
|
- function GetFunction : TJSFunction;
|
|
|
|
|
|
+ function GetFunction : IJSFunction;
|
|
|
|
|
|
function AllocUndefined: PByte;
|
|
function AllocUndefined: PByte;
|
|
function AllocBool(b: boolean): PByte;
|
|
function AllocBool(b: boolean): PByte;
|
|
@@ -466,6 +466,7 @@ type
|
|
public
|
|
public
|
|
Constructor Create(aObjectID : TJOBObjectID);
|
|
Constructor Create(aObjectID : TJOBObjectID);
|
|
Constructor Create(aObjectID,aThisID : TJOBObjectID);
|
|
Constructor Create(aObjectID,aThisID : TJOBObjectID);
|
|
|
|
+ destructor Destroy; override;
|
|
function _GetLength: NativeInt;
|
|
function _GetLength: NativeInt;
|
|
function _GetName: UnicodeString;
|
|
function _GetName: UnicodeString;
|
|
function _GetPrototyp: IJSFunction;
|
|
function _GetPrototyp: IJSFunction;
|
|
@@ -970,6 +971,13 @@ type
|
|
{ TJSPromise }
|
|
{ TJSPromise }
|
|
|
|
|
|
TJSPromise = class(TJSObject,IJSPromise)
|
|
TJSPromise = class(TJSObject,IJSPromise)
|
|
|
|
+ FResolveCallback,
|
|
|
|
+ FRejectCallback : IJSFunction;
|
|
|
|
+ FExecutor : TJSPromiseExecutor;
|
|
|
|
+ function HandleResolve(const aValue : Variant): variant;
|
|
|
|
+ function HandleReject(const aValue : Variant): variant;
|
|
|
|
+ protected
|
|
|
|
+ Procedure DoExecutor(const OnResolve, OnReject: TJSPromiseResolver); virtual;
|
|
public
|
|
public
|
|
constructor Create(const Executor: TJSPromiseExecutor); overload;
|
|
constructor Create(const Executor: TJSPromiseExecutor); overload;
|
|
function all(const arg: Variant): IJSPromise; overload;
|
|
function all(const arg: Variant): IJSPromise; overload;
|
|
@@ -1268,38 +1276,23 @@ begin
|
|
TJSPromiseFinallyHandler(aMethod)();
|
|
TJSPromiseFinallyHandler(aMethod)();
|
|
end;
|
|
end;
|
|
|
|
|
|
-Type
|
|
|
|
-
|
|
|
|
- { TPromiseHelper }
|
|
|
|
-
|
|
|
|
- TPromiseHelper = Class(TObject)
|
|
|
|
- FResolveCallback : TJSFunction;
|
|
|
|
- FRejectCallback : TJSFunction;
|
|
|
|
- constructor create (aResolve,aReject : TJSFunction);
|
|
|
|
- function HandleResolve(const aValue : Variant): variant;
|
|
|
|
- function HandleReject(const aValue : Variant): variant;
|
|
|
|
- end;
|
|
|
|
-
|
|
|
|
function JOBCallTJSPromiseExecutor(const aMethod: TMethod; var H: TJOBCallbackHelper): PByte;
|
|
function JOBCallTJSPromiseExecutor(const aMethod: TMethod; var H: TJOBCallbackHelper): PByte;
|
|
|
|
|
|
var
|
|
var
|
|
- F1,F2 : TJSFunction;
|
|
|
|
- Helper : TPromiseHelper;
|
|
|
|
|
|
+ P : TJSPromise;
|
|
|
|
|
|
begin
|
|
begin
|
|
- F1:=H.GetFunction;
|
|
|
|
- F2:=H.GetFunction;
|
|
|
|
- Helper:=TPromiseHelper.Create(F1,F2);
|
|
|
|
|
|
+ P:=TJSPromise(aMethod.Data);
|
|
|
|
+ P.FResolveCallback:=H.GetFunction;
|
|
|
|
+ P.FRejectCallBack:=H.GetFunction;
|
|
try
|
|
try
|
|
- TJSPromiseExecutor(aMethod)(@Helper.HandleResolve, @Helper.HandleReject);
|
|
|
|
- Helper.Free;
|
|
|
|
|
|
+ TJSPromiseExecutor(aMethod)(@P.HandleResolve, @P.HandleReject);
|
|
except
|
|
except
|
|
on E : Exception do
|
|
on E : Exception do
|
|
begin
|
|
begin
|
|
{$IFDEF VerboseJOB}
|
|
{$IFDEF VerboseJOB}
|
|
Writeln('Wasm error calling promise executor : ',E.Message);
|
|
Writeln('Wasm error calling promise executor : ',E.Message);
|
|
{$ENDIF}
|
|
{$ENDIF}
|
|
- Helper.Free;
|
|
|
|
Raise;
|
|
Raise;
|
|
end;
|
|
end;
|
|
on O : TObject do
|
|
on O : TObject do
|
|
@@ -1307,7 +1300,6 @@ begin
|
|
{$IFDEF VerboseJOB}
|
|
{$IFDEF VerboseJOB}
|
|
Writeln('Wasm error calling promise executor : ',O.ClassName);
|
|
Writeln('Wasm error calling promise executor : ',O.ClassName);
|
|
{$ENDIF}
|
|
{$ENDIF}
|
|
- Helper.Free;
|
|
|
|
Raise;
|
|
Raise;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -1317,24 +1309,6 @@ begin
|
|
Result:=H.AllocUndefined;
|
|
Result:=H.AllocUndefined;
|
|
end;
|
|
end;
|
|
|
|
|
|
-{ TPromiseHelper }
|
|
|
|
-
|
|
|
|
-constructor TPromiseHelper.create(aResolve, aReject: TJSFunction);
|
|
|
|
-begin
|
|
|
|
- FResolveCallback:=aResolve;
|
|
|
|
- FRejectCallback:=aReject;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function TPromiseHelper.HandleResolve(const aValue: Variant): variant;
|
|
|
|
-begin
|
|
|
|
- result:=FResolveCallback.apply([aValue]);
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
-function TPromiseHelper.HandleReject(const aValue: Variant): variant;
|
|
|
|
-begin
|
|
|
|
- Result:=FRejectCallback.apply([aValue]);
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
|
|
|
|
{ TJSTextEncoder }
|
|
{ TJSTextEncoder }
|
|
|
|
|
|
@@ -1352,12 +1326,30 @@ end;
|
|
|
|
|
|
{ TJSPromise }
|
|
{ TJSPromise }
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function TJSPromise.HandleResolve(const aValue: Variant): variant;
|
|
|
|
+begin
|
|
|
|
+ result:=FResolveCallback.apply(Self,[aValue]);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function TJSPromise.HandleReject(const aValue: Variant): variant;
|
|
|
|
+begin
|
|
|
|
+ Result:=FRejectCallback.apply(Self,[aValue]);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TJSPromise.DoExecutor(const OnResolve, OnReject: TJSPromiseResolver);
|
|
|
|
+begin
|
|
|
|
+ FExecutor(OnResolve,OnReject);
|
|
|
|
+end;
|
|
|
|
+
|
|
constructor TJSPromise.Create(const Executor: TJSPromiseExecutor);
|
|
constructor TJSPromise.Create(const Executor: TJSPromiseExecutor);
|
|
|
|
|
|
var
|
|
var
|
|
m: TJOB_Method;
|
|
m: TJOB_Method;
|
|
begin
|
|
begin
|
|
- m:=TJOB_Method.Create(TMethod(Executor),@JobCallTJSPromiseExecutor);
|
|
|
|
|
|
+ FExecutor:=Executor;
|
|
|
|
+ m:=TJOB_Method.Create(TMethod(@DoExecutor),@JobCallTJSPromiseExecutor);
|
|
try
|
|
try
|
|
JOBCreate([m]);
|
|
JOBCreate([m]);
|
|
finally
|
|
finally
|
|
@@ -1929,6 +1921,11 @@ begin
|
|
FThisID:=aThisID;
|
|
FThisID:=aThisID;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+destructor TJSFunction.destroy;
|
|
|
|
+begin
|
|
|
|
+ Inherited;
|
|
|
|
+end;
|
|
|
|
+
|
|
function TJSFunction._GetLength: NativeInt;
|
|
function TJSFunction._GetLength: NativeInt;
|
|
begin
|
|
begin
|
|
Result:=ReadJSPropertyLongInt('length');
|
|
Result:=ReadJSPropertyLongInt('length');
|
|
@@ -2185,10 +2182,11 @@ begin
|
|
inc(Index);
|
|
inc(Index);
|
|
end;
|
|
end;
|
|
|
|
|
|
-function TJOBCallbackHelper.GetFunction: TJSFunction;
|
|
|
|
|
|
+function TJOBCallbackHelper.GetFunction: IJSFunction;
|
|
var
|
|
var
|
|
aType : byte;
|
|
aType : byte;
|
|
ObjId,ThisId: LongWord;
|
|
ObjId,ThisId: LongWord;
|
|
|
|
+ F : TJSFunction;
|
|
|
|
|
|
begin
|
|
begin
|
|
{$IFDEF VerboseJOB}
|
|
{$IFDEF VerboseJOB}
|
|
@@ -2207,8 +2205,9 @@ begin
|
|
ThisId:=PLongWord(p)^;
|
|
ThisId:=PLongWord(p)^;
|
|
inc(p,4);
|
|
inc(p,4);
|
|
end;
|
|
end;
|
|
- Result:=TJSFunction.Create(ObjId,ThisId);
|
|
|
|
- Result.JOBObjectIDOwner:=false; // owned by caller (JS code in browser)
|
|
|
|
|
|
+ F:=TJSFunction.Create(ObjId,ThisId);
|
|
|
|
+ F.JOBObjectIDOwner:=false; // owned by caller (JS code in browser)
|
|
|
|
+ Result:=F;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJOBCallbackHelper.GetValue: TJOB_JSValue;
|
|
function TJOBCallbackHelper.GetValue: TJOB_JSValue;
|
|
@@ -2545,7 +2544,6 @@ constructor TJOB_String.Create(const aValue: UnicodeString);
|
|
begin
|
|
begin
|
|
Kind:=jjvkString;
|
|
Kind:=jjvkString;
|
|
Value:=aValue;
|
|
Value:=aValue;
|
|
- Writeln('Creating unicode string : ',aValue);
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJOB_String.AsString: UTF8string;
|
|
function TJOB_String.AsString: UTF8string;
|