Browse Source

* Handle complex nested types in arguments

Michaël Van Canneyt 1 year ago
parent
commit
388a55904a

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

@@ -64,6 +64,7 @@ Type
     wibtError,
     wibtError,
     wibtDOMException,
     wibtDOMException,
     // arrays
     // arrays
+    wibtVariantArray,
     wibtArrayBuffer,
     wibtArrayBuffer,
     wibtArrayBufferView,
     wibtArrayBufferView,
     wibtDataView,
     wibtDataView,
@@ -111,6 +112,7 @@ const
     'Function',
     'Function',
     'Error',
     'Error',
     'DOMException',
     'DOMException',
+    'VariantArray',
     'ArrayBuffer',
     'ArrayBuffer',
     'ArrayBufferView',
     'ArrayBufferView',
     'DataView',
     'DataView',

+ 10 - 1
packages/webidl/src/webidltopas.pp

@@ -1465,6 +1465,7 @@ Var
   I: Integer;
   I: Integer;
   CD: TIDLArgumentDefinition;
   CD: TIDLArgumentDefinition;
   DL: TIDLDefinitionList;
   DL: TIDLDefinitionList;
+  ODef : TIDLDefinition absolute posEl;
 
 
 begin
 begin
   For I:=0 to aList.Count-1 do
   For I:=0 to aList.Count-1 do
@@ -1473,8 +1474,13 @@ begin
     if Not (DL is TIDLPartialDefinitionList) then
     if Not (DL is TIDLPartialDefinitionList) then
       begin
       begin
       CD:=TIDLArgumentDefinition.Create(Nil,aName,PosEl.SrcFile,PosEl.Line,PosEl.Column);
       CD:=TIDLArgumentDefinition.Create(Nil,aName,PosEl.SrcFile,PosEl.Line,PosEl.Column);
-      CD.ArgumentType:=TIDLTypeDefDefinition.Create(CD,'',PosEl.SrcFile,PosEl.Line,PosEl.Column);
+      if PosEl is TIDLTypeDefDefinition then
+        CD.ArgumentType:=TIDLTypeDefDefinitionClass(Posel.ClassType).Create(CD,'',PosEl.SrcFile,PosEl.Line,PosEl.Column)
+      else
+        CD.ArgumentType:=TIDLTypeDefDefinition.Create(CD,'',PosEl.SrcFile,PosEl.Line,PosEl.Column);
       CD.ArgumentType.TypeName:=aTypeName;
       CD.ArgumentType.TypeName:=aTypeName;
+      if (PosEl is TIDLDefinition) and (ODef.Data is TPasData) then
+        CD.ArgumentType.Data:=ClonePasData(ODef.Data as TPasData,CD.ArgumentType);
       DL.Add(CD);
       DL.Add(CD);
       CD.Data:=CreatePasData(aPasName,CD,false);
       CD.Data:=CreatePasData(aPasName,CD,false);
       ResolveTypeDef(CD.ArgumentType);
       ResolveTypeDef(CD.ArgumentType);
@@ -2054,6 +2060,7 @@ begin
   else if D Is TIDLDictionaryDefinition then
   else if D Is TIDLDictionaryDefinition then
     ResolveTypeDefs(TIDLDictionaryDefinition(D).Members)
     ResolveTypeDefs(TIDLDictionaryDefinition(D).Members)
   else if D is TIDLIncludesDefinition then
   else if D is TIDLIncludesDefinition then
+    //
   else if D Is TIDLFunctionDefinition then
   else if D Is TIDLFunctionDefinition then
     begin
     begin
     FD:=TIDLFunctionDefinition(D);
     FD:=TIDLFunctionDefinition(D);
@@ -2092,9 +2099,11 @@ begin
     ResolveTypeDef(DMD.DefaultValue);
     ResolveTypeDef(DMD.DefaultValue);
     end
     end
   else if D is TIDLEnumDefinition then
   else if D is TIDLEnumDefinition then
