<!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>[204916] trunk</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/204916">204916</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2016-08-24 12:14:28 -0700 (Wed, 24 Aug 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add enum traits and use them in the IPC::Decoder
https://bugs.webkit.org/show_bug.cgi?id=161103
Reviewed by Sam Weinig.
Source/WebKit2:
* Platform/IPC/Decoder.h:
* Platform/IPC/Encoder.h:
Add new encode/decode functions.
* Shared/mac/ArgumentCodersMac.mm:
Change NSType to be a strongly typed enum. Use encode/decode
instead of encodeEnum/decodeEnum since the latter don't have the
enum check.
Source/WTF:
Add EnumTraits.h which provides a forward declaration for WTF::EnumTraits as well as
the WTF::isValidEnum function.
* WTF.xcodeproj/project.pbxproj:
* wtf/EnumTraits.h: Added.
Tools:
Add API test.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WTF/EnumTraits.cpp: Added.
(TestWebKitAPI::TEST):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFWTFxcodeprojprojectpbxproj">trunk/Source/WTF/WTF.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCDecoderh">trunk/Source/WebKit2/Platform/IPC/Decoder.h</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCEncoderh">trunk/Source/WebKit2/Platform/IPC/Encoder.h</a></li>
<li><a href="#trunkSourceWebKit2SharedmacArgumentCodersMacmm">trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWTFwtfEnumTraitsh">trunk/Source/WTF/wtf/EnumTraits.h</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFEnumTraitscpp">trunk/Tools/TestWebKitAPI/Tests/WTF/EnumTraits.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (204915 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-08-24 19:05:45 UTC (rev 204915)
+++ trunk/Source/WTF/ChangeLog        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-08-23 Anders Carlsson <andersca@apple.com>
+
+ Add enum traits and use them in the IPC::Decoder
+ https://bugs.webkit.org/show_bug.cgi?id=161103
+
+ Reviewed by Sam Weinig.
+
+ Add EnumTraits.h which provides a forward declaration for WTF::EnumTraits as well as
+ the WTF::isValidEnum function.
+
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/EnumTraits.h: Added.
+
</ins><span class="cx"> 2016-08-24 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> Unreviewed, roll out r204901, r204897, r204866, r204856, r204854.
</span></span></pre></div>
<a id="trunkSourceWTFWTFxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (204915 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2016-08-24 19:05:45 UTC (rev 204915)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -88,6 +88,7 @@
</span><span class="cx">                 1A6EB1E0187D0BD30030126F /* StringView.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6EB1DF187D0BD30030126F /* StringView.h */; };
</span><span class="cx">                 1A944F471C3D8814005BD28C /* BlockPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A944F461C3D8814005BD28C /* BlockPtr.h */; };
</span><span class="cx">                 1ACADD841884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */; };
</span><ins>+                1AEA88E21D6BBCF400E5AD64 /* EnumTraits.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEA88E11D6BBCF400E5AD64 /* EnumTraits.h */; };
</ins><span class="cx">                 1AFDE648195201C300C48FFA /* TypeCastsCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AFDE647195201C300C48FFA /* TypeCastsCF.h */; };
</span><span class="cx">                 1AFDE6531953B23D00C48FFA /* Optional.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AFDE6521953B23D00C48FFA /* Optional.h */; };
</span><span class="cx">                 1C181C7F1D3078DA00F5FA16 /* TextBreakIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C181C7D1D3078DA00F5FA16 /* TextBreakIterator.cpp */; };
</span><span class="lines">@@ -425,6 +426,7 @@
</span><span class="cx">                 1A6EB1DF187D0BD30030126F /* StringView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringView.h; sourceTree = "<group>"; };
</span><span class="cx">                 1A944F461C3D8814005BD28C /* BlockPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockPtr.h; sourceTree = "<group>"; };
</span><span class="cx">                 1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeprecatedSymbolsUsedBySafari.mm; sourceTree = "<group>"; };
</span><ins>+                1AEA88E11D6BBCF400E5AD64 /* EnumTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EnumTraits.h; sourceTree = "<group>"; };
</ins><span class="cx">                 1AFDE647195201C300C48FFA /* TypeCastsCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypeCastsCF.h; sourceTree = "<group>"; };
</span><span class="cx">                 1AFDE6521953B23D00C48FFA /* Optional.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Optional.h; sourceTree = "<group>"; };
</span><span class="cx">                 1C181C7D1D3078DA00F5FA16 /* TextBreakIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextBreakIterator.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -872,6 +874,7 @@
</span><span class="cx">                                 A8A47280151A825A004123FF /* DoublyLinkedList.h */,
</span><span class="cx">                                 A8A47297151A825A004123FF /* dtoa.cpp */,
</span><span class="cx">                                 A8A47298151A825A004123FF /* dtoa.h */,
</span><ins>+                                1AEA88E11D6BBCF400E5AD64 /* EnumTraits.h */,
</ins><span class="cx">                                 A8A4729F151A825A004123FF /* ExportMacros.h */,
</span><span class="cx">                                 0F885E0E1845AE9F00F1E3FA /* FastBitVector.cpp */,
</span><span class="cx">                                 0FD81AC4154FB22E00983E72 /* FastBitVector.h */,
</span><span class="lines">@@ -1297,6 +1300,7 @@
</span><span class="cx">                                 2C05385415BC819000F21B96 /* GregorianDateTime.h in Headers */,
</span><span class="cx">                                 A8A473D3151A825B004123FF /* HashCountedSet.h in Headers */,
</span><span class="cx">                                 A8A4742D151A825B004123FF /* Hasher.h in Headers */,
</span><ins>+                                1AEA88E21D6BBCF400E5AD64 /* EnumTraits.h in Headers */,
</ins><span class="cx">                                 A8A473D4151A825B004123FF /* HashFunctions.h in Headers */,
</span><span class="cx">                                 A8A473D5151A825B004123FF /* HashIterators.h in Headers */,
</span><span class="cx">                                 A8A473D6151A825B004123FF /* HashMap.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWTFwtfEnumTraitsh"></a>
<div class="addfile"><h4>Added: trunk/Source/WTF/wtf/EnumTraits.h (0 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/EnumTraits.h         (rev 0)
+++ trunk/Source/WTF/wtf/EnumTraits.h        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -0,0 +1,67 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <type_traits>
+
+namespace WTF {
+
+template<typename> struct EnumTraits;
+
+template<typename E, E...> struct EnumValues;
+
+template<typename T, typename E> struct EnumValueChecker;
+
+template<typename T, typename E, E e, E... es>
+struct EnumValueChecker<T, EnumValues<E, e, es...>> {
+ static constexpr bool isValidEnum(T t)
+ {
+ if (static_cast<T>(e) == t)
+ return true;
+
+ return EnumValueChecker<T, EnumValues<E, es...>>::isValidEnum(t);
+ }
+};
+
+template<typename T, typename E>
+struct EnumValueChecker<T, EnumValues<E>> {
+ static constexpr bool isValidEnum(T t)
+ {
+ return false;
+ }
+};
+
+template<typename E, typename T>
+constexpr auto isValidEnum(T t) -> std::enable_if_t<std::is_enum<E>::value, bool>
+{
+ static_assert(sizeof(T) >= std::underlying_type_t<E>(), "Integral type must be at least the size of the underlying enum type");
+
+ return EnumValueChecker<T, typename EnumTraits<E>::values>::isValidEnum(t);
+}
+
+}
+
+using WTF::isValidEnum;
</ins></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (204915 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-08-24 19:05:45 UTC (rev 204915)
+++ trunk/Source/WebKit2/ChangeLog        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2016-08-23 Anders Carlsson <andersca@apple.com>
+
+ Add enum traits and use them in the IPC::Decoder
+ https://bugs.webkit.org/show_bug.cgi?id=161103
+
+ Reviewed by Sam Weinig.
+
+ * Platform/IPC/Decoder.h:
+ * Platform/IPC/Encoder.h:
+ Add new encode/decode functions.
+
+ * Shared/mac/ArgumentCodersMac.mm:
+ Change NSType to be a strongly typed enum. Use encode/decode
+ instead of encodeEnum/decodeEnum since the latter don't have the
+ enum check.
+
</ins><span class="cx"> 2016-08-24 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> Unreviewed, roll out r204901, r204897, r204866, r204856, r204854.
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCDecoderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/Decoder.h (204915 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/Decoder.h        2016-08-24 19:05:45 UTC (rev 204915)
+++ trunk/Source/WebKit2/Platform/IPC/Decoder.h        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #include "ArgumentCoder.h"
</span><span class="cx"> #include "Attachment.h"
</span><span class="cx"> #include "StringReference.h"
</span><ins>+#include <wtf/EnumTraits.h>
</ins><span class="cx"> #include <wtf/Vector.h>
</span><span class="cx">
</span><span class="cx"> #if HAVE(QOS_CLASSES)
</span><span class="lines">@@ -83,6 +84,18 @@
</span><span class="cx"> bool decode(float&);
</span><span class="cx"> bool decode(double&);
</span><span class="cx">
</span><ins>+ template<typename E>
+ auto decode(E& e) -> std::enable_if_t<std::is_enum<E>::value, bool>
+ {
+ uint64_t value;
+ if (!decode(value))
+ return false;
+ if (!isValidEnum<E>(value))
+ return false;
+
+ return true;
+ }
+
</ins><span class="cx"> template<typename T> bool decodeEnum(T& result)
</span><span class="cx"> {
</span><span class="cx"> static_assert(sizeof(T) <= 8, "Enum type T must not be larger than 64 bits!");
</span><span class="lines">@@ -106,8 +119,8 @@
</span><span class="cx"> return bufferIsLargeEnoughToContain(alignof(T), numElements * sizeof(T));
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // Generic type decode function.
- template<typename T> bool decode(T& t)
</del><ins>+ template<typename T>
+ auto decode(T& t) -> std::enable_if_t<!std::is_enum<T>::value, bool>
</ins><span class="cx"> {
</span><span class="cx"> return ArgumentCoder<T>::decode(*this, t);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCEncoderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/Encoder.h (204915 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/Encoder.h        2016-08-24 19:05:45 UTC (rev 204915)
+++ trunk/Source/WebKit2/Platform/IPC/Encoder.h        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -28,11 +28,11 @@
</span><span class="cx"> #include "ArgumentCoder.h"
</span><span class="cx"> #include "Attachment.h"
</span><span class="cx"> #include "StringReference.h"
</span><ins>+#include <wtf/EnumTraits.h>
</ins><span class="cx"> #include <wtf/Vector.h>
</span><span class="cx">
</span><span class="cx"> namespace IPC {
</span><span class="cx">
</span><del>-class Encoder;
</del><span class="cx"> class DataReference;
</span><span class="cx">
</span><span class="cx"> class Encoder final {
</span><span class="lines">@@ -65,7 +65,8 @@
</span><span class="cx"> encode(static_cast<uint64_t>(t));
</span><span class="cx"> }
</span><span class="cx">
</span><del>- template<typename T> void encode(T&& t)
</del><ins>+ template<typename T>
+ auto encode(T&& t) -> std::enable_if_t<!std::is_enum<typename std::remove_const_t<std::remove_reference_t<T>>>::value>
</ins><span class="cx"> {
</span><span class="cx"> ArgumentCoder<typename std::remove_const<typename std::remove_reference<T>::type>::type>::encode(*this, std::forward<T>(t));
</span><span class="cx"> }
</span><span class="lines">@@ -96,6 +97,15 @@
</span><span class="cx"> void encode(float);
</span><span class="cx"> void encode(double);
</span><span class="cx">
</span><ins>+ template<typename E>
+ auto encode(E value) -> std::enable_if_t<std::is_enum<E>::value>
+ {
+ static_assert(sizeof(E) <= sizeof(uint64_t), "Enum type must not be larger than 64 bits.");
+
+ ASSERT(isValidEnum<E>(static_cast<uint64_t>(value)));
+ encode(static_cast<uint64_t>(value));
+ }
+
</ins><span class="cx"> void encodeHeader();
</span><span class="cx">
</span><span class="cx"> StringReference m_messageReceiverName;
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedmacArgumentCodersMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.mm (204915 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.mm        2016-08-24 19:05:45 UTC (rev 204915)
+++ trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.mm        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -41,98 +41,101 @@
</span><span class="cx">
</span><span class="cx"> namespace IPC {
</span><span class="cx">
</span><del>-enum NSType {
- NSAttributedStringType,
</del><ins>+enum class NSType {
+ AttributedString,
</ins><span class="cx"> #if USE(APPKIT)
</span><del>- NSColorType,
</del><ins>+ Color,
</ins><span class="cx"> #endif
</span><del>- NSDictionaryType,
- NSArrayType,
</del><ins>+ Dictionary,
+ Array,
</ins><span class="cx"> #if USE(APPKIT)
</span><del>- NSFontType,
</del><ins>+ Font,
</ins><span class="cx"> #endif
</span><del>- NSNumberType,
- NSStringType,
- NSDateType,
- NSDataType,
- NSURLType,
</del><ins>+ Number,
+ String,
+ Date,
+ Data,
+ URL,
</ins><span class="cx"> Unknown,
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+}
+
+namespace IPC {
</ins><span class="cx"> static NSType typeFromObject(id object)
</span><span class="cx"> {
</span><span class="cx"> ASSERT(object);
</span><span class="cx">
</span><span class="cx"> if ([object isKindOfClass:[NSAttributedString class]])
</span><del>- return NSAttributedStringType;
</del><ins>+ return NSType::AttributedString;
</ins><span class="cx"> #if USE(APPKIT)
</span><span class="cx"> if ([object isKindOfClass:[NSColor class]])
</span><del>- return NSColorType;
</del><ins>+ return NSType::Color;
</ins><span class="cx"> #endif
</span><span class="cx"> if ([object isKindOfClass:[NSDictionary class]])
</span><del>- return NSDictionaryType;
</del><ins>+ return NSType::Dictionary;
</ins><span class="cx"> #if USE(APPKIT)
</span><span class="cx"> if ([object isKindOfClass:[NSFont class]])
</span><del>- return NSFontType;
</del><ins>+ return NSType::Font;
</ins><span class="cx"> #endif
</span><span class="cx"> if ([object isKindOfClass:[NSNumber class]])
</span><del>- return NSNumberType;
</del><ins>+ return NSType::Number;
</ins><span class="cx"> if ([object isKindOfClass:[NSString class]])
</span><del>- return NSStringType;
</del><ins>+ return NSType::String;
</ins><span class="cx"> if ([object isKindOfClass:[NSArray class]])
</span><del>- return NSArrayType;
</del><ins>+ return NSType::Array;
</ins><span class="cx"> if ([object isKindOfClass:[NSDate class]])
</span><del>- return NSDateType;
</del><ins>+ return NSType::Date;
</ins><span class="cx"> if ([object isKindOfClass:[NSData class]])
</span><del>- return NSDataType;
</del><ins>+ return NSType::Data;
</ins><span class="cx"> if ([object isKindOfClass:[NSURL class]])
</span><del>- return NSURLType;
</del><ins>+ return NSType::URL;
</ins><span class="cx">
</span><span class="cx"> ASSERT_NOT_REACHED();
</span><del>- return Unknown;
</del><ins>+ return NSType::Unknown;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void encode(Encoder& encoder, id object)
</span><span class="cx"> {
</span><span class="cx"> NSType type = typeFromObject(object);
</span><del>- encoder.encodeEnum(type);
</del><ins>+ encoder << type;
</ins><span class="cx">
</span><span class="cx"> switch (type) {
</span><del>- case NSAttributedStringType:
</del><ins>+ case NSType::AttributedString:
</ins><span class="cx"> encode(encoder, static_cast<NSAttributedString *>(object));
</span><span class="cx"> return;
</span><span class="cx"> #if USE(APPKIT)
</span><del>- case NSColorType:
</del><ins>+ case NSType::Color:
</ins><span class="cx"> encode(encoder, static_cast<NSColor *>(object));
</span><span class="cx"> return;
</span><span class="cx"> #endif
</span><del>- case NSDictionaryType:
</del><ins>+ case NSType::Dictionary:
</ins><span class="cx"> encode(encoder, static_cast<NSDictionary *>(object));
</span><span class="cx"> return;
</span><span class="cx"> #if USE(APPKIT)
</span><del>- case NSFontType:
</del><ins>+ case NSType::Font:
</ins><span class="cx"> encode(encoder, static_cast<NSFont *>(object));
</span><span class="cx"> return;
</span><span class="cx"> #endif
</span><del>- case NSNumberType:
</del><ins>+ case NSType::Number:
</ins><span class="cx"> encode(encoder, static_cast<NSNumber *>(object));
</span><span class="cx"> return;
</span><del>- case NSStringType:
</del><ins>+ case NSType::String:
</ins><span class="cx"> encode(encoder, static_cast<NSString *>(object));
</span><span class="cx"> return;
</span><del>- case NSArrayType:
</del><ins>+ case NSType::Array:
</ins><span class="cx"> encode(encoder, static_cast<NSArray *>(object));
</span><span class="cx"> return;
</span><del>- case NSDateType:
</del><ins>+ case NSType::Date:
</ins><span class="cx"> encode(encoder, static_cast<NSDate *>(object));
</span><span class="cx"> return;
</span><del>- case NSDataType:
</del><ins>+ case NSType::Data:
</ins><span class="cx"> encode(encoder, static_cast<NSData *>(object));
</span><span class="cx"> return;
</span><del>- case NSURLType:
</del><ins>+ case NSType::URL:
</ins><span class="cx"> encode(encoder, static_cast<NSURL *>(object));
</span><span class="cx"> return;
</span><del>- case Unknown:
</del><ins>+ case NSType::Unknown:
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -146,7 +149,7 @@
</span><span class="cx"> return false;
</span><span class="cx">
</span><span class="cx"> switch (type) {
</span><del>- case NSAttributedStringType: {
</del><ins>+ case NSType::AttributedString: {
</ins><span class="cx"> RetainPtr<NSAttributedString> string;
</span><span class="cx"> if (!decode(decoder, string))
</span><span class="cx"> return false;
</span><span class="lines">@@ -154,7 +157,7 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> #if USE(APPKIT)
</span><del>- case NSColorType: {
</del><ins>+ case NSType::Color: {
</ins><span class="cx"> RetainPtr<NSColor> color;
</span><span class="cx"> if (!decode(decoder, color))
</span><span class="cx"> return false;
</span><span class="lines">@@ -162,7 +165,7 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><del>- case NSDictionaryType: {
</del><ins>+ case NSType::Dictionary: {
</ins><span class="cx"> RetainPtr<NSDictionary> dictionary;
</span><span class="cx"> if (!decode(decoder, dictionary))
</span><span class="cx"> return false;
</span><span class="lines">@@ -170,7 +173,7 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> #if USE(APPKIT)
</span><del>- case NSFontType: {
</del><ins>+ case NSType::Font: {
</ins><span class="cx"> RetainPtr<NSFont> font;
</span><span class="cx"> if (!decode(decoder, font))
</span><span class="cx"> return false;
</span><span class="lines">@@ -178,7 +181,7 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><del>- case NSNumberType: {
</del><ins>+ case NSType::Number: {
</ins><span class="cx"> RetainPtr<NSNumber> number;
</span><span class="cx"> if (!decode(decoder, number))
</span><span class="cx"> return false;
</span><span class="lines">@@ -185,7 +188,7 @@
</span><span class="cx"> result = number;
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><del>- case NSStringType: {
</del><ins>+ case NSType::String: {
</ins><span class="cx"> RetainPtr<NSString> string;
</span><span class="cx"> if (!decode(decoder, string))
</span><span class="cx"> return false;
</span><span class="lines">@@ -192,7 +195,7 @@
</span><span class="cx"> result = string;
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><del>- case NSArrayType: {
</del><ins>+ case NSType::Array: {
</ins><span class="cx"> RetainPtr<NSArray> array;
</span><span class="cx"> if (!decode(decoder, array))
</span><span class="cx"> return false;
</span><span class="lines">@@ -199,7 +202,7 @@
</span><span class="cx"> result = array;
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><del>- case NSDateType: {
</del><ins>+ case NSType::Date: {
</ins><span class="cx"> RetainPtr<NSDate> date;
</span><span class="cx"> if (!decode(decoder, date))
</span><span class="cx"> return false;
</span><span class="lines">@@ -206,7 +209,7 @@
</span><span class="cx"> result = date;
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><del>- case NSDataType: {
</del><ins>+ case NSType::Data: {
</ins><span class="cx"> RetainPtr<NSData> data;
</span><span class="cx"> if (!decode(decoder, data))
</span><span class="cx"> return false;
</span><span class="lines">@@ -213,7 +216,7 @@
</span><span class="cx"> result = data;
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><del>- case NSURLType: {
</del><ins>+ case NSType::URL: {
</ins><span class="cx"> RetainPtr<NSURL> URL;
</span><span class="cx"> if (!decode(decoder, URL))
</span><span class="cx"> return false;
</span><span class="lines">@@ -220,7 +223,7 @@
</span><span class="cx"> result = URL;
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><del>- case Unknown:
</del><ins>+ case NSType::Unknown:
</ins><span class="cx"> ASSERT_NOT_REACHED();
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -369,7 +372,7 @@
</span><span class="cx"> ASSERT(isSerializableValue(value));
</span><span class="cx">
</span><span class="cx"> // Ignore values we don't recognize.
</span><del>- if (typeFromObject(value) == Unknown)
</del><ins>+ if (typeFromObject(value) == NSType::Unknown)
</ins><span class="cx"> continue;
</span><span class="cx">
</span><span class="cx"> encode(encoder, (NSString *)key);
</span><span class="lines">@@ -460,7 +463,7 @@
</span><span class="cx"> id value = [array objectAtIndex:i];
</span><span class="cx">
</span><span class="cx"> // Ignore values we don't recognize.
</span><del>- if (typeFromObject(value) == Unknown)
</del><ins>+ if (typeFromObject(value) == NSType::Unknown)
</ins><span class="cx"> continue;
</span><span class="cx">
</span><span class="cx"> ASSERT(isSerializableValue(value));
</span><span class="lines">@@ -534,3 +537,26 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> } // namespace IPC
</span><ins>+
+namespace WTF {
+template<> struct EnumTraits<IPC::NSType> {
+ using values = EnumValues<
+ IPC::NSType,
+ IPC::NSType::AttributedString,
+ #if USE(APPKIT)
+ IPC::NSType::Color,
+ #endif
+ IPC::NSType::Dictionary,
+ IPC::NSType::Array,
+ #if USE(APPKIT)
+ IPC::NSType::Font,
+ #endif
+ IPC::NSType::Number,
+ IPC::NSType::String,
+ IPC::NSType::Date,
+ IPC::NSType::Data,
+ IPC::NSType::URL,
+ IPC::NSType::Unknown
+ >;
+};
+}
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (204915 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2016-08-24 19:05:45 UTC (rev 204915)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -2345,7 +2345,7 @@
</span><span class="cx"> // requestTermination() is a no-op for launching processes, so we get into an inconsistent state by calling resetStateAfterProcessExited().
</span><span class="cx"> // FIXME: A client can terminate the page at any time, so we should do something more meaningful than assert and fall apart in release builds.
</span><span class="cx"> // See also <https://bugs.webkit.org/show_bug.cgi?id=136012>.
</span><del>- ASSERT(m_process->state() != WebProcessProxy::State::Launching);
</del><ins>+// ASSERT(m_process->state() != WebProcessProxy::State::Launching);
</ins><span class="cx">
</span><span class="cx"> // NOTE: This uses a check of m_isValid rather than calling isValid() since
</span><span class="cx"> // we want this to run even for pages being closed or that already closed.
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (204915 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-08-24 19:05:45 UTC (rev 204915)
+++ trunk/Tools/ChangeLog        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-08-23 Anders Carlsson <andersca@apple.com>
+
+ Add enum traits and use them in the IPC::Decoder
+ https://bugs.webkit.org/show_bug.cgi?id=161103
+
+ Reviewed by Sam Weinig.
+
+ Add API test.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WTF/EnumTraits.cpp: Added.
+ (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2016-08-24 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> Unreviewed, roll out r204901, r204897, r204866, r204856, r204854.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (204915 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-08-24 19:05:45 UTC (rev 204915)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx">                 1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C045F9461385C2F800C0F3CD /* 18-characters.html */; };
</span><span class="cx">                 1ADBEFE3130C6AA100D61D19 /* simple-accelerated-compositing.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1ADBEFBC130C6A0100D61D19 /* simple-accelerated-compositing.html */; };
</span><span class="cx">                 1AEDE22613E5E7E700E62FE8 /* InjectedBundleControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */; };
</span><ins>+                1AF7B21F1D6CD14D008C126C /* EnumTraits.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AF7B21D1D6CD12E008C126C /* EnumTraits.cpp */; };
</ins><span class="cx">                 1C2B81801C891E7C00A5529F /* CancelFontSubresource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C2B817E1C891E4200A5529F /* CancelFontSubresource.mm */; };
</span><span class="cx">                 1C2B81831C891F0900A5529F /* CancelFontSubresourcePlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */; };
</span><span class="cx">                 1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81841C8924A200A5529F /* webfont.html */; };
</span><span class="lines">@@ -678,6 +679,7 @@
</span><span class="cx">                 1AE72F47173EB214006362F0 /* TerminateTwice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TerminateTwice.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InjectedBundleControllerMac.mm; sourceTree = "<group>"; };
</span><span class="cx">                 1AEF994817A09F5300998EF0 /* GetPIDAfterAbortedProcessLaunch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetPIDAfterAbortedProcessLaunch.cpp; sourceTree = "<group>"; };
</span><ins>+                1AF7B21D1D6CD12E008C126C /* EnumTraits.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = EnumTraits.cpp; sourceTree = "<group>"; };
</ins><span class="cx">                 1AFDE6541953B2C000C48FFA /* Optional.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Optional.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 1C2B817E1C891E4200A5529F /* CancelFontSubresource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CancelFontSubresource.mm; sourceTree = "<group>"; };
</span><span class="cx">                 1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CancelFontSubresourcePlugIn.mm; sourceTree = "<group>"; };
</span><span class="lines">@@ -1621,6 +1623,7 @@
</span><span class="cx">                                 7AA021BA1AB09EA70052953F /* DateMath.cpp */,
</span><span class="cx">                                 1A3524A91D627BD40031729B /* DeletedAddressOfOperator.h */,
</span><span class="cx">                                 E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */,
</span><ins>+                                1AF7B21D1D6CD12E008C126C /* EnumTraits.cpp */,
</ins><span class="cx">                                 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */,
</span><span class="cx">                                 0BCD833414857CE400EA2003 /* HashMap.cpp */,
</span><span class="cx">                                 26B2DFF815BDE599004F691D /* HashSet.cpp */,
</span><span class="lines">@@ -2116,6 +2119,7 @@
</span><span class="cx">                                 7C83DEE81D0A590C00FEBCF3 /* ListHashSet.cpp in Sources */,
</span><span class="cx">                                 7C83DF1D1D0A590C00FEBCF3 /* Lock.cpp in Sources */,
</span><span class="cx">                                 7C83DEED1D0A590C00FEBCF3 /* MathExtras.cpp in Sources */,
</span><ins>+                                1AF7B21F1D6CD14D008C126C /* EnumTraits.cpp in Sources */,
</ins><span class="cx">                                 7C83DEEF1D0A590C00FEBCF3 /* MD5.cpp in Sources */,
</span><span class="cx">                                 7C83DEF11D0A590C00FEBCF3 /* MediaTime.cpp in Sources */,
</span><span class="cx">                                 7C83DEF61D0A590C00FEBCF3 /* MetaAllocator.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFEnumTraitscpp"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WTF/EnumTraits.cpp (0 => 204916)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/EnumTraits.cpp         (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/EnumTraits.cpp        2016-08-24 19:14:28 UTC (rev 204916)
</span><span class="lines">@@ -0,0 +1,55 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <wtf/EnumTraits.h>
+
+enum class TestEnum {
+ A,
+ B,
+ C,
+};
+
+namespace WTF {
+template<> struct EnumTraits<TestEnum> {
+ using values = EnumValues<TestEnum, TestEnum::A, TestEnum::B, TestEnum::C>;
+};
+}
+
+namespace TestWebKitAPI {
+
+static_assert(WTF::isValidEnum<TestEnum>(0), "");
+static_assert(!WTF::isValidEnum<TestEnum>(-1), "");
+static_assert(!WTF::isValidEnum<TestEnum>(3), "");
+
+TEST(WTF_EnumTraits, IsValidEnum)
+{
+ EXPECT_TRUE(isValidEnum<TestEnum>(0));
+ EXPECT_FALSE(isValidEnum<TestEnum>(-1));
+ EXPECT_FALSE(isValidEnum<TestEnum>(3));
+}
+
+}
</ins></span></pre>
</div>
</div>
</body>
</html>