Browse Source

webidl: pass variant args as const

mattias 2 years ago
parent
commit
73185e89e1
2 changed files with 45 additions and 0 deletions
  1. 1 0
      packages/webidl/src/webidltopas.pp
  2. 44 0
      packages/webidl/tests/tcwebidl2wasmjob.pas

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

@@ -1142,6 +1142,7 @@ begin
     if (ArgType is TIDLFunctionDefinition)
         or (ArgType is TIDLDictionaryDefinition)
         or (ArgType is TIDLSequenceTypeDefDefinition)
+        or (ArgResolvedTypeName='Variant')
         or (ArgResolvedTypeName='UnicodeString')
         or (ArgResolvedTypeName='UTF8String') then
       ArgName:='const '+ArgName;

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

@@ -45,6 +45,7 @@ type
     procedure TestWJ_IntfFunction_Void;
     procedure TestWJ_IntfFunction_SetEventHandler;
     procedure TestWJ_IntfFunction_Promise;
+    procedure TestWJ_IntfFunction_ArgAny;
   end;
 
 function LinesToStr(Args: array of const): string;
@@ -627,6 +628,49 @@ begin
   '']);
 end;
 
+procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_ArgAny;
+begin
+  TestWebIDL([
+  'interface Attr {',
+  '  void append(any node);',
+  '};',
+  ''],
+  ['Type',
+  '  // Forward class definitions',
+  '  IJSAttr = interface;',
+  '  TJSAttr = class;',
+  '  { --------------------------------------------------------------------',
+  '    TJSAttr',
+  '    --------------------------------------------------------------------}',
+  '',
+  '  IJSAttr = interface(IJSObject)',
+  '    [''{AA94F48A-84D7-3FAA-A2A6-208CA4B2AF2A}'']',
+  '    procedure append(const aNode: Variant);',
+  '  end;',
+  '',
+  '  TJSAttr = class(TJSObject,IJSAttr)',
+  '  Private',
+  '  Public',
+  '    procedure append(const aNode: Variant);',
+  '    class function Cast(Intf: IJSObject): IJSAttr;',
+  '  end;',
+  '',
+  'implementation',
+  '',
+  'procedure TJSAttr.append(const aNode: Variant);',
+  'begin',
+  '  InvokeJSNoResult(''append'',[aNode]);',
+  'end;',
+  '',
+  'class function TJSAttr.Cast(Intf: IJSObject): IJSAttr;',
+  'begin',
+  '  Result:=TJSAttr.JOBCast(Intf);',
+  'end;',
+  '',
+  'end.',
+  '']);
+end;
+
 initialization
   RegisterTests([TTestWebIDL2Wasmjob]);