Title: [192177] trunk/Source
Revision
192177
Author
ander...@apple.com
Date
2015-11-09 14:00:31 -0800 (Mon, 09 Nov 2015)

Log Message

Introspect reply block types as well
https://bugs.webkit.org/show_bug.cgi?id=151048

Reviewed by Tim Horton.

Source/WebKit2:

* Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
(initializeMethod):
(initializeMethods):
(-[_WKRemoteObjectInterface debugDescription]):

Source/WTF:

Fix operator-> implementation.

* wtf/Optional.h:
(WTF::Optional::operator->):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (192176 => 192177)


--- trunk/Source/WTF/ChangeLog	2015-11-09 21:50:46 UTC (rev 192176)
+++ trunk/Source/WTF/ChangeLog	2015-11-09 22:00:31 UTC (rev 192177)
@@ -1,3 +1,15 @@
+2015-11-09  Anders Carlsson  <ander...@apple.com>
+
+        Introspect reply block types as well
+        https://bugs.webkit.org/show_bug.cgi?id=151048
+
+        Reviewed by Tim Horton.
+
+        Fix operator-> implementation.
+
+        * wtf/Optional.h:
+        (WTF::Optional::operator->):
+
 2015-11-05  Nikos Andronikos  <nikos.andronikos-web...@cisra.canon.com.au>
 
         Add runtime and compile time flags for enabling Web Animations API and model.

Modified: trunk/Source/WTF/wtf/Optional.h (192176 => 192177)


--- trunk/Source/WTF/wtf/Optional.h	2015-11-09 21:50:46 UTC (rev 192176)
+++ trunk/Source/WTF/wtf/Optional.h	2015-11-09 22:00:31 UTC (rev 192177)
@@ -136,13 +136,13 @@
     const T* operator->() const
     {
         ASSERT(m_isEngaged);
-        return asPtr()->operator->();
+        return asPtr();
     }
 
     T* operator->()
     {
         ASSERT(m_isEngaged);
-        return asPtr()->operator->();
+        return asPtr();
     }
 
     const T& operator*() const { return value(); }

Modified: trunk/Source/WebKit2/ChangeLog (192176 => 192177)


--- trunk/Source/WebKit2/ChangeLog	2015-11-09 21:50:46 UTC (rev 192176)
+++ trunk/Source/WebKit2/ChangeLog	2015-11-09 22:00:31 UTC (rev 192177)
@@ -1,5 +1,17 @@
 2015-11-09  Anders Carlsson  <ander...@apple.com>
 
+        Introspect reply block types as well
+        https://bugs.webkit.org/show_bug.cgi?id=151048
+
+        Reviewed by Tim Horton.
+
+        * Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
+        (initializeMethod):
+        (initializeMethods):
+        (-[_WKRemoteObjectInterface debugDescription]):
+
+2015-11-09  Anders Carlsson  <ander...@apple.com>
+
         Implement -[_WKRemoteObjectInterface debugDescription] and have it look like the NSXPCInterface equivalent
         https://bugs.webkit.org/show_bug.cgi?id=151044
 

Modified: trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm (192176 => 192177)


--- trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm	2015-11-09 21:50:46 UTC (rev 192176)
+++ trunk/Source/WebKit2/Shared/API/Cocoa/_WKRemoteObjectInterface.mm	2015-11-09 22:00:31 UTC (rev 192177)
@@ -31,6 +31,7 @@
 #import <objc/runtime.h>
 #import <wtf/HashMap.h>
 #import <wtf/NeverDestroyed.h>
+#import <wtf/Optional.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Vector.h>
 #import <wtf/text/CString.h>
@@ -39,13 +40,20 @@
 const char *_protocol_getMethodTypeEncoding(Protocol *p, SEL sel, BOOL isRequiredMethod, BOOL isInstanceMethod);
 
 @interface NSMethodSignature ()
+- (NSMethodSignature *)_signatureForBlockAtArgumentIndex:(NSInteger)idx;
 - (Class)_classForObjectAtArgumentIndex:(NSInteger)idx;
