Changeset 204916 in webkit
- Timestamp:
- Aug 24, 2016 12:14:28 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r204912 r204916 1 2016-08-23 Anders Carlsson <andersca@apple.com> 2 3 Add enum traits and use them in the IPC::Decoder 4 https://bugs.webkit.org/show_bug.cgi?id=161103 5 6 Reviewed by Sam Weinig. 7 8 Add EnumTraits.h which provides a forward declaration for WTF::EnumTraits as well as 9 the WTF::isValidEnum function. 10 11 * WTF.xcodeproj/project.pbxproj: 12 * wtf/EnumTraits.h: Added. 13 1 14 2016-08-24 Filip Pizlo <fpizlo@apple.com> 2 15 -
trunk/Source/WTF/WTF.xcodeproj/project.pbxproj
r204529 r204916 89 89 1A944F471C3D8814005BD28C /* BlockPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A944F461C3D8814005BD28C /* BlockPtr.h */; }; 90 90 1ACADD841884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */; }; 91 1AEA88E21D6BBCF400E5AD64 /* EnumTraits.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEA88E11D6BBCF400E5AD64 /* EnumTraits.h */; }; 91 92 1AFDE648195201C300C48FFA /* TypeCastsCF.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AFDE647195201C300C48FFA /* TypeCastsCF.h */; }; 92 93 1AFDE6531953B23D00C48FFA /* Optional.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AFDE6521953B23D00C48FFA /* Optional.h */; }; … … 426 427 1A944F461C3D8814005BD28C /* BlockPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlockPtr.h; sourceTree = "<group>"; }; 427 428 1ACADD821884480100D8B71D /* DeprecatedSymbolsUsedBySafari.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeprecatedSymbolsUsedBySafari.mm; sourceTree = "<group>"; }; 429 1AEA88E11D6BBCF400E5AD64 /* EnumTraits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EnumTraits.h; sourceTree = "<group>"; }; 428 430 1AFDE647195201C300C48FFA /* TypeCastsCF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TypeCastsCF.h; sourceTree = "<group>"; }; 429 431 1AFDE6521953B23D00C48FFA /* Optional.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Optional.h; sourceTree = "<group>"; }; … … 873 875 A8A47297151A825A004123FF /* dtoa.cpp */, 874 876 A8A47298151A825A004123FF /* dtoa.h */, 877 1AEA88E11D6BBCF400E5AD64 /* EnumTraits.h */, 875 878 A8A4729F151A825A004123FF /* ExportMacros.h */, 876 879 0F885E0E1845AE9F00F1E3FA /* FastBitVector.cpp */, … … 1298 1301 A8A473D3151A825B004123FF /* HashCountedSet.h in Headers */, 1299 1302 A8A4742D151A825B004123FF /* Hasher.h in Headers */, 1303 1AEA88E21D6BBCF400E5AD64 /* EnumTraits.h in Headers */, 1300 1304 A8A473D4151A825B004123FF /* HashFunctions.h in Headers */, 1301 1305 A8A473D5151A825B004123FF /* HashIterators.h in Headers */, -
trunk/Source/WebKit2/ChangeLog
r204912 r204916 1 2016-08-23 Anders Carlsson <andersca@apple.com> 2 3 Add enum traits and use them in the IPC::Decoder 4 https://bugs.webkit.org/show_bug.cgi?id=161103 5 6 Reviewed by Sam Weinig. 7 8 * Platform/IPC/Decoder.h: 9 * Platform/IPC/Encoder.h: 10 Add new encode/decode functions. 11 12 * Shared/mac/ArgumentCodersMac.mm: 13 Change NSType to be a strongly typed enum. Use encode/decode 14 instead of encodeEnum/decodeEnum since the latter don't have the 15 enum check. 16 1 17 2016-08-24 Filip Pizlo <fpizlo@apple.com> 2 18 -
trunk/Source/WebKit2/Platform/IPC/Decoder.h
r204668 r204916 29 29 #include "Attachment.h" 30 30 #include "StringReference.h" 31 #include <wtf/EnumTraits.h> 31 32 #include <wtf/Vector.h> 32 33 … … 84 85 bool decode(double&); 85 86 87 template<typename E> 88 auto decode(E& e) -> std::enable_if_t<std::is_enum<E>::value, bool> 89 { 90 uint64_t value; 91 if (!decode(value)) 92 return false; 93 if (!isValidEnum<E>(value)) 94 return false; 95 96 return true; 97 } 98 86 99 template<typename T> bool decodeEnum(T& result) 87 100 { … … 107 120 } 108 121 109 // Generic type decode function.110 template<typename T> bool decode(T& t)122 template<typename T> 123 auto decode(T& t) -> std::enable_if_t<!std::is_enum<T>::value, bool> 111 124 { 112 125 return ArgumentCoder<T>::decode(*this, t); -
trunk/Source/WebKit2/Platform/IPC/Encoder.h
r204665 r204916 29 29 #include "Attachment.h" 30 30 #include "StringReference.h" 31 #include <wtf/EnumTraits.h> 31 32 #include <wtf/Vector.h> 32 33 33 34 namespace IPC { 34 35 35 class Encoder;36 36 class DataReference; 37 37 … … 66 66 } 67 67 68 template<typename T> void encode(T&& t) 68 template<typename T> 69 auto encode(T&& t) -> std::enable_if_t<!std::is_enum<typename std::remove_const_t<std::remove_reference_t<T>>>::value> 69 70 { 70 71 ArgumentCoder<typename std::remove_const<typename std::remove_reference<T>::type>::type>::encode(*this, std::forward<T>(t)); … … 97 98 void encode(double); 98 99 100 template<typename E> 101 auto encode(E value) -> std::enable_if_t<std::is_enum<E>::value> 102 { 103 static_assert(sizeof(E) <= sizeof(uint64_t), "Enum type must not be larger than 64 bits."); 104 105 ASSERT(isValidEnum<E>(static_cast<uint64_t>(value))); 106 encode(static_cast<uint64_t>(value)); 107 } 108 99 109 void encodeHeader(); 100 110 -
trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.mm
r204668 r204916 42 42 namespace IPC { 43 43 44 enum NSType {45 NSAttributedStringType,46 #if USE(APPKIT) 47 NSColorType,48 #endif 49 NSDictionaryType,50 NSArrayType,51 #if USE(APPKIT) 52 NSFontType,53 #endif 54 N SNumberType,55 NSStringType,56 NSDateType,57 NSDataType,58 NSURLType,44 enum class NSType { 45 AttributedString, 46 #if USE(APPKIT) 47 Color, 48 #endif 49 Dictionary, 50 Array, 51 #if USE(APPKIT) 52 Font, 53 #endif 54 Number, 55 String, 56 Date, 57 Data, 58 URL, 59 59 Unknown, 60 60 }; 61 61 62 } 63 64 namespace IPC { 62 65 static NSType typeFromObject(id object) 63 66 { … … 65 68 66 69 if ([object isKindOfClass:[NSAttributedString class]]) 67 return NS AttributedStringType;70 return NSType::AttributedString; 68 71 #if USE(APPKIT) 69 72 if ([object isKindOfClass:[NSColor class]]) 70 return NS ColorType;73 return NSType::Color; 71 74 #endif 72 75 if ([object isKindOfClass:[NSDictionary class]]) 73 return NS DictionaryType;76 return NSType::Dictionary; 74 77 #if USE(APPKIT) 75 78 if ([object isKindOfClass:[NSFont class]]) 76 return NS FontType;79 return NSType::Font; 77 80 #endif 78 81 if ([object isKindOfClass:[NSNumber class]]) 79 return NS NumberType;82 return NSType::Number; 80 83 if ([object isKindOfClass:[NSString class]]) 81 return NS StringType;84 return NSType::String; 82 85 if ([object isKindOfClass:[NSArray class]]) 83 return NS ArrayType;86 return NSType::Array; 84 87 if ([object isKindOfClass:[NSDate class]]) 85 return NS DateType;88 return NSType::Date; 86 89 if ([object isKindOfClass:[NSData class]]) 87 return NS DataType;90 return NSType::Data; 88 91 if ([object isKindOfClass:[NSURL class]]) 89 return NS URLType;92 return NSType::URL; 90 93 91 94 ASSERT_NOT_REACHED(); 92 return Unknown;95 return NSType::Unknown; 93 96 } 94 97 … … 96 99 { 97 100 NSType type = typeFromObject(object); 98 encoder .encodeEnum(type);101 encoder << type; 99 102 100 103 switch (type) { 101 case NS AttributedStringType:104 case NSType::AttributedString: 102 105 encode(encoder, static_cast<NSAttributedString *>(object)); 103 106 return; 104 107 #if USE(APPKIT) 105 case NS ColorType:108 case NSType::Color: 106 109 encode(encoder, static_cast<NSColor *>(object)); 107 110 return; 108 111 #endif 109 case NS DictionaryType:112 case NSType::Dictionary: 110 113 encode(encoder, static_cast<NSDictionary *>(object)); 111 114 return; 112 115 #if USE(APPKIT) 113 case NS FontType:116 case NSType::Font: 114 117 encode(encoder, static_cast<NSFont *>(object)); 115 118 return; 116 119 #endif 117 case NS NumberType:120 case NSType::Number: 118 121 encode(encoder, static_cast<NSNumber *>(object)); 119 122 return; 120 case NS StringType:123 case NSType::String: 121 124 encode(encoder, static_cast<NSString *>(object)); 122 125 return; 123 case NS ArrayType:126 case NSType::Array: 124 127 encode(encoder, static_cast<NSArray *>(object)); 125 128 return; 126 case NS DateType:129 case NSType::Date: 127 130 encode(encoder, static_cast<NSDate *>(object)); 128 131 return; 129 case NS DataType:132 case NSType::Data: 130 133 encode(encoder, static_cast<NSData *>(object)); 131 134 return; 132 case NS URLType:135 case NSType::URL: 133 136 encode(encoder, static_cast<NSURL *>(object)); 134 137 return; 135 case Unknown:138 case NSType::Unknown: 136 139 break; 137 140 } … … 147 150 148 151 switch (type) { 149 case NS AttributedStringType: {152 case NSType::AttributedString: { 150 153 RetainPtr<NSAttributedString> string; 151 154 if (!decode(decoder, string)) … … 155 158 } 156 159 #if USE(APPKIT) 157 case NS ColorType: {160 case NSType::Color: { 158 161 RetainPtr<NSColor> color; 159 162 if (!decode(decoder, color)) … … 163 166 } 164 167 #endif 165 case NS DictionaryType: {168 case NSType::Dictionary: { 166 169 RetainPtr<NSDictionary> dictionary; 167 170 if (!decode(decoder, dictionary)) … … 171 174 } 172 175 #if USE(APPKIT) 173 case NS FontType: {176 case NSType::Font: { 174 177 RetainPtr<NSFont> font; 175 178 if (!decode(decoder, font)) … … 179 182 } 180 183 #endif 181 case NS NumberType: {184 case NSType::Number: { 182 185 RetainPtr<NSNumber> number; 183 186 if (!decode(decoder, number)) … … 186 189 return true; 187 190 } 188 case NS StringType: {191 case NSType::String: { 189 192 RetainPtr<NSString> string; 190 193 if (!decode(decoder, string)) … … 193 196 return true; 194 197 } 195 case NS ArrayType: {198 case NSType::Array: { 196 199 RetainPtr<NSArray> array; 197 200 if (!decode(decoder, array)) … … 200 203 return true; 201 204 } 202 case NS DateType: {205 case NSType::Date: { 203 206 RetainPtr<NSDate> date; 204 207 if (!decode(decoder, date)) … … 207 210 return true; 208 211 } 209 case NS DataType: {212 case NSType::Data: { 210 213 RetainPtr<NSData> data; 211 214 if (!decode(decoder, data)) … … 214 217 return true; 215 218 } 216 case NS URLType: {219 case NSType::URL: { 217 220 RetainPtr<NSURL> URL; 218 221 if (!decode(decoder, URL)) … … 221 224 return true; 222 225 } 223 case Unknown:226 case NSType::Unknown: 224 227 ASSERT_NOT_REACHED(); 225 228 return false; … … 370 373 371 374 // Ignore values we don't recognize. 372 if (typeFromObject(value) == Unknown)375 if (typeFromObject(value) == NSType::Unknown) 373 376 continue; 374 377 … … 461 464 462 465 // Ignore values we don't recognize. 463 if (typeFromObject(value) == Unknown)466 if (typeFromObject(value) == NSType::Unknown) 464 467 continue; 465 468 … … 535 538 536 539 } // namespace IPC 540 541 namespace WTF { 542 template<> struct EnumTraits<IPC::NSType> { 543 using values = EnumValues< 544 IPC::NSType, 545 IPC::NSType::AttributedString, 546 #if USE(APPKIT) 547 IPC::NSType::Color, 548 #endif 549 IPC::NSType::Dictionary, 550 IPC::NSType::Array, 551 #if USE(APPKIT) 552 IPC::NSType::Font, 553 #endif 554 IPC::NSType::Number, 555 IPC::NSType::String, 556 IPC::NSType::Date, 557 IPC::NSType::Data, 558 IPC::NSType::URL, 559 IPC::NSType::Unknown 560 >; 561 }; 562 } -
trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp
r204912 r204916 2346 2346 // 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. 2347 2347 // See also <https://bugs.webkit.org/show_bug.cgi?id=136012>. 2348 ASSERT(m_process->state() != WebProcessProxy::State::Launching);2348 // ASSERT(m_process->state() != WebProcessProxy::State::Launching); 2349 2349 2350 2350 // NOTE: This uses a check of m_isValid rather than calling isValid() since -
trunk/Tools/ChangeLog
r204912 r204916 1 2016-08-23 Anders Carlsson <andersca@apple.com> 2 3 Add enum traits and use them in the IPC::Decoder 4 https://bugs.webkit.org/show_bug.cgi?id=161103 5 6 Reviewed by Sam Weinig. 7 8 Add API test. 9 10 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 11 * TestWebKitAPI/Tests/WTF/EnumTraits.cpp: Added. 12 (TestWebKitAPI::TEST): 13 1 14 2016-08-24 Filip Pizlo <fpizlo@apple.com> 2 15 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r204909 r204916 36 36 1ADBEFE3130C6AA100D61D19 /* simple-accelerated-compositing.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1ADBEFBC130C6A0100D61D19 /* simple-accelerated-compositing.html */; }; 37 37 1AEDE22613E5E7E700E62FE8 /* InjectedBundleControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */; }; 38 1AF7B21F1D6CD14D008C126C /* EnumTraits.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AF7B21D1D6CD12E008C126C /* EnumTraits.cpp */; }; 38 39 1C2B81801C891E7C00A5529F /* CancelFontSubresource.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C2B817E1C891E4200A5529F /* CancelFontSubresource.mm */; }; 39 40 1C2B81831C891F0900A5529F /* CancelFontSubresourcePlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C2B81811C891EFA00A5529F /* CancelFontSubresourcePlugIn.mm */; }; … … 679 680 1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InjectedBundleControllerMac.mm; sourceTree = "<group>"; }; 680 681 1AEF994817A09F5300998EF0 /* GetPIDAfterAbortedProcessLaunch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetPIDAfterAbortedProcessLaunch.cpp; sourceTree = "<group>"; }; 682 1AF7B21D1D6CD12E008C126C /* EnumTraits.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = EnumTraits.cpp; sourceTree = "<group>"; }; 681 683 1AFDE6541953B2C000C48FFA /* Optional.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Optional.cpp; sourceTree = "<group>"; }; 682 684 1C2B817E1C891E4200A5529F /* CancelFontSubresource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CancelFontSubresource.mm; sourceTree = "<group>"; }; … … 1622 1624 1A3524A91D627BD40031729B /* DeletedAddressOfOperator.h */, 1623 1625 E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */, 1626 1AF7B21D1D6CD12E008C126C /* EnumTraits.cpp */, 1624 1627 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */, 1625 1628 0BCD833414857CE400EA2003 /* HashMap.cpp */, … … 2117 2120 7C83DF1D1D0A590C00FEBCF3 /* Lock.cpp in Sources */, 2118 2121 7C83DEED1D0A590C00FEBCF3 /* MathExtras.cpp in Sources */, 2122 1AF7B21F1D6CD14D008C126C /* EnumTraits.cpp in Sources */, 2119 2123 7C83DEEF1D0A590C00FEBCF3 /* MD5.cpp in Sources */, 2120 2124 7C83DEF11D0A590C00FEBCF3 /* MediaTime.cpp in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.