Browse Source

* Handle "object" as argument type

Michaël Van Canneyt 1 year ago
parent
commit
e044aae4dc
2 changed files with 31 additions and 0 deletions
  1. 2 0
      packages/webidl/src/webidltowasmjob.pp
  2. 29 0
      packages/webidl/tests/tcwebidl2wasmjob.pas

+ 2 - 0
packages/webidl/src/webidltowasmjob.pp

@@ -1029,6 +1029,7 @@ begin
       'UnicodeString': GetFunc:='GetString';
       'Variant': GetFunc:='GetVariant';
       'TJOB_JSValue': GetFunc:='GetValue';
+      'IJSObject': GetFunc:='GetObject';
       else
         if (ArgType is TIDLInterfaceDefinition) or (ArgType is TIDLDictionaryDefinition) then
           GetFunc:='GetObject('+GetName(ArgType)+') as '+ArgTypeName
@@ -1088,6 +1089,7 @@ begin
     'UnicodeString': GetFunc:='Result:=H.AllocString('+Call+');';
     'Variant': GetFunc:='Result:=H.AllocVariant('+Call+');';
     'TJOB_JSValue': GetFunc:='Result:=H.AllocJSValue('+Call+');';
+    'IJSObject' : GetFunc:='Result:=H.AllocIntf('+Call+');'
     else
       if ReturnDef is TIDLInterfaceDefinition then
         GetFunc:='Result:=H.AllocIntf('+Call+');'

+ 29 - 0
packages/webidl/tests/tcwebidl2wasmjob.pas

@@ -45,6 +45,8 @@ type
     procedure TestWJ_IntfAttribute_ArrayBufferView;
     procedure TestWJ_IntfAttribute_ChromeOnly;
 
+    procedure TestWJ_CallBackObject;
+
     // todo procedure TestWJ_IntfAttribute_Any;
 
     // functions
@@ -684,6 +686,33 @@ begin
   ]);
 end;
 
+procedure TTestWebIDL2WasmJob.TestWJ_CallBackObject;
+
+begin
+  WebIDLToPas.TypeAliases.Add('AudioWorkletProcessor=IJSObject');
+  TestWebIDL([
+  '  callback constructor AudioWorkletProcessorConstructor = AudioWorkletProcessor (object options);'
+  ],
+  [
+  'Type',
+  '  // Forward class definitions',
+  '  TAudioWorkletProcessorConstructor = function (options: IJSObject): IJSObject of object;',
+  '',
+  'implementation',
+  '',
+  'function JOBCallTAudioWorkletProcessorConstructor(const aMethod: TMethod; var H: TJOBCallbackHelper): PByte;',
+  ' var',
+  '   options: IJSObject;',
+  'begin',
+  '  options:=H.GetObject;',
+  '  Result:=H.AllocIntf(TAudioWorkletProcessorConstructor(aMethod)(options));',
+  'end;',
+  '',
+  'end.'
+  ]);
+
+end;
+
 procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_Void;
 begin
   TestWebIDL([