+- (NSString *)_typeString;
 @end
 
 struct MethodInfo {
     Vector<HashSet<Class>> allowedArgumentClasses;
 
-    // FIXME: This should have allowed reply argument classes too.
+    struct ReplyInfo {
+        NSUInteger replyPosition;
+        CString replySignature;
+        Vector<HashSet<Class>> allowedReplyClasses;
+    };
+    Optional<ReplyInfo> replyInfo;
 };
 
 @implementation _WKRemoteObjectInterface {
@@ -77,13 +85,14 @@
     return propertyListClasses;
 }
 
-static void initializeMethod(MethodInfo& methodInfo, NSMethodSignature *methodSignature, bool forReplyBlock)
+static void initializeMethod(MethodInfo& methodInfo, Protocol *protocol, SEL selector, NSMethodSignature *methodSignature, bool forReplyBlock)
 {
     Vector<HashSet<Class>> allowedClasses;
 
     NSUInteger firstArgument = forReplyBlock ? 1 : 2;
     NSUInteger argumentCount = methodSignature.numberOfArguments;
 
+    bool foundBlock = false;
     for (NSUInteger i = firstArgument; i < argumentCount; ++i) {
         const char* argumentType = [methodSignature getArgumentTypeAtIndex:i];
 
@@ -93,6 +102,23 @@
             continue;
         }
 
+        if (*(argumentType + 1) == '?') {
+            if (forReplyBlock)
+                [NSException raise:NSInvalidArgumentException format:@"Blocks as arguments to the reply block of method (%s / %s) are not allowed", protocol_getName(protocol), sel_getName(selector)];
+
+            if (foundBlock)
+                [NSException raise:NSInvalidArgumentException format:@"Only one reply block is allowed per method (%s / %s)", protocol_getName(protocol), sel_getName(selector)];
+            foundBlock = true;
+            NSMethodSignature *blockSignature = [methodSignature _signatureForBlockAtArgumentIndex:i];
+            ASSERT(blockSignature._typeString);
+
+            methodInfo.replyInfo = MethodInfo::ReplyInfo();
+            methodInfo.replyInfo->replyPosition = i;
+            methodInfo.replyInfo->replySignature = blockSignature._typeString.UTF8String;
+
+            initializeMethod(methodInfo, protocol, selector, blockSignature, true);
+        }
+
         Class objectClass = [methodSignature _classForObjectAtArgumentIndex:i];
         if (!objectClass) {
             allowedClasses.append({ });
@@ -108,7 +134,10 @@
         allowedClasses.append({ objectClass });
     }
 
-    methodInfo.allowedArgumentClasses = WTF::move(allowedClasses);
+    if (forReplyBlock)
+        methodInfo.replyInfo->allowedReplyClasses = WTF::move(allowedClasses);
+    else
+        methodInfo.allowedArgumentClasses = WTF::move(allowedClasses);
 }
 
 static void initializeMethods(_WKRemoteObjectInterface *interface, Protocol *protocol, bool requiredMethods)
@@ -128,7 +157,7 @@
 
         NSMethodSignature *methodSignature = [NSMethodSignature signatureWithObjCTypes:methodTypeEncoding];
 
-        initializeMethod(methodInfo, methodSignature, false);
+        initializeMethod(methodInfo, protocol, selector, methodSignature, false);
     }
 
     free(methods);
@@ -220,9 +249,13 @@
         return result.autorelease();
     };
 
-    for (auto& selectorAndMethod : _methods)
+    for (auto& selectorAndMethod : _methods) {
         [result appendFormat:@" selector = %s\n  argument classes = %@\n", sel_getName(selectorAndMethod.key), descriptionForClasses(selectorAndMethod.value.allowedArgumentClasses)];
 
+        if (auto replyInfo = selectorAndMethod.value.replyInfo)
+            [result appendFormat:@"  reply block = (argument #%lu '%s') %@\n", static_cast<unsigned long>(replyInfo->replyPosition), replyInfo->replySignature.data(), descriptionForClasses(replyInfo->allowedReplyClasses)];
+    }
+
     [result appendString:@">\n"];
     return result.autorelease();
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to