mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-18 05:29:20 +02:00
wasi: job: write property object via separate wasi call
This commit is contained in:
parent
83b37657ff
commit
00c7d0ff4b
@ -25,7 +25,8 @@ Type
|
||||
Protected
|
||||
function FindObject(ObjId: TJOBObjectID): TJSObject; 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_NoResult(ObjId: TJOBObjectID; NameP, NameLen, ArgsP: NativeInt): TJOBResult; virtual;
|
||||
function Set_JSProperty(ObjId: TJOBObjectID; NameP, NameLen, 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;
|
||||
@ -74,6 +75,7 @@ end;
|
||||
procedure TJOBBridge.FillImportObject(aObject: TJSObject);
|
||||
begin
|
||||
aObject[JOBFn_InvokeNoResult]:=@Invoke_NoResult;
|
||||
aObject[JOBFn_SetProperty]:=@Set_JSProperty;
|
||||
aObject[JOBFn_InvokeBooleanResult]:=@Invoke_BooleanResult;
|
||||
aObject[JOBFn_InvokeDoubleResult]:=@Invoke_DoubleResult;
|
||||
aObject[JOBFn_InvokeStringResult]:=@Invoke_StringResult;
|
||||
@ -153,12 +155,19 @@ begin
|
||||
end;
|
||||
|
||||
function TJOBBridge.Invoke_NoResult(ObjId: TJOBObjectID; NameP, NameLen,
|
||||
Invoke, ArgsP: NativeInt): TJOBResult;
|
||||
ArgsP: NativeInt): TJOBResult;
|
||||
var
|
||||
JSResult: JSValue;
|
||||
begin
|
||||
// invoke
|
||||
Result:=Invoke_JSResult(ObjId,NameP,NameLen,Invoke,ArgsP,JSResult);
|
||||
Result:=Invoke_JSResult(ObjId,NameP,NameLen,JOBInvokeCall,ArgsP,JSResult);
|
||||
end;
|
||||
|
||||
function TJOBBridge.Set_JSProperty(ObjId: TJOBObjectID; NameP, NameLen,
|
||||
ArgsP: NativeInt): TJOBResult;
|
||||
var
|
||||
JSResult: JSValue;
|
||||
begin
|
||||
Result:=Invoke_JSResult(ObjId,NameP,NameLen,JOBInvokeSetter,ArgsP,JSResult);
|
||||
end;
|
||||
|
||||
function TJOBBridge.Invoke_BooleanResult(ObjId: TJOBObjectID; NameP, NameLen,
|
||||
|
@ -52,6 +52,7 @@ const
|
||||
|
||||
JOBExportName = 'job';
|
||||
JOBFn_InvokeNoResult = 'invoke_noresult';
|
||||
JOBFn_SetProperty = 'setproperty';
|
||||
JOBFn_InvokeBooleanResult = 'invoke_boolresult';
|
||||
JOBFn_InvokeDoubleResult = 'invoke_doubleresult';
|
||||
JOBFn_InvokeStringResult = 'invoke_stringresult';
|
||||
|
@ -42,10 +42,6 @@ Type
|
||||
jigCall, // call function
|
||||
jigGetter // read property
|
||||
);
|
||||
TJOBInvokeSetType = (
|
||||
jisCall, // call function
|
||||
jisSetter // write property
|
||||
);
|
||||
|
||||
TJSObject = class;
|
||||
TJSObjectClass = class of TJSObject;
|
||||
@ -62,11 +58,12 @@ Type
|
||||
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;
|
||||
procedure SetJSProperty(const aName: string; Const Args: Array of const); 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; Invoke: TJOBInvokeSetType = jisCall); virtual;
|
||||
procedure InvokeJSNoResult(const aName: string; Const Args: Array of const); 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;
|
||||
@ -96,10 +93,16 @@ function __job_invoke_noresult(
|
||||
ObjID: TJOBObjectID;
|
||||
NameP: PChar;
|
||||
NameLen: longint;
|
||||
Invoke: longint;
|
||||
ArgP: PByte
|
||||
): TJOBResult; external JOBExportName name JOBFn_InvokeNoResult;
|
||||
|
||||
function __job_setproperty(
|
||||
ObjID: TJOBObjectID;
|
||||
NameP: PChar;
|
||||
NameLen: longint;
|
||||
ArgP: PByte
|
||||
): TJOBResult; external JOBExportName name JOBFn_SetProperty;
|
||||
|
||||
function __job_invoke_boolresult(
|
||||
ObjID: TJOBObjectID;
|
||||
NameP: PChar;
|
||||
@ -154,10 +157,6 @@ const
|
||||
JOBInvokeCall,
|
||||
JOBInvokeGetter
|
||||
);
|
||||
InvokeSetToInt: array[TJOBInvokeSetType] of integer = (
|
||||
JOBInvokeCall,
|
||||
JOBInvokeSetter
|
||||
);
|
||||
|
||||
{$IFDEF VerboseJOB}
|
||||
function GetVarRecName(vt: word): string;
|
||||
@ -506,6 +505,21 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TJSObject.SetJSProperty(const aName: string;
|
||||
const Args: array of const);
|
||||
var
|
||||
InvokeArgs: PByte;
|
||||
begin
|
||||
if length(Args)<>1 then
|
||||
InvokeJS_Raise(aName,'wrong arg count');
|
||||
InvokeArgs:=CreateInvokeJSArgs(Args);
|
||||
try
|
||||
__job_setproperty(ObjectID,PChar(aName),length(aName),InvokeArgs);
|
||||
finally
|
||||
FreeMem(InvokeArgs);
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TJSObject.CreateFromID(aID: TJOBObjectID);
|
||||
begin
|
||||
FObjectID:=aID;
|
||||
@ -519,17 +533,17 @@ begin
|
||||
end;
|
||||
|
||||
procedure TJSObject.InvokeJSNoResult(const aName: string;
|
||||
const Args: array of const; Invoke: TJOBInvokeSetType);
|
||||
const Args: array of const);
|
||||
var
|
||||
aError: TJOBResult;
|
||||
InvokeArgs: PByte;
|
||||
begin
|
||||
if length(Args)=0 then
|
||||
aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),InvokeSetToInt[Invoke],nil)
|
||||
aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),nil)
|
||||
else begin
|
||||
InvokeArgs:=CreateInvokeJSArgs(Args);
|
||||
try
|
||||
aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),InvokeSetToInt[Invoke],InvokeArgs);
|
||||
aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),InvokeArgs);
|
||||
finally
|
||||
if InvokeArgs<>nil then
|
||||
FreeMem(InvokeArgs);
|
||||
@ -658,35 +672,35 @@ end;
|
||||
|
||||
procedure TJSObject.WriteJSPropertyBoolean(const aName: string; Value: Boolean);
|
||||
begin
|
||||
InvokeJSNoResult(aName,[Value],jisSetter);
|
||||
SetJSProperty(aName,[Value]);
|
||||
end;
|
||||
|
||||
procedure TJSObject.WriteJSPropertyDouble(const aName: string; Value: Double);
|
||||
begin
|
||||
InvokeJSNoResult(aName,[Value],jisSetter);
|
||||
SetJSProperty(aName,[Value]);
|
||||
end;
|
||||
|
||||
procedure TJSObject.WriteJSPropertyUnicodeString(const aName: string;
|
||||
const Value: UnicodeString);
|
||||
begin
|
||||
InvokeJSNoResult(aName,[Value],jisSetter);
|
||||
SetJSProperty(aName,[Value]);
|
||||
end;
|
||||
|
||||
procedure TJSObject.WriteJSPropertyUtf8String(const aName: string;
|
||||
const Value: String);
|
||||
begin
|
||||
InvokeJSNoResult(aName,[Value],jisSetter);
|
||||
SetJSProperty(aName,[Value]);
|
||||
end;
|
||||
|
||||
procedure TJSObject.WriteJSPropertyObject(const aName: string; Value: TJSObject
|
||||
);
|
||||
begin
|
||||
InvokeJSNoResult(aName,[Value],jisSetter);
|
||||
SetJSProperty(aName,[Value]);
|
||||
end;
|
||||
|
||||
procedure TJSObject.WriteJSPropertyLongInt(const aName: string; Value: LongInt);
|
||||
begin
|
||||
InvokeJSNoResult(aName,[Value],jisSetter);
|
||||
SetJSProperty(aName,[Value]);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
Loading…
Reference in New Issue
Block a user