wasi: job: read/write property

This commit is contained in:
mattias 2022-05-25 14:31:44 +02:00
parent 3496007ff2
commit 0bd91a14dd
6 changed files with 261 additions and 116 deletions

View File

@ -43,6 +43,7 @@
<Unit>
<Filename Value="job_browser.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="JOB_Browser"/>
</Unit>
</Units>
</ProjectOptions>

View File

@ -17,6 +17,8 @@ Type
procedure Proc;
function ArgsToStr(Args: TJSFunctionArguments): string;
published
Size: integer;
Caption: string;
function GetBoolean: boolean;
function GetDouble: double;
function GetString: string;

View File

@ -12,13 +12,27 @@ type
{ TBird }
TBird = class(TJSObject)
private
function GetSize: integer;
procedure SetSize(const AValue: integer);
public
function GetDouble: double;
function GetInteger: integer;
property Size: integer read GetSize write SetSize;
end;
{ TBird }
function TBird.GetSize: integer;
begin
Result:=ReadJSPropertyLongInt('Size');
end;
procedure TBird.SetSize(const AValue: integer);
begin
WriteJSPropertyLongInt('Size',AValue);
end;
function TBird.GetDouble: double;
begin
Result:=InvokeJSDoubleResult('GetDouble',[]);
@ -40,16 +54,15 @@ begin
writeln('AAA1 ');
u:='äbc';
u:=obj.InvokeJSUnicodeStringResult('GetString',[u]);
writeln('AAA2 u="',u,'"');
//obj.InvokeJSNoResult('Proc',[]);
//d:=obj.InvokeJSDoubleResult('GetDouble',[u,12345678901]);
Freddy:=obj.InvokeJSObjResult('CreateChick',TBird,['Freddy']) as TBird;
Freddy:=obj.InvokeJSObjResult('CreateChick',['Freddy'],TBird) as TBird;
writeln('AAA3 ');
i:=Freddy.GetInteger;
writeln('AAA4 ',i);
Freddy.Size:=81;
writeln('AAA4 ');
i:=Freddy.Size;
writeln('AAA5 ',i);
Freddy.Free;
writeln('AAA5 ');
writeln('AAA6 ');
end.

View File

