Browse Source

* Do not generate code for types that are used in a ignored definiton

Michaël Van Canneyt 1 year ago
parent
commit
70b2f29b92
2 changed files with 43 additions and 0 deletions
  1. 2 0
      packages/webidl/src/webidltopas.pp
  2. 41 0
      packages/webidl/tests/tcwebidl2wasmjob.pas

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

@@ -2022,6 +2022,8 @@ var
   FD: TIDLFunctionDefinition;
 begin
   if D=nil then exit;
+  if not ConvertDef(D) then
+    exit;
   //writeln('TBaseWebIDLToPas.ResolveTypeDef START ',D.Name,':',D.ClassName,' at ',GetDefPos(D),' D=',hexstr(ptruint(D),sizeof(ptruint)*2));
   if D Is TIDLInterfaceDefinition then
     ResolveTypeDefs(TIDLInterfaceDefinition(D).Members)

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

@@ -61,6 +61,7 @@ type
     procedure TestWJ_IntfFunction_SequenceResult;
     procedure TestWJ_IntfFunction_GlobalSequenceResult;
     procedure TestWJ_IntfFunction_ChromeOnly;
+    procedure TestWJ_IntfFunction_ChromeOnlyNewObject;
     // Namespace attribute
     procedure TestWJ_NamespaceAttribute_Boolean;
     // maplike
@@ -1306,6 +1307,46 @@ begin
   ]);
 end;
 
+procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_ChromeOnlyNewObject;
+begin
+
+    TestWebIDL([
+    'interface Attr {',
+    '  [ChromeOnly, NewObject] ',
+    '  ConsoleInstance createInstance(optional ConsoleInstanceOptions options = {});',
+    '};'
+    ],
+    [
+    'Type',
+      '  // Forward class definitions',
+      '  IJSAttr = interface;',
+      '  TJSAttr = class;',
+      '  { --------------------------------------------------------------------',
+      '    TJSAttr',
+      '    --------------------------------------------------------------------}',
+      '',
+      '  IJSAttr = interface(IJSObject)',
+      '    [''{AA94F48A-9540-32B7-B05B-E99EB8B2AF2A}'']',
+      '  end;',
+      '',
+      '  TJSAttr = class(TJSObject,IJSAttr)',
+      '  Private',
+      '  Public',
+      '    class function Cast(const Intf: IJSObject): IJSAttr;',
+      '  end;',
+      '',
+      'implementation',
+      '',
+      'class function TJSAttr.Cast(const Intf: IJSObject): IJSAttr;',
+      'begin',
+      '  Result:=TJSAttr.JOBCast(Intf);',
+      'end;',
+      '',
+      'end.',
+      ''
+    ]);
+end;
+
 
 procedure TTestWebIDL2WasmJob.TestWJ_NamespaceAttribute_Boolean;
 begin