Title: [290780] trunk/Source/WebCore
Revision
290780
Author
[email protected]
Date
2022-03-03 09:25:38 -0800 (Thu, 03 Mar 2022)

Log Message

Update IDLParser to support trailing commas in enums.
https://bugs.webkit.org/show_bug.cgi?id=232607
<rdar://problem/85189036>

Patch by Dan Glastonbury <[email protected]> on 2022-03-03
Reviewed by Sam Weinig.

Now compatible with the grammar specified by [1].

[1] https://webidl.spec.whatwg.org/#prod-EnumValueListComma

* bindings/scripts/IDLParser.pm:
(parseEnumValues):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::convertEnumerationToString):
(WebCore::convertEnumerationToJS):
(WebCore::parseEnumeration<TestObj::EnumTrailingComma>):
(WebCore::expectedEnumerationValues<TestObj::EnumTrailingComma>):
* bindings/scripts/test/JS/JSTestObj.h:
* bindings/scripts/test/TestObj.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290779 => 290780)


--- trunk/Source/WebCore/ChangeLog	2022-03-03 17:24:15 UTC (rev 290779)
+++ trunk/Source/WebCore/ChangeLog	2022-03-03 17:25:38 UTC (rev 290780)
@@ -1,3 +1,25 @@
+2022-03-03  Dan Glastonbury  <[email protected]>
+
+        Update IDLParser to support trailing commas in enums.
+        https://bugs.webkit.org/show_bug.cgi?id=232607
+        <rdar://problem/85189036>
+
+        Reviewed by Sam Weinig.
+
+        Now compatible with the grammar specified by [1].
+
+        [1] https://webidl.spec.whatwg.org/#prod-EnumValueListComma
+
+        * bindings/scripts/IDLParser.pm:
+        (parseEnumValues):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::convertEnumerationToString):
+        (WebCore::convertEnumerationToJS):
+        (WebCore::parseEnumeration<TestObj::EnumTrailingComma>):
+        (WebCore::expectedEnumerationValues<TestObj::EnumTrailingComma>):
+        * bindings/scripts/test/JS/JSTestObj.h:
+        * bindings/scripts/test/TestObj.idl:
+
 2022-03-03  Antti Koivisto  <[email protected]>
 
         Simplify pseudo element resolution

Modified: trunk/Source/WebCore/bindings/scripts/IDLParser.pm (290779 => 290780)


--- trunk/Source/WebCore/bindings/scripts/IDLParser.pm	2022-03-03 17:24:15 UTC (rev 290779)
+++ trunk/Source/WebCore/bindings/scripts/IDLParser.pm	2022-03-03 17:25:38 UTC (rev 290780)
@@ -1507,6 +1507,9 @@
     my $next = $self->nextToken();
     if ($next->value() eq ",") {
         $self->assertTokenValue($self->getToken(), ",", __LINE__);
+    }
+    $next = $self->nextToken();
+    if ($next->type() == StringToken) {
         my $enumValueToken = $self->getToken();
         $self->assertTokenType($enumValueToken, StringToken);
         my $enumValue = $self->unquoteString($enumValueToken->value());

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (290779 => 290780)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2022-03-03 17:24:15 UTC (rev 290779)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2022-03-03 17:25:38 UTC (rev 290780)
@@ -165,6 +165,38 @@
     return "\"\", \"enumValue1\", \"EnumValue2\", \"EnumValue3\"";
 }
 
+String convertEnumerationToString(TestObj::EnumTrailingComma enumerationValue)
+{
+    static const NeverDestroyed<String> values[] = {
+        MAKE_STATIC_STRING_IMPL("enumValue1"),
+        MAKE_STATIC_STRING_IMPL("enumValue2"),
+    };
+    static_assert(static_cast<size_t>(TestObj::EnumTrailingComma::EnumValue1) == 0, "TestObj::EnumTrailingComma::EnumValue1 is not 0 as expected");
+    static_assert(static_cast<size_t>(TestObj::EnumTrailingComma::EnumValue2) == 1, "TestObj::EnumTrailingComma::EnumValue2 is not 1 as expected");
+    ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
+    return values[static_cast<size_t>(enumerationValue)];
+}
+
+template<> JSString* convertEnumerationToJS(JSGlobalObject& lexicalGlobalObject, TestObj::EnumTrailingComma enumerationValue)
+{
+    return jsStringWithCache(lexicalGlobalObject.vm(), convertEnumerationToString(enumerationValue));
+}
+
+template<> std::optional<TestObj::EnumTrailingComma> parseEnumeration<TestObj::EnumTrailingComma>(JSGlobalObject& lexicalGlobalObject, JSValue value)
+{
+    auto stringValue = value.toWTFString(&lexicalGlobalObject);
+    if (stringValue == "enumValue1")
+        return TestObj::EnumTrailingComma::EnumValue1;
+    if (stringValue == "enumValue2")
+        return TestObj::EnumTrailingComma::EnumValue2;
+    return std::nullopt;
+}
+
+template<> const char* expectedEnumerationValues<TestObj::EnumTrailingComma>()
+{
+    return "\"enumValue1\", \"enumValue2\"";
+}
+
 String convertEnumerationToString(TestObj::Optional enumerationValue)
 {
     static const NeverDestroyed<String> values[] = {

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.h (290779 => 290780)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.h	2022-03-03 17:24:15 UTC (rev 290779)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.h	2022-03-03 17:25:38 UTC (rev 290780)
@@ -121,6 +121,12 @@
 template<> std::optional<TestObj::EnumType> parseEnumeration<TestObj::EnumType>(JSC::JSGlobalObject&, JSC::JSValue);
 template<> const char* expectedEnumerationValues<TestObj::EnumType>();
 
+String convertEnumerationToString(TestObj::EnumTrailingComma);
+template<> JSC::JSString* convertEnumerationToJS(JSC::JSGlobalObject&, TestObj::EnumTrailingComma);
+
+template<> std::optional<TestObj::EnumTrailingComma> parseEnumeration<TestObj::EnumTrailingComma>(JSC::JSGlobalObject&, JSC::JSValue);
+template<> const char* expectedEnumerationValues<TestObj::EnumTrailingComma>();
+
 String convertEnumerationToString(TestObj::Optional);
 template<> JSC::JSString* convertEnumerationToJS(JSC::JSGlobalObject&, TestObj::Optional);
 

Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (290779 => 290780)


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2022-03-03 17:24:15 UTC (rev 290779)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2022-03-03 17:25:38 UTC (rev 290780)
@@ -31,6 +31,7 @@
 // changes in its output.
 
 enum TestEnumType { "", "enumValue1", "EnumValue2", "EnumValue3" };
+enum TestEnumTrailingComma { "enumValue1", "enumValue2", };
 
 // Leading underscore on an enum should be removed.
 enum _optional { "", "OptionalValue1", "OptionalValue2", "OptionalValue3" };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to