@ -24,12 +24,12 @@ Type
FStringResult: string;
Protected
function FindObject(ObjId: TJOBObjectID): TJSObject; virtual;
function Invoke_JSResult(ObjId: TJOBObjectID; FuncNameP, FuncNameLen, ArgsP: NativeInt; out JSResult: JSValue): TJOBResult; virtual;
function Invoke_NoResult(ObjId: TJOBObjectID; FuncNameP, FuncNameLen, ArgsP, Dummy: NativeInt): TJOBResult; virtual;
function Invoke_BooleanResult(ObjId: TJOBObjectID; FuncNameP, FuncNameLen, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
function Invoke_DoubleResult(ObjId: TJOBObjectID; FuncNameP, FuncNameLen, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
function Invoke_StringResult(ObjId: TJOBObjectID; FuncNameP, FuncNameLen, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
function Invoke_ObjectResult(ObjId: TJOBObjectID; FuncNameP, FuncNameLen, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
function Invoke_JSResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP: NativeInt; out JSResult: JSValue): TJOBResult; virtual;
function Invoke_NoResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP: NativeInt): TJOBResult; virtual;
function Invoke_BooleanResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
function Invoke_DoubleResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
function Invoke_StringResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
function Invoke_ObjectResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
function ReleaseObject(ObjId: TJOBObjectID): TJOBResult; virtual;
function GetStringResult(ResultP: NativeInt): TJOBResult; virtual;
function ReleaseStringResult: TJOBResult; virtual;
@ -93,59 +93,82 @@ begin
Result:=nil;
end;
function TJOBBridge.Invoke_JSResult(ObjId: TJOBObjectID; FuncNameP,
FuncNameLen, ArgsP: NativeInt; out JSResult: JSValue): TJOBResult;
function TJOBBridge.Invoke_JSResult(ObjId: TJOBObjectID; NameP, NameLen,
Invoke, ArgsP: NativeInt; out JSResult: JSValue): TJOBResult;
var
View: TJSDataView;
aBytes: TJSUint8Array;
FuncName: String;
PropName: String;
Args: TJSValueDynArray;
Obj: TJSObject;
fn: JSValue;
begin
//writeln('TJOBBridge.Invoke_JSResult ObjId=',ObjId,' FuncNameP=',FuncNameP,' FuncNameLen=',FuncNameLen,' ArgsP=',ArgsP);
writeln('TJOBBridge.Invoke_JSResult ObjId=',ObjId,' FuncNameP=',NameP,' FuncNameLen=',NameLen,' ArgsP=',ArgsP,' Invoke=',Invoke);
Obj:=FindObject(ObjId);
if Obj=nil then
exit(JOBResult_UnknownObjId);
View:=getModuleMemoryDataView();
aBytes:=TJSUint8Array.New(View.buffer, FuncNameP, FuncNameLen);
aBytes:=TJSUint8Array.New(View.buffer, NameP, NameLen);
//writeln('TJOBBridge.Invoke_JSResult aBytes=',aBytes);
FuncName:=TypedArrayToString(aBytes);
//writeln('TJOBBridge.Invoke_JSResult FuncName="',FuncName,'"');
PropName:=TypedArrayToString(aBytes);
writeln('TJOBBridge.Invoke_JSResult PropName="',PropName,'"');
fn:=Obj[FuncName];
if jstypeof(fn)<>'function' then
case Invoke of
JOBInvokeCall:
begin
fn:=Obj[PropName];
if jstypeof(fn)<>'function' then
exit(JOBResult_NotAFunction);
if ArgsP=0 then
JSResult:=TJSFunction(fn).call(Obj)
else begin
Args:=GetInvokeArguments(View,ArgsP);
JSResult:=TJSFunction(fn).apply(Obj,Args);
end;
end;
JOBInvokeGetter:
begin
if ArgsP>0 then
exit(JOBResult_WrongArgs);
JSResult:=Obj[PropName];
end;
JOBInvokeSetter:
begin
JSResult:=Undefined;
if ArgsP=0 then
exit(JOBResult_WrongArgs);
Args:=GetInvokeArguments(View,ArgsP);
if length(Args)<>1 then
exit(JOBResult_WrongArgs);
Obj[PropName]:=Args[0];
end
else
exit(JOBResult_NotAFunction);
if ArgsP=0 then
JSResult:=TJSFunction(fn).call(Obj)
else begin
Args:=GetInvokeArguments(View,ArgsP);
JSResult:=TJSFunction(fn).apply(Obj,Args);
end;
Result:=JOBResult_Success;
end;
function TJOBBridge.Invoke_NoResult(ObjId: TJOBObjectID; FuncNameP,
FuncNameLen, ArgsP, Dummy: NativeInt): TJOBResult;
function TJOBBridge.Invoke_NoResult(ObjId: TJOBObjectID; NameP, NameLen,
Invoke, ArgsP: NativeInt): TJOBResult;
var
JSResult: JSValue;
begin
// invoke
Result:=Invoke_JSResult(ObjId,FuncNameP,FuncNameLen,ArgsP,JSResult);
Result:=Invoke_JSResult(ObjId,NameP,NameLen,Invoke,ArgsP,JSResult);
end;
function TJOBBridge.Invoke_BooleanResult(ObjId: TJOBObjectID; FuncNameP,
FuncNameLen, ArgsP, ResultP: NativeInt): TJOBResult;
function TJOBBridge.Invoke_BooleanResult(ObjId: TJOBObjectID; NameP, NameLen,
Invoke, ArgsP, ResultP: NativeInt): TJOBResult;
var
JSResult: JSValue;
b: byte;
begin
// invoke
Result:=Invoke_JSResult(ObjId,FuncNameP,FuncNameLen,ArgsP,JSResult);
Result:=Invoke_JSResult(ObjId,NameP,NameLen,Invoke,ArgsP,JSResult);
if Result<>JOBResult_Success then
exit;
// check result type
@ -160,13 +183,13 @@ begin
Result:=JOBResult_Boolean;
end;
function TJOBBridge.Invoke_DoubleResult(ObjId: TJOBObjectID; FuncNameP,
FuncNameLen, ArgsP, ResultP: NativeInt): TJOBResult;
function TJOBBridge.Invoke_DoubleResult(ObjId: TJOBObjectID; NameP, NameLen,
Invoke, ArgsP, ResultP: NativeInt): TJOBResult;
var
JSResult: JSValue;
begin
// invoke
Result:=Invoke_JSResult(ObjId,FuncNameP,FuncNameLen,ArgsP,JSResult);
Result:=Invoke_JSResult(ObjId,NameP,NameLen,Invoke,ArgsP,JSResult);
if Result<>JOBResult_Success then
exit;
// check result type
@ -177,13 +200,13 @@ begin
Result:=JOBResult_Double;
end;
function TJOBBridge.Invoke_StringResult(ObjId: TJOBObjectID; FuncNameP,
FuncNameLen, ArgsP, ResultP: NativeInt): TJOBResult;
function TJOBBridge.Invoke_StringResult(ObjId: TJOBObjectID; NameP, NameLen,
Invoke, ArgsP, ResultP: NativeInt): TJOBResult;
var
JSResult: JSValue;
begin
// invoke
Result:=Invoke_JSResult(ObjId,FuncNameP,FuncNameLen,ArgsP,JSResult);
Result:=Invoke_JSResult(ObjId,NameP,NameLen,Invoke,ArgsP,JSResult);
if Result<>JOBResult_Success then
exit;
// check result type
@ -196,14 +219,15 @@ begin
getModuleMemoryDataView().setInt32(ResultP, length(FStringResult), env.IsLittleEndian);
end;
function TJOBBridge.Invoke_ObjectResult(ObjId: TJOBObjectID; FuncNameP,
FuncNameLen, ArgsP, ResultP: NativeInt): TJOBResult;
function TJOBBridge.Invoke_ObjectResult(ObjId: TJOBObjectID; NameP, NameLen,
Invoke, ArgsP, ResultP: NativeInt): TJOBResult;
var
t: String;
JSResult, NewId: JSValue;
begin
// invoke
Result:=Invoke_JSResult(ObjId,FuncNameP,FuncNameLen,ArgsP,JSResult);
Result:=Invoke_JSResult(ObjId,NameP,NameLen,Invoke,ArgsP,JSResult);
writeln('BBB1 TJOBBridge.Invoke_ObjectResult ',Result,' JSResult=',JSResult);
if Result<>JOBResult_Success then
exit;
// check result type

View File

@ -18,24 +18,26 @@ const
JOBResult_Success = 1;
JOBResult_UnknownObjId = 2;
JOBResult_NotAFunction = 3;
JOBResult_Undefined = 4;
JOBResult_Null = 5;
JOBResult_Boolean = 6;
JOBResult_Number = 7;
JOBResult_Double = 8;
JOBResult_String = 9;
JOBResult_Function = 10;
JOBResult_Object = 11;
JOBResult_BigInt = 12;
JOBResult_Symbol = 13;
JOBResult_WrongArgs = 4;
JOBResult_Undefined = 5;
JOBResult_Null = 6;
JOBResult_Boolean = 7;
JOBResult_Number = 8;
JOBResult_Double = 9;
JOBResult_String = 10;
JOBResult_Function = 11;
JOBResult_Object = 12;
JOBResult_BigInt = 13;
JOBResult_Symbol = 14;
JOBResultLast = 13;
JOBResultLast = 14;
JOBResult_Names: array[0..JOBResultLast] of string = (
'None',
'Success',
'UnknownObjId',
'NotAFunction',
'WrongArgs',
'Undefined',
'Null',
'Boolean',
@ -68,6 +70,10 @@ const
JOBArgUnicodeString = 7; // followed by length and pointer
JOBArgPointer = 8;
JOBInvokeCall = 0;
JOBInvokeGetter = 1;
JOBInvokeSetter = 2;
JOBObjIdDocument = -1;
JOBObjIdWindow = -2;
JOBObjIdConsole = -3;

View File

@ -31,12 +31,22 @@ Type
PJOBObjectID = ^TJOBObjectID;
TJOBInvokeOneResultFunc = function(
ObjID: TJOBObjectID;
FuncNameP: PChar;
FuncNameLen: longint;
NameP: PChar;
NameLen: longint;
Invoke: longint;
ArgP: PByte;
ResultP: PByte
): TJOBResult;
TJOBInvokeGetType = (
jigCall, // call function
jigGetter // read property
);
TJOBInvokeSetType = (
jisCall, // call function
jisSetter // write property
);
TJSObject = class;
TJSObjectClass = class of TJSObject;
@ -47,23 +57,36 @@ Type
FObjectID: TJOBObjectID;
protected
function InvokeJSOneResult(const aName: string; Const Args: Array of const;
const InvokeFunc: TJOBInvokeOneResultFunc; ResultP: PByte): TJOBResult;
procedure InvokeRaise(const aName, Msg: string); virtual;
procedure InvokeRaiseResultMismatch(const aName: string; Expected, Actual: TJOBResult); virtual;
procedure InvokeRaiseResultMismatchStr(const aName: string; const Expected, Actual: string); virtual;
const InvokeFunc: TJOBInvokeOneResultFunc; ResultP: PByte; Invoke: TJOBInvokeGetType): TJOBResult;
procedure InvokeJS_Raise(const aName, Msg: string); virtual;
procedure InvokeJS_RaiseResultMismatch(const aName: string; Expected, Actual: TJOBResult); virtual;
procedure InvokeJS_RaiseResultMismatchStr(const aName: string; const Expected, Actual: string); virtual;
function CreateInvokeJSArgs(const Args: array of const): PByte; virtual;
public
constructor CreateFromID(aID: TJOBObjectID); virtual;
destructor Destroy; override;
property ObjectID: TJOBObjectID read FObjectID;
procedure InvokeJSNoResult(const aName: string; Const Args: Array of const); virtual;
function InvokeJSBooleanResult(const aName: string; Const Args: Array of const): Boolean; virtual;
function InvokeJSDoubleResult(const aName: string; Const Args: Array of const): Double; virtual;
function InvokeJSUnicodeStringResult(const aName: string; Const Args: Array of const): UnicodeString; virtual;
function InvokeJSObjResult(const aName: string; aResultClass: TJSObjectClass; Const Args: Array of const): TJSObject; virtual;
// ToDo: InvokeJSVarRecResult
function InvokeJSUtf8StringResult(const aName: string; Const args: Array of const): String; virtual;
function InvokeJSLongIntResult(const aName: string; Const args: Array of const): LongInt; virtual;
procedure InvokeJSNoResult(const aName: string; Const Args: Array of const; Invoke: TJOBInvokeSetType = jisCall); virtual;
function InvokeJSBooleanResult(const aName: string; Const Args: Array of const; Invoke: TJOBInvokeGetType = jigCall): Boolean; virtual;
function InvokeJSDoubleResult(const aName: string; Const Args: Array of const; Invoke: TJOBInvokeGetType = jigCall): Double; virtual;
function InvokeJSUnicodeStringResult(const aName: string; Const Args: Array of const; Invoke: TJOBInvokeGetType = jigCall): UnicodeString; virtual;
function InvokeJSObjResult(const aName: string; Const Args: Array of const; aResultClass: TJSObjectClass; Invoke: TJOBInvokeGetType = jigCall): TJSObject; virtual;
// ToDo: InvokeJSValueResult
function InvokeJSUtf8StringResult(const aName: string; Const args: Array of const; Invoke: TJOBInvokeGetType = jigCall): String; virtual;
function InvokeJSLongIntResult(const aName: string; Const args: Array of const; Invoke: TJOBInvokeGetType = jigCall): LongInt; virtual;
function ReadJSPropertyBoolean(const aName: string): boolean; virtual;
function ReadJSPropertyDouble(const aName: string): double; virtual;
function ReadJSPropertyUnicodeString(const aName: string): UnicodeString; virtual;
function ReadJSPropertyObject(const aName: string; aResultClass: TJSObjectClass): TJSObject; virtual;
function ReadJSPropertyUtf8String(const aName: string): string; virtual;
function ReadJSPropertyLongInt(const aName: string): LongInt; virtual;
// ToDo: get JSValue property
procedure WriteJSPropertyBoolean(const aName: string; Value: Boolean); virtual;
procedure WriteJSPropertyDouble(const aName: string; Value: Double); virtual;
procedure WriteJSPropertyUnicodeString(const aName: string; const Value: UnicodeString); virtual;
procedure WriteJSPropertyUtf8String(const aName: string; const Value: String); virtual;
// ToDo: procedure WriteJSPropertyObject(const aName: string; AnObjectID: TJOBObjectID); virtual;
procedure WriteJSPropertyLongInt(const aName: string; Value: LongInt); virtual;
end;
var
@ -71,32 +94,35 @@ var
function __job_invoke_noresult(
ObjID: TJOBObjectID;
FuncNameP: PChar;
FuncNameLen: longint;
ArgP: PByte;
Dummy: PByte
NameP: PChar;
NameLen: longint;
Invoke: longint;
ArgP: PByte
): TJOBResult; external JOBExportName name JOBFn_InvokeNoResult;
function __job_invoke_boolresult(
ObjID: TJOBObjectID;
FuncNameP: PChar;
FuncNameLen: longint;
NameP: PChar;
NameLen: longint;
Invoke: longint;
ArgP: PByte;
ResultP: PByte // bytebool
): TJOBResult; external JOBExportName name JOBFn_InvokeBooleanResult;
function __job_invoke_doubleresult(
ObjID: TJOBObjectID;
FuncNameP: PChar;
FuncNameLen: longint;
NameP: PChar;
NameLen: longint;
Invoke: longint;
ArgP: PByte;
ResultP: PByte // double
): TJOBResult; external JOBExportName name JOBFn_InvokeDoubleResult;
function __job_invoke_stringresult(
ObjID: TJOBObjectID;
FuncNameP: PChar;
FuncNameLen: longint;
NameP: PChar;
NameLen: longint;
Invoke: longint;
ArgP: PByte;
ResultLenP: PByte // length
): TJOBResult; external JOBExportName name JOBFn_InvokeStringResult;
@ -110,8 +136,9 @@ function __job_releasestringresult(
function __job_invoke_objectresult(
ObjID: TJOBObjectID;
FuncNameP: PChar;
FuncNameLen: longint;
NameP: PChar;
NameLen: longint;
Invoke: longint;
ArgP: PByte;
ResultP: PByte // nativeint
): TJOBResult; external JOBExportName name JOBFn_InvokeObjectResult;
@ -122,6 +149,16 @@ function __job_release_object(
implementation
const
InvokeGetToInt: array[TJOBInvokeGetType] of integer = (
JOBInvokeCall,
JOBInvokeGetter
);
InvokeSetToInt: array[TJOBInvokeSetType] of integer = (
JOBInvokeCall,
JOBInvokeSetter
);
{$IFDEF VerboseJOB}
function GetVarRecName(vt: word): string;
begin
@ -155,17 +192,18 @@ end;
{ TJSObject }
function TJSObject.InvokeJSOneResult(const aName: string; const Args: array of const;
const InvokeFunc: TJOBInvokeOneResultFunc; ResultP: PByte): TJOBResult;
function TJSObject.InvokeJSOneResult(const aName: string;
const Args: array of const; const InvokeFunc: TJOBInvokeOneResultFunc;
ResultP: PByte; Invoke: TJOBInvokeGetType): TJOBResult;
var
InvokeArgs: PByte;
begin
if length(Args)=0 then
Result:=InvokeFunc(ObjectID,PChar(aName),length(aName),nil,ResultP)
Result:=InvokeFunc(ObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],nil,ResultP)
else begin
InvokeArgs:=CreateInvokeJSArgs(Args);
try
Result:=InvokeFunc(ObjectID,PChar(aName),length(aName),InvokeArgs,ResultP);
Result:=InvokeFunc(ObjectID,PChar(aName),length(aName),InvokeGetToInt[Invoke],InvokeArgs,ResultP);
finally
if InvokeArgs<>nil then
FreeMem(InvokeArgs);
@ -173,7 +211,7 @@ begin
end;
end;
procedure TJSObject.InvokeRaise(const aName, Msg: string);
procedure TJSObject.InvokeJS_Raise(const aName, Msg: string);
var
E: EJSInvoke;
begin
@ -183,21 +221,21 @@ begin
raise E;
end;
procedure TJSObject.InvokeRaiseResultMismatch(const aName: string;
procedure TJSObject.InvokeJS_RaiseResultMismatch(const aName: string;
Expected, Actual: TJOBResult);
begin
case Actual of
JOBResult_UnknownObjId: InvokeRaise(aName,'unknown object id '+IntToStr(ObjectID));
JOBResult_NotAFunction: InvokeRaise(aName,'object '+IntToStr(ObjectID)+' does not have a function "'+aName+'"');
JOBResult_UnknownObjId: InvokeJS_Raise(aName,'unknown object id '+IntToStr(ObjectID));
JOBResult_NotAFunction: InvokeJS_Raise(aName,'object '+IntToStr(ObjectID)+' does not have a function "'+aName+'"');
else
InvokeRaiseResultMismatchStr(aName,JOBResult_Names[Expected],JOBResult_Names[Actual]);
InvokeJS_RaiseResultMismatchStr(aName,JOBResult_Names[Expected],JOBResult_Names[Actual]);
end;
end;
procedure TJSObject.InvokeRaiseResultMismatchStr(const aName: string;
procedure TJSObject.InvokeJS_RaiseResultMismatchStr(const aName: string;
const Expected, Actual: string);
begin
InvokeRaise(aName,'expected '+Expected+', but got '+Actual+' from object '+IntToStr(ObjectID)+' function "'+aName+'"');
InvokeJS_Raise(aName,'expected '+Expected+', but got '+Actual+' from object '+IntToStr(ObjectID)+' function "'+aName+'"');
end;
function TJSObject.CreateInvokeJSArgs(const Args: array of const): PByte;
@ -249,7 +287,10 @@ begin
strlen(Args[i].VPChar);
inc(Len,1+SizeOf(NativeInt)+SizeOf(PByte));
end;
vtObject : RaiseNotSupported('object');
vtObject :
begin
RaiseNotSupported('object');
end;
vtClass : RaiseNotSupported('class');
vtPWideChar : RaiseNotSupported('pwidechar');
vtAnsiString : inc(Len,1+SizeOf(NativeInt)+SizeOf(PByte));
@ -458,60 +499,60 @@ begin
end;
procedure TJSObject.InvokeJSNoResult(const aName: string;
const Args: array of const);
const Args: array of const; Invoke: TJOBInvokeSetType);
var
aError: TJOBResult;
InvokeArgs: PByte;
begin
if length(Args)=0 then
aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),nil,nil)
aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),InvokeSetToInt[Invoke],nil)
else begin
InvokeArgs:=CreateInvokeJSArgs(Args);
try
aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),InvokeArgs,nil);
aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),InvokeSetToInt[Invoke],InvokeArgs);
finally
if InvokeArgs<>nil then
FreeMem(InvokeArgs);
end;
end;
if aError<>JOBResult_Success then
InvokeRaiseResultMismatch(aName,JOBResult_Success,aError);
InvokeJS_RaiseResultMismatch(aName,JOBResult_Success,aError);
end;
function TJSObject.InvokeJSBooleanResult(const aName: string;
const Args: array of const): Boolean;
const Args: array of const; Invoke: TJOBInvokeGetType): Boolean;
var
aError: TJOBResult;
b: bytebool;
begin
b:=false;
aError:=InvokeJSOneResult(aName,Args,@__job_invoke_boolresult,@b);
aError:=InvokeJSOneResult(aName,Args,@__job_invoke_boolresult,@b,Invoke);
if aError<>JOBResult_Boolean then
InvokeRaiseResultMismatch(aName,JOBResult_Boolean,aError);
InvokeJS_RaiseResultMismatch(aName,JOBResult_Boolean,aError);
Result:=b;
end;
function TJSObject.InvokeJSDoubleResult(const aName: string;
const Args: array of const): Double;
const Args: array of const; Invoke: TJOBInvokeGetType): Double;
var
aError: TJOBResult;
begin
Result:=NaN;
aError:=InvokeJSOneResult(aName,Args,@__job_invoke_doubleresult,@Result);
aError:=InvokeJSOneResult(aName,Args,@__job_invoke_doubleresult,@Result,Invoke);
if aError<>JOBResult_Double then
InvokeRaiseResultMismatch(aName,JOBResult_Double,aError);
InvokeJS_RaiseResultMismatch(aName,JOBResult_Double,aError);
end;
function TJSObject.InvokeJSUnicodeStringResult(const aName: string;
const Args: array of const): UnicodeString;
const Args: array of const; Invoke: TJOBInvokeGetType): UnicodeString;
var
ResultLen: NativeInt;
aError: TJOBResult;
begin
ResultLen:=0;
aError:=InvokeJSOneResult(aName,Args,@__job_invoke_stringresult,@ResultLen);
aError:=InvokeJSOneResult(aName,Args,@__job_invoke_stringresult,@ResultLen,Invoke);
if aError<>JOBResult_String then
InvokeRaiseResultMismatch(aName,JOBResult_String,aError);
InvokeJS_RaiseResultMismatch(aName,JOBResult_String,aError);
if ResultLen=0 then
exit('');
try
@ -526,42 +567,100 @@ begin
end;
function TJSObject.InvokeJSObjResult(const aName: string;
aResultClass: TJSObjectClass; const Args: array of const): TJSObject;
const Args: array of const; aResultClass: TJSObjectClass;
Invoke: TJOBInvokeGetType): TJSObject;
var
aError: TJOBResult;
NewObjId: TJOBObjectID;
begin
Result:=nil;
NewObjId:=-1;
aError:=InvokeJSOneResult(aName,Args,@__job_invoke_objectresult,@NewObjId);
aError:=InvokeJSOneResult(aName,Args,@__job_invoke_objectresult,@NewObjId,Invoke);
if aError=JOBResult_Null then
exit;
if aError<>JOBResult_Object then
InvokeRaiseResultMismatch(aName,JOBResult_Object,aError);
InvokeJS_RaiseResultMismatch(aName,JOBResult_Object,aError);
Result:=aResultClass.CreateFromID(NewObjId);
end;
function TJSObject.InvokeJSUtf8StringResult(const aName: string;
const args: array of const): String;
const args: array of const; Invoke: TJOBInvokeGetType): String;
begin
Result:=String(InvokeJSUnicodeStringResult(aName,Args));
Result:=String(InvokeJSUnicodeStringResult(aName,Args,Invoke));
end;
function TJSObject.InvokeJSLongIntResult(const aName: string;
const args: array of const): LongInt;
const args: array of const; Invoke: TJOBInvokeGetType): LongInt;
var
d: Double;
begin
d:=InvokeJSDoubleResult(aName,Args);
if Frac(d)<>0 then
InvokeRaiseResultMismatchStr(aName,'longint','double')
else if (d<low(longint)) or (d>high(longint)) then
InvokeRaiseResultMismatchStr(aName,'longint','double')
d:=InvokeJSDoubleResult(aName,Args,Invoke);
if (Frac(d)<>0) or (d<low(longint)) or (d>high(longint)) then
InvokeJS_RaiseResultMismatchStr(aName,'longint','double')
else
Result:=Trunc(d);
end;
function TJSObject.ReadJSPropertyBoolean(const aName: string): boolean;
begin
Result:=InvokeJSBooleanResult(aName,[],jigGetter);
end;
function TJSObject.ReadJSPropertyDouble(const aName: string): double;
begin
Result:=InvokeJSDoubleResult(aName,[],jigGetter);
end;
function TJSObject.ReadJSPropertyUnicodeString(const aName: string
): UnicodeString;
begin
Result:=InvokeJSUnicodeStringResult(aName,[],jigGetter);
end;
function TJSObject.ReadJSPropertyObject(const aName: string;
aResultClass: TJSObjectClass): TJSObject;
begin
Result:=InvokeJSObjResult(aName,[],aResultClass,jigGetter);
end;
function TJSObject.ReadJSPropertyUtf8String(const aName: string): string;
begin
Result:=InvokeJSUtf8StringResult(aName,[],jigGetter);
end;
function TJSObject.ReadJSPropertyLongInt(const aName: string): LongInt;
begin
Result:=InvokeJSLongIntResult(aName,[],jigGetter);
end;
procedure TJSObject.WriteJSPropertyBoolean(const aName: string; Value: Boolean);
begin
InvokeJSNoResult(aName,[Value],jisSetter);
end;
procedure TJSObject.WriteJSPropertyDouble(const aName: string; Value: Double);
begin
InvokeJSNoResult(aName,[Value],jisSetter);
end;
procedure TJSObject.WriteJSPropertyUnicodeString(const aName: string;
const Value: UnicodeString);
begin
InvokeJSNoResult(aName,[Value],jisSetter);
end;
procedure TJSObject.WriteJSPropertyUtf8String(const aName: string;
const Value: String);
begin
InvokeJSNoResult(aName,[Value],jisSetter);
end;
procedure TJSObject.WriteJSPropertyLongInt(const aName: string; Value: LongInt);
begin
InvokeJSNoResult(aName,[Value],jisSetter);
end;
initialization
JSDocument:=TJSObject.CreateFromID(JOBObjIdDocument);