+    //
   else if D is TIDLSetlikeDefinition then
   else if D is TIDLSetlikeDefinition then
     ResolveTypeDef(TIDLSetlikeDefinition(D).ElementType)
     ResolveTypeDef(TIDLSetlikeDefinition(D).ElementType)
   else if D is TIDLImplementsOrIncludesDefinition then
   else if D is TIDLImplementsOrIncludesDefinition then
+    //
   else if D is TIDLIterableDefinition then
   else if D is TIDLIterableDefinition then
     begin
     begin
     IT:=TIDLIterableDefinition(D);
     IT:=TIDLIterableDefinition(D);

+ 15 - 7
packages/webidl/tests/tcwebidl2wasmjob.pas

@@ -320,7 +320,7 @@ procedure TCustomTestWebIDL2WasmJob.OnLog(Sender: TObject;
 begin
 begin
   if LogType=cltInfo then ;
   if LogType=cltInfo then ;
   if Sender=nil then ;
   if Sender=nil then ;
-  writeln('TCustomTestWebIDL2WasmJob.OnLog ',Msg);
+  Status('TCustomTestWebIDL2WasmJob.OnLog '+Msg);
 end;
 end;
 
 
 procedure TCustomTestWebIDL2WasmJob.Setup;
 procedure TCustomTestWebIDL2WasmJob.Setup;
@@ -1460,7 +1460,7 @@ procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_NestedUnionSequence;
 begin
 begin
   TestWebIDL([
   TestWebIDL([
   'interface Attr {',
   'interface Attr {',
-  '  long roundRect((unrestricted double or DOMPointInit or sequence<(unrestricted double or DOMPointInit)>) radii);',
+  '  long roundRect((double or sequence<(double or long)>) radii);',
   '};',
   '};',
   ''],
   ''],
 [
 [
@@ -1474,23 +1474,31 @@ begin
  '    TJSAttr',
  '    TJSAttr',
  '    --------------------------------------------------------------------}',
  '    --------------------------------------------------------------------}',
  '',
  '',
+ '   TVariantDynArray = IJSArray; // array of Variant',
  '  IJSAttr = interface(IJSObject)',
  '  IJSAttr = interface(IJSObject)',
- '    [''{AA94F48A-2BFB-3877-82A6-208CA4B2AF2A}'']',
- '    function vibrate: IJSFloat32Array;',
+ '    [''{AA94F48A-0CA1-3A6F-A546-208CA4B2AF2A}'']',
+ '    function roundRect(aRadii: Double): Integer; overload;',
+ '    function roundRect(const aRadii: TVariantDynArray): Integer; overload;',
  '  end;',
  '  end;',
  '',
  '',
  '  TJSAttr = class(TJSObject,IJSAttr)',
  '  TJSAttr = class(TJSObject,IJSAttr)',
  '  Private',
  '  Private',
  '  Public',
  '  Public',
- '    function vibrate: IJSFloat32Array;',
+ '    function roundRect(aRadii: Double): Integer; overload;',
+ '    function roundRect(const aRadii: TVariantDynArray): Integer; overload;',
  '    class function Cast(const Intf: IJSObject): IJSAttr;',
  '    class function Cast(const Intf: IJSObject): IJSAttr;',
  '  end;',
  '  end;',
  '',
  '',
  'implementation',
  'implementation',
  '',
  '',
- 'function TJSAttr.vibrate: IJSFloat32Array;',
+ 'function TJSAttr.roundRect(aRadii: Double): Integer; overload;',
  'begin',
  'begin',
- '  Result:=InvokeJSObjectResult(''vibrate'',[],TJSArray) as IJSFloat32Array;',
+ '  Result:=InvokeJSLongIntResult(''roundRect'',[aRadii]);',
+ 'end;',
+ '',
+ 'function TJSAttr.roundRect(const aRadii: TVariantDynArray): Integer; overload;',
+ 'begin',
+ '  Result:=InvokeJSLongIntResult(''roundRect'',[aRadii]);',
  'end;',
  'end;',
  '',
  '',
  'class function TJSAttr.Cast(const Intf: IJSObject): IJSAttr;',
  'class function TJSAttr.Cast(const Intf: IJSObject): IJSAttr;',