Title: [260112] trunk/Source/WebKit
Revision
260112
Author
ddkil...@apple.com
Date
2020-04-14 18:24:30 -0700 (Tue, 14 Apr 2020)

Log Message

dictionaryValueOfType() in WebCoreArgumentCodersMac.mm can be replaced with dynamic_cf_cast<>()
<https://webkit.org/b/210456>

Reviewed by Darin Adler.

* Shared/mac/WebCoreArgumentCodersMac.mm:
(IPC::dictionaryValueOfType): Delete.
(IPC::extractDictionaryValue): Add.
- Use dynamic_cf_cast<>() in place of manually checking the
  CFTypeID of each object.
(IPC::createArchiveList):
- Call new extractDictionaryValue() template function to verify
  values are the correct types in the dictionary and to set the
  output variables.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (260111 => 260112)


--- trunk/Source/WebKit/ChangeLog	2020-04-15 01:08:31 UTC (rev 260111)
+++ trunk/Source/WebKit/ChangeLog	2020-04-15 01:24:30 UTC (rev 260112)
@@ -1,5 +1,22 @@
 2020-04-14  David Kilzer  <ddkil...@apple.com>
 
+        dictionaryValueOfType() in WebCoreArgumentCodersMac.mm can be replaced with dynamic_cf_cast<>()
+        <https://webkit.org/b/210456>
+
+        Reviewed by Darin Adler.
+
+        * Shared/mac/WebCoreArgumentCodersMac.mm:
+        (IPC::dictionaryValueOfType): Delete.
+        (IPC::extractDictionaryValue): Add.
+        - Use dynamic_cf_cast<>() in place of manually checking the
+          CFTypeID of each object.
+        (IPC::createArchiveList):
+        - Call new extractDictionaryValue() template function to verify
+          values are the correct types in the dictionary and to set the
+          output variables.
+
+2020-04-14  David Kilzer  <ddkil...@apple.com>
+
         Use CFArrayGetValues() in createArchiveList() in WebCoreArgumentCodersMac.mm
         <https://webkit.org/b/210519>
 

Modified: trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm (260111 => 260112)


--- trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm	2020-04-15 01:08:31 UTC (rev 260111)
+++ trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm	2020-04-15 01:24:30 UTC (rev 260112)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2013 Company 100 Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,7 @@
 #import <WebCore/SerializedPlatformDataCueMac.h>
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <wtf/MachSendRight.h>
+#import <wtf/cf/TypeCastsCF.h>
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
 #import <WebCore/MediaPlaybackTargetContext.h>
@@ -91,17 +92,20 @@
     return dictionary;
 }
 
-static CFTypeRef dictionaryValueOfType(CFDictionaryRef dictionary, CFStringRef key, CFTypeID type)
+template<typename ValueType> bool extractDictionaryValue(CFDictionaryRef dictionary, CFStringRef key, ValueType* result)
 {
-    CFTypeRef value = CFDictionaryGetValue(dictionary, key);
-    if (value && CFGetTypeID(value) == type)
-        return value;
-    return nullptr;
+    auto untypedValue = CFDictionaryGetValue(dictionary, key);
+    auto value = dynamic_cf_cast<ValueType>(untypedValue);
+    if (untypedValue && !value)
+        return false;
+    if (result)
+        *result = value;
+    return true;
 }
 
 static bool createArchiveList(CFDictionaryRef representation, CFTypeRef tokenNull, CFIndex* version, CFTypeRef** objects, CFIndex* objectCount, CFDictionaryRef* protocolProperties, CFNumberRef* expectedContentLength, CFStringRef* mimeType)
 {
-    CFNumberRef versionNumber = (CFNumberRef)dictionaryValueOfType(representation, CFSTR("version"), CFNumberGetTypeID());
+    auto versionNumber = dynamic_cf_cast<CFNumberRef>(CFDictionaryGetValue(representation, CFSTR("version")));
     if (!versionNumber)
         return false;
 
@@ -108,7 +112,7 @@
     if (!CFNumberGetValue(versionNumber, kCFNumberCFIndexType, version))
         return false;
 
-    CFArrayRef archiveListArray = (CFArrayRef)dictionaryValueOfType(representation, CFSTR("archiveList"), CFArrayGetTypeID());
+    auto archiveListArray = dynamic_cf_cast<CFArrayRef>(CFDictionaryGetValue(representation, CFSTR("archiveList")));
     if (!archiveListArray)
         return false;
 
@@ -129,15 +133,13 @@
             (*objects)[i] = nullptr;
     }
 
-    if (protocolProperties)
-        *protocolProperties = (CFDictionaryRef)dictionaryValueOfType(representation, CFSTR("protocolProperties"), CFDictionaryGetTypeID());
+    if (!extractDictionaryValue(representation, CFSTR("protocolProperties"), protocolProperties))
+        return false;
+    if (!extractDictionaryValue(representation, CFSTR("expectedContentLength"), expectedContentLength))
+        return false;
+    if (!extractDictionaryValue(representation, CFSTR("mimeType"), mimeType))
+        return false;
 
-    if (expectedContentLength)
-        *expectedContentLength = (CFNumberRef)dictionaryValueOfType(representation, CFSTR("expectedContentLength"), CFNumberGetTypeID());
-
-    if (mimeType)
-        *mimeType = (CFStringRef)dictionaryValueOfType(representation, CFSTR("mimeType"), CFStringGetTypeID());
-
     return true;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to