Browse Source

Revert "wasi: job: write property object via separate wasi call"

This reverts commit 00c7d0ff4b589f69aeaae298a41c63ef8ad72936.
mattias 3 years ago
parent
commit
8a314fdc0a
3 changed files with 23 additions and 47 deletions
  1. 4 13
      demo/wasienv/dom/job_browser.pp
  2. 0 1
      demo/wasienv/dom/job_shared.pp
  3. 19 33
      demo/wasienv/dom/job_wasm.pas

+ 4 - 13
demo/wasienv/dom/job_browser.pp

@@ -25,8 +25,7 @@ Type
   Protected
   Protected
     function FindObject(ObjId: TJOBObjectID): TJSObject; virtual;
     function FindObject(ObjId: TJOBObjectID): TJSObject; virtual;
     function Invoke_JSResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP: NativeInt; out JSResult: JSValue): TJOBResult; virtual;
     function Invoke_JSResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP: NativeInt; out JSResult: JSValue): 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_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_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_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_StringResult(ObjId: TJOBObjectID; NameP, NameLen, Invoke, ArgsP, ResultP: NativeInt): TJOBResult; virtual;
@@ -75,7 +74,6 @@ end;
 procedure TJOBBridge.FillImportObject(aObject: TJSObject);
 procedure TJOBBridge.FillImportObject(aObject: TJSObject);
 begin
 begin
   aObject[JOBFn_InvokeNoResult]:=@Invoke_NoResult;
   aObject[JOBFn_InvokeNoResult]:=@Invoke_NoResult;
-  aObject[JOBFn_SetProperty]:=@Set_JSProperty;
   aObject[JOBFn_InvokeBooleanResult]:=@Invoke_BooleanResult;
   aObject[JOBFn_InvokeBooleanResult]:=@Invoke_BooleanResult;
   aObject[JOBFn_InvokeDoubleResult]:=@Invoke_DoubleResult;
   aObject[JOBFn_InvokeDoubleResult]:=@Invoke_DoubleResult;
   aObject[JOBFn_InvokeStringResult]:=@Invoke_StringResult;
   aObject[JOBFn_InvokeStringResult]:=@Invoke_StringResult;
@@ -155,19 +153,12 @@ begin
 end;
 end;
 
 
 function TJOBBridge.Invoke_NoResult(ObjId: TJOBObjectID; NameP, NameLen,
 function TJOBBridge.Invoke_NoResult(ObjId: TJOBObjectID; NameP, NameLen,
-  ArgsP: NativeInt): TJOBResult;
+  Invoke, ArgsP: NativeInt): TJOBResult;
 var
 var
   JSResult: JSValue;
   JSResult: JSValue;
 begin
 begin
-  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);
+  // invoke
+  Result:=Invoke_JSResult(ObjId,NameP,NameLen,Invoke,ArgsP,JSResult);
 end;
 end;
 
 
 function TJOBBridge.Invoke_BooleanResult(ObjId: TJOBObjectID; NameP, NameLen,
 function TJOBBridge.Invoke_BooleanResult(ObjId: TJOBObjectID; NameP, NameLen,

+ 0 - 1
demo/wasienv/dom/job_shared.pp

@@ -52,7 +52,6 @@ const
 
 
   JOBExportName = 'job';
   JOBExportName = 'job';
   JOBFn_InvokeNoResult = 'invoke_noresult';
   JOBFn_InvokeNoResult = 'invoke_noresult';
-  JOBFn_SetProperty = 'setproperty';
   JOBFn_InvokeBooleanResult = 'invoke_boolresult';
   JOBFn_InvokeBooleanResult = 'invoke_boolresult';
   JOBFn_InvokeDoubleResult = 'invoke_doubleresult';
   JOBFn_InvokeDoubleResult = 'invoke_doubleresult';
   JOBFn_InvokeStringResult = 'invoke_stringresult';
   JOBFn_InvokeStringResult = 'invoke_stringresult';

+ 19 - 33
demo/wasienv/dom/job_wasm.pas

@@ -42,6 +42,10 @@ Type
     jigCall,  // call function
     jigCall,  // call function
     jigGetter // read property
     jigGetter // read property
     );
     );
+  TJOBInvokeSetType = (
+    jisCall,  // call function
+    jisSetter // write property
+    );
 
 
   TJSObject = class;
   TJSObject = class;
   TJSObjectClass = class of TJSObject;
   TJSObjectClass = class of TJSObject;
@@ -58,12 +62,11 @@ Type
     procedure InvokeJS_RaiseResultMismatch(const aName: string; Expected, Actual: TJOBResult); virtual;
     procedure InvokeJS_RaiseResultMismatch(const aName: string; Expected, Actual: TJOBResult); virtual;
     procedure InvokeJS_RaiseResultMismatchStr(const aName: string; const Expected, Actual: string); virtual;
     procedure InvokeJS_RaiseResultMismatchStr(const aName: string; const Expected, Actual: string); virtual;
     function CreateInvokeJSArgs(const Args: array of const): PByte; virtual;
     function CreateInvokeJSArgs(const Args: array of const): PByte; virtual;
