<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[207768] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/207768">207768</a></dd>
<dt>Author</dt> <dd>zandobersek@gmail.com</dd>
<dt>Date</dt> <dd>2016-10-24 11:24:12 -0700 (Mon, 24 Oct 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[CodeGeneratorJS] Support enums for standalone dictionaries
https://bugs.webkit.org/show_bug.cgi?id=163885
Reviewed by Youenn Fablet.
Add support for enumerations in WebIDL files that specify
standalone dictionaries. Implementation of this is pretty
straight-forward and mirrors interface and callback generators
by calling GenerateEnumerations{Header,Implementation}Content()
functions in GenerateDictionary{Header,Implementation}().
In GenerateEnumerationsImplementationContent(), the
NeverDestroyed.h header is added to the implementation includes
since that class is used to hold an array of possible enum
values.
A test enum is added to the TestStandaloneDictionary.idl file
and the baselines are updated to reflect the new capability.
* bindings/scripts/CodeGenerator.pm:
(ProcessDocument):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateDictionary):
(GenerateEnumerationsImplementationContent):
(GenerateDictionaryHeader):
(GenerateDictionaryImplementation):
* bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp:
(WebCore::convertEnumerationToJS):
(WebCore::parseEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>):
(WebCore::convertEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>):
(WebCore::expectedEnumerationValues<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>):
(WebCore::convertDictionary<DictionaryImplName>):
* bindings/scripts/test/JS/JSTestStandaloneDictionary.h:
* bindings/scripts/test/TestStandaloneDictionary.idl:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptsCodeGeneratorpm">trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm">trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestJSJSTestStandaloneDictionarycpp">trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestJSJSTestStandaloneDictionaryh">trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.h</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestTestStandaloneDictionaryidl">trunk/Source/WebCore/bindings/scripts/test/TestStandaloneDictionary.idl</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (207767 => 207768)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-24 18:18:09 UTC (rev 207767)
+++ trunk/Source/WebCore/ChangeLog        2016-10-24 18:24:12 UTC (rev 207768)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-10-24 Zan Dobersek <zdobersek@igalia.com>
+
+ [CodeGeneratorJS] Support enums for standalone dictionaries
+ https://bugs.webkit.org/show_bug.cgi?id=163885
+
+ Reviewed by Youenn Fablet.
+
+ Add support for enumerations in WebIDL files that specify
+ standalone dictionaries. Implementation of this is pretty
+ straight-forward and mirrors interface and callback generators
+ by calling GenerateEnumerations{Header,Implementation}Content()
+ functions in GenerateDictionary{Header,Implementation}().
+
+ In GenerateEnumerationsImplementationContent(), the
+ NeverDestroyed.h header is added to the implementation includes
+ since that class is used to hold an array of possible enum
+ values.
+
+ A test enum is added to the TestStandaloneDictionary.idl file
+ and the baselines are updated to reflect the new capability.
+
+ * bindings/scripts/CodeGenerator.pm:
+ (ProcessDocument):
+ * bindings/scripts/CodeGeneratorJS.pm:
+ (GenerateDictionary):
+ (GenerateEnumerationsImplementationContent):
+ (GenerateDictionaryHeader):
+ (GenerateDictionaryImplementation):
+ * bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp:
+ (WebCore::convertEnumerationToJS):
+ (WebCore::parseEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>):
+ (WebCore::convertEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>):
+ (WebCore::expectedEnumerationValues<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>):
+ (WebCore::convertDictionary<DictionaryImplName>):
+ * bindings/scripts/test/JS/JSTestStandaloneDictionary.h:
+ * bindings/scripts/test/TestStandaloneDictionary.idl:
+
</ins><span class="cx"> 2016-10-24 Dave Hyatt <hyatt@apple.com>
</span><span class="cx">
</span><span class="cx"> Remove CSSCharsetRule from the CSS OM
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptsCodeGeneratorpm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm (207767 => 207768)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm        2016-10-24 18:18:09 UTC (rev 207767)
+++ trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm        2016-10-24 18:24:12 UTC (rev 207768)
</span><span class="lines">@@ -216,7 +216,7 @@
</span><span class="cx"> # It is possible to have dictionaries in an IDL file without any interface.
</span><span class="cx"> unless (@$interfaces) {
</span><span class="cx"> foreach my $dictionary (@{$useDocument->dictionaries}) {
</span><del>- $codeGenerator->GenerateDictionary($dictionary);
</del><ins>+ $codeGenerator->GenerateDictionary($dictionary, $useDocument->enumerations);
</ins><span class="cx"> $codeGenerator->WriteData($dictionary, $useOutputDir, $useOutputHeadersDir);
</span><span class="cx"> }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (207767 => 207768)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm        2016-10-24 18:18:09 UTC (rev 207767)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm        2016-10-24 18:24:12 UTC (rev 207768)
</span><span class="lines">@@ -134,11 +134,11 @@
</span><span class="cx">
</span><span class="cx"> sub GenerateDictionary
</span><span class="cx"> {
</span><del>- my ($object, $dictionary) = @_;
</del><ins>+ my ($object, $dictionary, $enumerations) = @_;
</ins><span class="cx">
</span><span class="cx"> my $className = GetDictionaryClassName($dictionary->name);
</span><del>- $object->GenerateDictionaryHeader($dictionary, $className);
- $object->GenerateDictionaryImplementation($dictionary, $className);
</del><ins>+ $object->GenerateDictionaryHeader($dictionary, $className, $enumerations);
+ $object->GenerateDictionaryImplementation($dictionary, $className, $enumerations);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> sub GenerateInterface
</span><span class="lines">@@ -889,6 +889,7 @@
</span><span class="cx"> $result .= "{\n";
</span><span class="cx"> # FIXME: Might be nice to make this global be "const", but NeverDestroyed does not currently support that.
</span><span class="cx"> # FIXME: Might be nice to make the entire array be NeverDestroyed instead of each value, but not sure what the syntax for that is.
</span><ins>+ AddToImplIncludes("<wtf/NeverDestroyed.h>");
</ins><span class="cx"> $result .= " static NeverDestroyed<const String> values[] = {\n";
</span><span class="cx"> foreach my $value (@{$enumeration->values}) {
</span><span class="cx"> if ($value eq "") {
</span><span class="lines">@@ -4454,7 +4455,7 @@
</span><span class="cx">
</span><span class="cx"> sub GenerateDictionaryHeader
</span><span class="cx"> {
</span><del>- my ($object, $dictionary, $className) = @_;
</del><ins>+ my ($object, $dictionary, $className, $enumerations) = @_;
</ins><span class="cx">
</span><span class="cx"> my $dictionaryName = $dictionary->name;
</span><span class="cx">
</span><span class="lines">@@ -4466,6 +4467,7 @@
</span><span class="cx">
</span><span class="cx"> push(@headerContent, "\nnamespace WebCore {\n\n");
</span><span class="cx"> push(@headerContent, GenerateDictionaryHeaderContent($dictionary, $className));
</span><ins>+ push(@headerContent, GenerateEnumerationsHeaderContent($dictionary, $enumerations));
</ins><span class="cx"> push(@headerContent, "} // namespace WebCore\n");
</span><span class="cx">
</span><span class="cx"> my $conditionalString = $codeGenerator->GenerateConditionalString($dictionary);
</span><span class="lines">@@ -4488,7 +4490,7 @@
</span><span class="cx">
</span><span class="cx"> sub GenerateDictionaryImplementation
</span><span class="cx"> {
</span><del>- my ($object, $dictionary, $className) = @_;
</del><ins>+ my ($object, $dictionary, $className, $enumerations) = @_;
</ins><span class="cx">
</span><span class="cx"> # - Add default header template
</span><span class="cx"> push(@implContentHeader, GenerateImplementationContentHeader($dictionary));
</span><span class="lines">@@ -4495,6 +4497,7 @@
</span><span class="cx">
</span><span class="cx"> push(@implContent, "\nusing namespace JSC;\n\n");
</span><span class="cx"> push(@implContent, "namespace WebCore {\n\n");
</span><ins>+ push(@implContent, GenerateEnumerationsImplementationContent($dictionary, $enumerations));
</ins><span class="cx"> push(@implContent, GenerateDictionaryImplementationContent($dictionary, $className));
</span><span class="cx"> push(@implContent, "} // namespace WebCore\n");
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestJSJSTestStandaloneDictionarycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp (207767 => 207768)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp        2016-10-24 18:18:09 UTC (rev 207767)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.cpp        2016-10-24 18:24:12 UTC (rev 207768)
</span><span class="lines">@@ -24,11 +24,52 @@
</span><span class="cx">
</span><span class="cx"> #include "JSTestStandaloneDictionary.h"
</span><span class="cx">
</span><ins>+#include <runtime/JSString.h>
+#include <wtf/NeverDestroyed.h>
</ins><span class="cx">
</span><span class="cx"> using namespace JSC;
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><ins>+template<> JSString* convertEnumerationToJS(ExecState& state, TestStandaloneDictionary::EnumInStandaloneDictionaryFile enumerationValue)
+{
+ static NeverDestroyed<const String> values[] = {
+ ASCIILiteral("enumValue1"),
+ ASCIILiteral("enumValue2"),
+ };
+ static_assert(static_cast<size_t>(TestStandaloneDictionary::EnumInStandaloneDictionaryFile::EnumValue1) == 0, "TestStandaloneDictionary::EnumInStandaloneDictionaryFile::EnumValue1 is not 0 as expected");
+ static_assert(static_cast<size_t>(TestStandaloneDictionary::EnumInStandaloneDictionaryFile::EnumValue2) == 1, "TestStandaloneDictionary::EnumInStandaloneDictionaryFile::EnumValue2 is not 1 as expected");
+ ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
+ return jsStringWithCache(&state, values[static_cast<size_t>(enumerationValue)]);
+}
+
+template<> Optional<TestStandaloneDictionary::EnumInStandaloneDictionaryFile> parseEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>(ExecState& state, JSValue value)
+{
+ auto stringValue = value.toWTFString(&state);
+ if (stringValue == "enumValue1")
+ return TestStandaloneDictionary::EnumInStandaloneDictionaryFile::EnumValue1;
+ if (stringValue == "enumValue2")
+ return TestStandaloneDictionary::EnumInStandaloneDictionaryFile::EnumValue2;
+ return Nullopt;
+}
+
+template<> TestStandaloneDictionary::EnumInStandaloneDictionaryFile convertEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>(ExecState& state, JSValue value)
+{
+ VM& vm = state.vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto result = parseEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>(state, value);
+ if (UNLIKELY(!result)) {
+ throwTypeError(&state, throwScope);
+ return { };
+ }
+ return result.value();
+}
+
+template<> const char* expectedEnumerationValues<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>()
+{
+ return "\"enumValue1\", \"enumValue2\"";
+}
+
</ins><span class="cx"> template<> DictionaryImplName convertDictionary<DictionaryImplName>(ExecState& state, JSValue value)
</span><span class="cx"> {
</span><span class="cx"> VM& vm = state.vm();
</span><span class="lines">@@ -49,6 +90,11 @@
</span><span class="cx"> result.boolMember = convert<IDLBoolean>(state, boolMemberValue);
</span><span class="cx"> RETURN_IF_EXCEPTION(throwScope, { });
</span><span class="cx"> }
</span><ins>+ JSValue enumMemberValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "enumMember"));
+ if (!enumMemberValue.isUndefined()) {
+ result.enumMember = convert<IDLEnumeration<TestEnumInStandaloneDictionaryFile>>(state, enumMemberValue);
+ RETURN_IF_EXCEPTION(throwScope, { });
+ }
</ins><span class="cx"> JSValue stringMemberValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "stringMember"));
</span><span class="cx"> if (!stringMemberValue.isUndefined()) {
</span><span class="cx"> result.stringMember = convert<IDLDOMString>(state, stringMemberValue);
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestJSJSTestStandaloneDictionaryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.h (207767 => 207768)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.h        2016-10-24 18:18:09 UTC (rev 207767)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestStandaloneDictionary.h        2016-10-24 18:24:12 UTC (rev 207768)
</span><span class="lines">@@ -29,6 +29,12 @@
</span><span class="cx">
</span><span class="cx"> template<> DictionaryImplName convertDictionary<DictionaryImplName>(JSC::ExecState&, JSC::JSValue);
</span><span class="cx">
</span><ins>+template<> JSC::JSString* convertEnumerationToJS(JSC::ExecState&, TestStandaloneDictionary::EnumInStandaloneDictionaryFile);
+
+template<> Optional<TestStandaloneDictionary::EnumInStandaloneDictionaryFile> parseEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>(JSC::ExecState&, JSC::JSValue);
+template<> TestStandaloneDictionary::EnumInStandaloneDictionaryFile convertEnumeration<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>(JSC::ExecState&, JSC::JSValue);
+template<> const char* expectedEnumerationValues<TestStandaloneDictionary::EnumInStandaloneDictionaryFile>();
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(Condition1)
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestTestStandaloneDictionaryidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/TestStandaloneDictionary.idl (207767 => 207768)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/test/TestStandaloneDictionary.idl        2016-10-24 18:18:09 UTC (rev 207767)
+++ trunk/Source/WebCore/bindings/scripts/test/TestStandaloneDictionary.idl        2016-10-24 18:24:12 UTC (rev 207768)
</span><span class="lines">@@ -26,6 +26,8 @@
</span><span class="cx"> * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx"> */
</span><span class="cx">
</span><ins>+enum TestEnumInStandaloneDictionaryFile { "enumValue1", "enumValue2" };
+
</ins><span class="cx"> [
</span><span class="cx"> ImplementedAs=DictionaryImplName,
</span><span class="cx"> Conditional=Condition1,
</span><span class="lines">@@ -32,4 +34,5 @@
</span><span class="cx"> ] dictionary TestStandaloneDictionary {
</span><span class="cx"> boolean boolMember;
</span><span class="cx"> DOMString stringMember;
</span><ins>+ TestEnumInStandaloneDictionaryFile enumMember;
</ins><span class="cx"> };
</span></span></pre>
</div>
</div>
</body>
</html>