Implement -[_WKRemoteObjectInterface debugDescription] and have it look like the...
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Nov 2015 20:16:22 +0000 (20:16 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Nov 2015 20:16:22 +0000 (20:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151044

Reviewed by Tim Horton.

* Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
(-[_WKRemoteObjectInterface debugDescription]):
(-[_WKRemoteObjectInterface description]): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192171 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm

index 13d46f3..7e01264 100644 (file)
@@ -1,3 +1,14 @@
+2015-11-09  Anders Carlsson  <andersca@apple.com>
+
+        Implement -[_WKRemoteObjectInterface debugDescription] and have it look like the NSXPCInterface equivalent
+        https://bugs.webkit.org/show_bug.cgi?id=151044
+
+        Reviewed by Tim Horton.
+
+        * Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
+        (-[_WKRemoteObjectInterface debugDescription]):
+        (-[_WKRemoteObjectInterface description]): Deleted.
+
 2015-11-06  Anders Carlsson  <andersca@apple.com>
 
         Rework the way allowed argument classes are stored
index b72dfde..a8f4100 100644 (file)
 #import <wtf/NeverDestroyed.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Vector.h>
+#import <wtf/text/CString.h>
 
 extern "C"
 const char *_protocol_getMethodTypeEncoding(Protocol *p, SEL sel, BOOL isRequiredMethod, BOOL isInstanceMethod);
 
-@interface NSMethodSignature (WKDetails)
+@interface NSMethodSignature ()
 - (Class)_classForObjectAtArgumentIndex:(NSInteger)idx;
 @end
 
@@ -176,9 +177,54 @@ static void initializeMethods(_WKRemoteObjectInterface *interface, Protocol *pro
     return _identifier.get();
 }
 
-- (NSString *)description
+- (NSString *)debugDescription
 {
-    return [NSString stringWithFormat:@"<%@: %p; protocol = \"%@\"; identifier = \"%@\">", NSStringFromClass(self.class), self, _identifier.get(), NSStringFromProtocol(_protocol)];
+    auto result = adoptNS([[NSMutableString alloc] initWithFormat:@"<%@: %p; protocol = \"%@\"; identifier = \"%@\"\n", NSStringFromClass(self.class), self, _identifier.get(), NSStringFromProtocol(_protocol)]);
+
+    auto descriptionForClasses = [](const Vector<HashSet<Class>>& allowedClasses) {
+        auto result = adoptNS([[NSMutableString alloc] initWithString:@"["]);
+        bool needsComma = false;
+
+        auto descriptionForArgument = [](const HashSet<Class>& allowedArgumentClasses) {
+            auto result = adoptNS([[NSMutableString alloc] initWithString:@"{"]);
+
+            Vector<Class> orderedArgumentClasses;
+            copyToVector(allowedArgumentClasses, orderedArgumentClasses);
+
+            std::sort(orderedArgumentClasses.begin(), orderedArgumentClasses.end(), [](Class a, Class b) {
+                return CString(class_getName(a)) < CString(class_getName(b));
+            });
+
+            bool needsComma = false;
+            for (auto& argumentClass : orderedArgumentClasses) {
+                if (needsComma)
+                    [result appendString:@", "];
+
+                [result appendFormat:@"%s", class_getName(argumentClass)];
+                needsComma = true;
+            }
+
+            [result appendString:@"}"];
+            return result.autorelease();
+        };
+
+        for (auto& argumentClasses : allowedClasses) {
+            if (needsComma)
+                [result appendString:@", "];
+
+            [result appendString:descriptionForArgument(argumentClasses)];
+            needsComma = true;
+        }
+
+        [result appendString:@"]"];
+        return result.autorelease();
+    };
+
+    for (auto& selectorAndMethod : _methods)
+        [result appendFormat:@" selector = %s\n  argument classes = %@\n", sel_getName(selectorAndMethod.key), descriptionForClasses(selectorAndMethod.value.allowedArgumentClasses)];
+
+    [result appendString:@">\n"];
+    return result.autorelease();
 }
 
 static HashSet<Class>& classesForSelectorArgument(_WKRemoteObjectInterface *interface, SEL selector, NSUInteger argumentIndex)