Browse Source

* Fix stringifier

Michaël Van Canneyt 1 year ago
parent
commit
38dac868e0

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

@@ -310,10 +310,11 @@ end;
 function TBaseWebIDLToPas.GetName(ADef: TIDLDefinition): String;
 
 begin
-  If Assigned(ADef) and (ADef.Data is TPasData) then
-    Result:=TPasData(ADef.Data).PasName
-  else
-    Result:=ADef.Name;
+  If Assigned(ADef) then
+    if (ADef.Data is TPasData) then
+      Result:=TPasData(ADef.Data).PasName
+    else
+      Result:=ADef.Name;
 end;
 
 function TBaseWebIDLToPas.GetPasClassName(const aName: string): string;

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

@@ -1075,11 +1075,17 @@ var
 
 begin
   aClassName:=GetName(aParent);
+  // case
+  // stringifier ;
+  // is equivalent to toString : DOMString
+  // no n
+  if (Attr.Name='') and (aoStringifier in Attr.Options) then
+    Exit;
+  if Attr.AttributeType=nil then
+    Exit;
 
   AttrType:=GetPrivateGetterInfo(Attr,AttrTypeName,AttrResolvedTypeName,FuncName);
-
   Call:=GetReadPropertyCall(AttrResolvedTypeName, AttrTypeName, Attr.Name, AttrType);
-
   Addln('function '+aClassName+'.'+FuncName+': '+AttrTypeName+';');
   Addln('begin');
   Addln('  Result:='+Call+';');
@@ -1095,6 +1101,8 @@ var
 
 begin
   Result:=true;
+  if (Attr.Name='') and (aoStringifier in Attr.Options) then
+    Exit;
   if Attr.AttributeType=nil then
     exit;
   AttrType:=GetPrivateGetterInfo(Attr,AttrTypeName,AttrResolvedTypeName,FuncName);
@@ -1105,6 +1113,8 @@ function TWebIDLToPasWasmJob.GetPrivateSetterInfo(Attr: TIDLAttributeDefinition;
 
 begin
   Result:=nil;
+  if (Attr.Name='') and (aoStringifier in Attr.Options) then
+    Exit;
   if Attr.AttributeType=nil then
     exit;
   FuncName:=SetterPrefix+GetName(Attr);

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

@@ -39,6 +39,7 @@ type
 
     // attributes
     procedure TestWJ_IntfAttribute_Boolean;
+    procedure TestWJ_IntfStringifier;
     // todo procedure TestWJ_IntfAttribute_Any;
 
     // functions
@@ -478,6 +479,43 @@ begin
   '']);
 end;
 
+procedure TTestWebIDL2WasmJob.TestWJ_IntfStringifier;
+begin
+  TestWebIDL([
+  'interface Attr {',
+  '  stringifier;',
+  '};',
+  ''],
+  ['Type',
+  '  // Forward class definitions',
+  '  IJSAttr = interface;',
+  '  TJSAttr = class;',
+  '  { --------------------------------------------------------------------',
+  '    TJSAttr',
+  '    --------------------------------------------------------------------}',
+  '',
+  '  IJSAttr = interface(IJSObject)',
+  '    [''{AA94F45E-60F0-381A-A2A6-208CA4B2AF2A}'']',
+  '  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_IntfFunction_Void;
 begin
   TestWebIDL([

+ 3 - 5
packages/webidl/tests/testidl.lpi

@@ -22,13 +22,13 @@
     </PublishOptions>
     <RunParams>
       <local>
-        <CommandLineParams Value="--suite=TTestMapLikeInterfaceParser"/>
+        <CommandLineParams Value="--suite=TTestWebIDL2WasmJob.TestWJ_IntfStringifier"/>
       </local>
       <FormatVersion Value="2"/>
       <Modes Count="1">
         <Mode0 Name="default">
           <local>
-            <CommandLineParams Value="--suite=TTestMapLikeInterfaceParser"/>
+            <CommandLineParams Value="--suite=TTestWebIDL2WasmJob.TestWJ_IntfStringifier"/>
           </local>
         </Mode0>
       </Modes>
@@ -89,6 +89,7 @@
     </CodeGeneration>
     <Linking>
       <Debugging>
+        <DebugInfoType Value="dsDwarf3"/>
         <TrashVariables Value="True"/>
       </Debugging>
       <Options>
@@ -97,9 +98,6 @@
         </Win32>
       </Options>
     </Linking>
-    <Other>
-      <CustomOptions Value="-tunicodertl"/>
-    </Other>
   </CompilerOptions>
   <Debugging>
     <Exceptions Count="3">