Browse Source

webidl: parse [LegacyNullToEmptyString] DOMString

mattias 3 years ago
parent
commit
82bfe6cf0d
2 changed files with 28 additions and 8 deletions
  1. 22 7
      packages/webidl/src/webidlparser.pp
  2. 6 1
      packages/webidl/tests/tcidlparser.pp

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

@@ -207,7 +207,7 @@ end;
 procedure TWebIDLParser.CheckCurrentToken(aToken: TIDLToken);
 begin
   if (aToken<>CurrentToken) then
-    Error(SErrInvalidToken,[GetTokenName(aToken),CurrenttokenString]);
+    Error(SErrInvalidToken,[GetTokenName(aToken),CurrentTokenString]);
 end;
 
 procedure TWebIDLParser.CheckCurrentTokens(aTokens: TIDLTokens);
@@ -1190,6 +1190,7 @@ Const
   SimpleTypeTokens = PrimitiveTokens+IdentifierTokens;
   TypeTokens = PrefixTokens+SimpleTypeTokens;
   ExtraTypeTokens = TypeTokens +[tkStringToken,tkVoid];
+  LegacyDOMString = 'LegacyNullToEmptyString';
 
 Var
   isNull , ok: Boolean;
@@ -1198,10 +1199,6 @@ Var
   tk : TIDLToken;
 
 begin
-  if AllowExtraTypes then
-    Allowed:=ExtraTypeTokens
-  else
-    Allowed:=TypeTokens;
   Result:=Nil;
   ok:=false;
   try
@@ -1210,6 +1207,25 @@ begin
       tk:=GetToken
     else
       tk:=CurrentToken;
+    if tk=tkSquaredBraceOpen then
+      begin
+      // special: [LegacyNullToEmptyString] DOMString
+      ExpectToken(tkIdentifier);
+      if CurrentTokenString<>LegacyDOMString then
+        Error(SErrInvalidToken,[LegacyDOMString,CurrentTokenString]);
+      ExpectToken(tkSquaredBraceClose);
+      ExpectToken(tkDOMString);
+      Result:=TIDLTypeDefDefinition(Context.Add(aParent,TIDLTypeDefDefinition,''));
+      Result.TypeName:='DOMString';
+      Result.Attributes.Add(LegacyDOMString);
+      GetToken;
+      ok:=true;
+      exit;
+      end;
+    if AllowExtraTypes then
+      Allowed:=ExtraTypeTokens
+    else
+      Allowed:=TypeTokens;
     CheckCurrentTokens(Allowed);
     TypeName:=CurrentTokenString;
     if (tk in SimplePrefixTokens) then
@@ -1238,8 +1254,7 @@ begin
       tk:=GetToken;
       isNull:=True;
       end;
-    if Assigned(Result) then
-      Result.AllowNull:=isNull;
+    Result.AllowNull:=isNull;
     ok:=true;
   finally
     if not ok then

+ 6 - 1
packages/webidl/tests/tcidlparser.pp

@@ -183,6 +183,7 @@ Type
   Published
     Procedure ParseSimpleAttribute;
     Procedure ParseSimpleAttributeWithExtendedAttrs;
+    Procedure ParseSimpleAttributeLegacyNullToEmptyString;
     Procedure ParseSimpleStaticAttribute;
     Procedure ParseSimpleStringifierAttribute;
     Procedure ParseSimpleReadonlyAttribute;
@@ -636,6 +637,11 @@ begin
   AssertTrue('Have attribute',ParseAttribute('[Me] attribute short A','A','short',[]).HasSimpleAttribute('Me'));
 end;
 
+procedure TTestAttributeInterfaceParser.ParseSimpleAttributeLegacyNullToEmptyString;
+begin
+  ParseAttribute('attribute [LegacyNullToEmptyString] DOMString A','A','DOMString',[]);
+end;
+
 procedure TTestAttributeInterfaceParser.ParseSimpleStaticAttribute;
 begin
   ParseAttribute('static attribute short A','A','short',[aoStatic]);
@@ -649,7 +655,6 @@ end;
 procedure TTestAttributeInterfaceParser.ParseSimpleReadonlyAttribute;
 begin
   ParseAttribute('readonly attribute short A','A','short',[aoReadOnly]);
-
 end;
 
 procedure TTestAttributeInterfaceParser.ParseSimpleInheritedAttribute;