-    procedure SetJSProperty(const aName: string; Const Args: Array of const); virtual;
   public
   public
     constructor CreateFromID(aID: TJOBObjectID); virtual;
     constructor CreateFromID(aID: TJOBObjectID); virtual;
     destructor Destroy; override;
     destructor Destroy; override;
     property ObjectID: TJOBObjectID read FObjectID;
     property ObjectID: TJOBObjectID read FObjectID;
-    procedure InvokeJSNoResult(const aName: string; Const Args: Array of const); 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 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 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 InvokeJSUnicodeStringResult(const aName: string; Const Args: Array of const; Invoke: TJOBInvokeGetType = jigCall): UnicodeString; virtual;
@@ -93,16 +96,10 @@ function __job_invoke_noresult(
   ObjID: TJOBObjectID;
   ObjID: TJOBObjectID;
   NameP: PChar;
   NameP: PChar;
   NameLen: longint;
   NameLen: longint;
+  Invoke: longint;
   ArgP: PByte
   ArgP: PByte
 ): TJOBResult; external JOBExportName name JOBFn_InvokeNoResult;
 ): 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(
 function __job_invoke_boolresult(
   ObjID: TJOBObjectID;
   ObjID: TJOBObjectID;
   NameP: PChar;
   NameP: PChar;
@@ -157,6 +154,10 @@ const
     JOBInvokeCall,
     JOBInvokeCall,
     JOBInvokeGetter
     JOBInvokeGetter
     );
     );
+  InvokeSetToInt: array[TJOBInvokeSetType] of integer = (
+    JOBInvokeCall,
+    JOBInvokeSetter
+    );
 
 
 {$IFDEF VerboseJOB}
 {$IFDEF VerboseJOB}
 function GetVarRecName(vt: word): string;
 function GetVarRecName(vt: word): string;
@@ -505,21 +506,6 @@ begin
   {$ENDIF}
   {$ENDIF}
 end;
 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);
 constructor TJSObject.CreateFromID(aID: TJOBObjectID);
 begin
 begin
   FObjectID:=aID;
   FObjectID:=aID;
@@ -533,17 +519,17 @@ begin
 end;
 end;
 
 
 procedure TJSObject.InvokeJSNoResult(const aName: string;
 procedure TJSObject.InvokeJSNoResult(const aName: string;
-  const Args: array of const);
+  const Args: array of const; Invoke: TJOBInvokeSetType);
 var
 var
   aError: TJOBResult;
   aError: TJOBResult;
   InvokeArgs: PByte;
   InvokeArgs: PByte;
 begin
 begin
   if length(Args)=0 then
   if length(Args)=0 then
-    aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),nil)
+    aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),InvokeSetToInt[Invoke],nil)
   else begin
   else begin
     InvokeArgs:=CreateInvokeJSArgs(Args);
     InvokeArgs:=CreateInvokeJSArgs(Args);
     try
     try
-      aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),InvokeArgs);
+      aError:=__job_invoke_noresult(ObjectID,PChar(aName),length(aName),InvokeSetToInt[Invoke],InvokeArgs);
     finally
     finally
       if InvokeArgs<>nil then
       if InvokeArgs<>nil then
         FreeMem(InvokeArgs);
         FreeMem(InvokeArgs);
@@ -672,35 +658,35 @@ end;
 
 
 procedure TJSObject.WriteJSPropertyBoolean(const aName: string; Value: Boolean);
 procedure TJSObject.WriteJSPropertyBoolean(const aName: string; Value: Boolean);
 begin
 begin
-  SetJSProperty(aName,[Value]);
+  InvokeJSNoResult(aName,[Value],jisSetter);
 end;
 end;
 
 
 procedure TJSObject.WriteJSPropertyDouble(const aName: string; Value: Double);
 procedure TJSObject.WriteJSPropertyDouble(const aName: string; Value: Double);
 begin
 begin
-  SetJSProperty(aName,[Value]);
+  InvokeJSNoResult(aName,[Value],jisSetter);
 end;
 end;
 
 
 procedure TJSObject.WriteJSPropertyUnicodeString(const aName: string;
 procedure TJSObject.WriteJSPropertyUnicodeString(const aName: string;
   const Value: UnicodeString);
   const Value: UnicodeString);
 begin
 begin
-  SetJSProperty(aName,[Value]);
+  InvokeJSNoResult(aName,[Value],jisSetter);
 end;
 end;
 
 
 procedure TJSObject.WriteJSPropertyUtf8String(const aName: string;
 procedure TJSObject.WriteJSPropertyUtf8String(const aName: string;
   const Value: String);
   const Value: String);
 begin
 begin
-  SetJSProperty(aName,[Value]);
+  InvokeJSNoResult(aName,[Value],jisSetter);
 end;
 end;
 
 
 procedure TJSObject.WriteJSPropertyObject(const aName: string; Value: TJSObject
 procedure TJSObject.WriteJSPropertyObject(const aName: string; Value: TJSObject
   );
   );
 begin
 begin
-  SetJSProperty(aName,[Value]);
+  InvokeJSNoResult(aName,[Value],jisSetter);
 end;
 end;
 
 
 procedure TJSObject.WriteJSPropertyLongInt(const aName: string; Value: LongInt);
 procedure TJSObject.WriteJSPropertyLongInt(const aName: string; Value: LongInt);
 begin
 begin
-  SetJSProperty(aName,[Value]);
+  InvokeJSNoResult(aName,[Value],jisSetter);
 end;
 end;
 
 
 initialization
 initialization