Browse Source

webidl: fixed parsing optional attributes

mattias 3 years ago
parent
commit
5446a3afec

+ 7 - 7
packages/webidl/src/webidlparser.pp

@@ -345,16 +345,16 @@ begin
   Result:=TIDLArgumentDefinition(Context.Add(aParent,TIDLArgumentDefinition,''));
   ok:=false;
   try
-    if (CurrentToken=tkSquaredBraceOpen) then
-      begin
-      Result.Attributes:=ParseAttributes;
-      getToken;
-      end;
     if CurrentToken=tkOptional then
       begin
       Result.isOptional:=True;
       GetToken;
       end;
+    if (CurrentToken=tkSquaredBraceOpen) then
+      begin
+      Result.Attributes:=ParseAttributes;
+      GetToken;
+      end;
     Result.ArgumentType:=ParseType(Result,False);
     if CurrentToken=tkEllipsis then
       begin
@@ -495,7 +495,7 @@ Var
   tk : TIDLToken;
 
 begin
-  tk:=getToken;
+  tk:=GetToken;
   if tk in [tkReadOnly,tkAttribute] then
     begin
     Result:=ParseAttribute(aParent);
@@ -1132,7 +1132,7 @@ begin
       if Tk=tkSquaredBraceOpen then
         begin
         Attr:=ParseAttributes;
-        tk:=getToken;
+        tk:=GetToken;
         end;
       D:=ParseType(Result.Union,False);
       D.Attributes:=Attr;

+ 13 - 3
packages/webidl/tests/tcidlparser.pp

@@ -229,6 +229,7 @@ Type
     Procedure TestSimpleDeleterFunction;
     Procedure TestAttrFunctionFunction;
     Procedure TestOptionalDefaultArgFunction;
+    Procedure TestFunction_ClampArg;
   end;
 
   { TTestDictionaryParser }
@@ -459,7 +460,6 @@ end;
 procedure TTestOperationInterfaceParser.TestSimpleGetterFunction;
 begin
   AssertEquals('Options',[foGetter],ParseFunction('getter short A()','A','short',[]).Options);
-
 end;
 
 procedure TTestOperationInterfaceParser.TestSimpleSetterFunction;
@@ -487,6 +487,16 @@ begin
   ParseFunction('void A(optional short me = 0,optional short you = 0)','A','void',['short','me','short','you'])
 end;
 
+procedure TTestOperationInterfaceParser.TestFunction_ClampArg;
+var
+  F: TIDLFunctionDefinition;
+  Arg: TIDLDefinition;
+begin
+  F:=ParseFunction('void A(optional [Clamp] long long start)','A','void',['long long','start']);
+  Arg:=F.Arguments[0];
+  AssertEquals('optional arg is Clamp',true,Arg.HasSimpleAttribute('Clamp'));
+end;
+
 { TTestSerializerInterfaceParser }
 
 function TTestSerializerInterfaceParser.ParseSerializer(ADef: UTF8String; Attrs: array of UTF8String): TIDLSerializerDefinition;
@@ -800,7 +810,7 @@ end;
 
 procedure TTestFunctionCallbackParser.ParseOneOptionalArgumentWithAttrsReturnVoid;
 begin
-  ParseCallback('A','void',['[Me] optional unsigned long long','A']);
+  ParseCallback('A','void',['optional [Me] unsigned long long','A']);
   AssertTrue('is optional',Func.Argument[0].IsOptional);
   AssertEquals('Type name','unsigned long long',Func.Argument[0].ArgumentType.TypeName);
   AssertTrue('Have attribute',Func.Arguments[0].HasSimpleAttribute('Me'));
@@ -820,7 +830,7 @@ end;
 
 procedure TTestFunctionCallbackParser.ParseThreeArgumentsAttrsReturnVoid;
 begin
-  ParseCallback('A','void',['[Me] short','B','[Me] short','C','[Me] optional unsigned long long','D']);
+  ParseCallback('A','void',['[Me] short','B','[Me] short','C','optional [Me] unsigned long long','D']);
   AssertTrue('Have attribute',Func.Arguments[0].HasSimpleAttribute('Me'));
   AssertTrue('Have attribute',Func.Arguments[1].HasSimpleAttribute('Me'));
   AssertTrue('Have attribute',Func.Arguments[2].HasSimpleAttribute('Me'));

+ 0 - 1
utils/pas2js/webidl2pas.lpi

@@ -4,7 +4,6 @@
     <Version Value="12"/>
     <General>
       <Flags>
-        <SaveOnlyProjectUnits Value="True"/>
         <MainUnitHasCreateFormStatements Value="False"/>
         <MainUnitHasTitleStatement Value="False"/>
         <MainUnitHasScaledStatement Value="False"/>