Browse Source

* Sequence result support

Michaël Van Canneyt 1 year ago
parent
commit
dc7130d078
2 changed files with 54 additions and 1 deletions
  1. 4 1
      packages/webidl/src/webidltopas.pp
  2. 50 0
      packages/webidl/tests/tcwebidl2wasmjob.pas

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

@@ -1876,7 +1876,10 @@ begin
     CN:=GetTypeName(TIDLSequenceTypeDefDefinition(D));
     CN:=GetTypeName(TIDLSequenceTypeDefDefinition(D));
     sDef:=FindGlobalDef(CN);
     sDef:=FindGlobalDef(CN);
     if (SDef=Nil) or (sDef.Data=Nil) then
     if (SDef=Nil) or (sDef.Data=Nil) then
-      Result:=CreatePasData(EscapeKeyWord(CN),D,true)
+      begin
+      Result:=CreatePasData(EscapeKeyWord(CN),D,true);
+      AddJSIdentifier(D);
+      end
     else
     else
       Result:=ClonePasData(TPasData(sDef.Data),D);
       Result:=ClonePasData(TPasData(sDef.Data),D);
     D.Data:=Result;
     D.Data:=Result;

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

@@ -58,6 +58,7 @@ type
     procedure TestWJ_IntfFunction_ArrayBufferArg;
     procedure TestWJ_IntfFunction_ArrayBufferArg;
     procedure TestWJ_IntfFunction_ArrayBufferViewArg;
     procedure TestWJ_IntfFunction_ArrayBufferViewArg;
     procedure TestWJ_IntfFunction_SequenceResult;
     procedure TestWJ_IntfFunction_SequenceResult;
+    procedure TestWJ_IntfFunction_GlobalSequenceResult;
     // Namespace attribute
     // Namespace attribute
     procedure TestWJ_NamespaceAttribute_Boolean;
     procedure TestWJ_NamespaceAttribute_Boolean;
     // maplike
     // maplike
@@ -1177,6 +1178,55 @@ begin
     ]);
     ]);
 end;
 end;
 
 
+procedure TTestWebIDL2WasmJob.TestWJ_IntfFunction_GlobalSequenceResult;
+begin
+  TestWebIDL([
+  'typedef sequence <long> LongSeq;',
+  'interface Attr {',
+  '  LongSeq vibrate();',
+  '};',
+  ''],
+  [
+   'Type',
+   '',
+   '  // Forward class definitions',
+   '  IJSAttr = interface;',
+   '  TJSAttr = class;',
+   '  TIntegerDynArray = IJSArray; // array of Integer',
+   '',
+   '  { --------------------------------------------------------------------',
+   '    TJSAttr',
+   '    --------------------------------------------------------------------}',
+   '',
+   '  IJSAttr = interface(IJSObject)',
+   '    [''{AA94F48A-2BFB-3877-82A6-208CA4B2AF2A}'']',
+   '    function vibrate: TIntegerDynArray;',
+   '  end;',
+   '',
+   '  TJSAttr = class(TJSObject,IJSAttr)',
+   '  Private',
+   '  Public',
+   '    function vibrate: TIntegerDynArray;',
+   '    class function Cast(const Intf: IJSObject): IJSAttr;',
+   '  end;',
+   '',
+   'implementation',
+   '',
+   'function TJSAttr.vibrate: TIntegerDynArray;',
+   'begin',
+   '  Result:=InvokeJSObjectResult(''vibrate'',[],TJSArray) as TIntegerDynArray;',
+   'end;',
+   '',
+   'class function TJSAttr.Cast(const Intf: IJSObject): IJSAttr;',
+   'begin',
+   '  Result:=TJSAttr.JOBCast(Intf);',
+   'end;',
+   '',
+   'end.'
+ ]);
+
+end;
+
 
 
 procedure TTestWebIDL2WasmJob.TestWJ_NamespaceAttribute_Boolean;
 procedure TTestWebIDL2WasmJob.TestWJ_NamespaceAttribute_Boolean;
 begin
 begin