Browse Source

webidl: parse stringifier;

mattias 3 years ago
parent
commit
d8196a6ffe

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

@@ -189,6 +189,7 @@ Type
   TIDLInterfaceDefinition = Class(TIDLStructuredDefinition)
   TIDLInterfaceDefinition = Class(TIDLStructuredDefinition)
   private
   private
     FHasSerializer: Boolean;
     FHasSerializer: Boolean;
+    FHasStringifier: Boolean;
     FIsInclude: Boolean;
     FIsInclude: Boolean;
     FIsMixin: Boolean;
     FIsMixin: Boolean;
     FParentInterface: TIDLInterfaceDefinition;
     FParentInterface: TIDLInterfaceDefinition;
@@ -196,6 +197,7 @@ Type
     Function AsString (aFull : Boolean) : UTF8String; override;
     Function AsString (aFull : Boolean) : UTF8String; override;
     Property ParentInterface : TIDLInterfaceDefinition Read FParentInterface Write FParentInterface;
     Property ParentInterface : TIDLInterfaceDefinition Read FParentInterface Write FParentInterface;
     Property HasSerializer : Boolean Read FHasSerializer Write FHasSerializer;
     Property HasSerializer : Boolean Read FHasSerializer Write FHasSerializer;
+    Property HasStringifier : Boolean Read FHasStringifier Write FHasStringifier;
     // is this a mixin definition?
     // is this a mixin definition?
     Property IsMixin : Boolean Read FIsMixin Write FIsMixin;
     Property IsMixin : Boolean Read FIsMixin Write FIsMixin;
     Property IsInclude : Boolean Read FIsInclude Write FIsInclude;
     Property IsInclude : Boolean Read FIsInclude Write FIsInclude;

+ 20 - 5
packages/webidl/src/webidlparser.pp

@@ -509,18 +509,27 @@ Var
 
 
 begin
 begin
   tk:=GetToken;
   tk:=GetToken;
-  if tk in [tkReadOnly,tkAttribute] then
+  case tk of
+  tkReadOnly,tkAttribute:
     begin
     begin
     Result:=ParseAttribute(aParent);
     Result:=ParseAttribute(aParent);
-    With TIDLAttributeDefinition(result) do
+    With TIDLAttributeDefinition(Result) do
       Options:=Options+[aoStringifier];
       Options:=Options+[aoStringifier];
-    end
+    end;
+  tkSemiColon:
+    begin
+    // stringifier;
+    Result:=TIDLAttributeDefinition(Context.Add(aParent,TIDLAttributeDefinition,''));
+    With TIDLAttributeDefinition(Result) do
+      Options:=Options+[aoStringifier];
+    end;
   else
   else
     begin
     begin
     Result:=ParseOperation(aParent);
     Result:=ParseOperation(aParent);
-    With TIDLFunctionDefinition(result) do
+    With TIDLFunctionDefinition(Result) do
       Options:=Options+[foStringifier];
       Options:=Options+[foStringifier];
     end;
     end;
+  end;
 end;
 end;
 
 
 function TWebIDLParser.ParseIterable(aParent: TIDLBaseObject): TIDLIterableDefinition;
 function TWebIDLParser.ParseIterable(aParent: TIDLBaseObject): TIDLIterableDefinition;
@@ -936,7 +945,13 @@ begin
           Result.HasSerializer:=True;
           Result.HasSerializer:=True;
           SemicolonSeen:=M=Nil;
           SemicolonSeen:=M=Nil;
           end;
           end;
-        tkStringifier : M:=ParseStringifier(Result.Members);
+        tkStringifier :
+          begin
+          M:=ParseStringifier(Result.Members);
+          Result.HasStringifier:=true;
+          if CurrentToken=tkSemiColon then
+            SemicolonSeen:=true;
+          end;
         tkIterable : ParseIterable(Result.Members);
         tkIterable : ParseIterable(Result.Members);
       else
       else
         {
         {

+ 14 - 0
packages/webidl/tests/tcidlparser.pp

@@ -186,6 +186,7 @@ Type
     Procedure ParseSimpleAttributeLegacyNullToEmptyString;
     Procedure ParseSimpleAttributeLegacyNullToEmptyString;
     Procedure ParseSimpleStaticAttribute;
     Procedure ParseSimpleStaticAttribute;
     Procedure ParseSimpleStringifierAttribute;
     Procedure ParseSimpleStringifierAttribute;
+    Procedure ParseStringifierNoAttribute;
     Procedure ParseSimpleReadonlyAttribute;
     Procedure ParseSimpleReadonlyAttribute;
     Procedure ParseSimpleInheritedAttribute;
     Procedure ParseSimpleInheritedAttribute;
     Procedure ParseSimpleReadonlyInheritedAttribute;
     Procedure ParseSimpleReadonlyInheritedAttribute;
@@ -667,6 +668,19 @@ begin
   ParseAttribute('stringifier attribute short A','A','short',[aoStringifier]);
   ParseAttribute('stringifier attribute short A','A','short',[aoStringifier]);
 end;
 end;
 
 
+procedure TTestAttributeInterfaceParser.ParseStringifierNoAttribute;
+var
+  Id: TIDLInterfaceDefinition;
+  Def: TIDLAttributeDefinition;
+begin
+  Id:=ParseInterFace('IA','',['stringifier']);
+  AssertEquals('Correct class',TIDLAttributeDefinition,Id.Members[0].ClassType);
+  Def:=Id.Members[0] as TIDLAttributeDefinition;
+  AssertEquals('Attr name','',Def.Name);
+  AssertNull('Have type',Def.AttributeType);
+  AssertEquals('Attr options',[aoStringifier],Def.Options);
+end;
+
 procedure TTestAttributeInterfaceParser.ParseSimpleReadonlyAttribute;
 procedure TTestAttributeInterfaceParser.ParseSimpleReadonlyAttribute;
 begin
 begin
   ParseAttribute('readonly attribute short A','A','short',[aoReadOnly]);
   ParseAttribute('readonly attribute short A','A','short',[aoReadOnly]);