Use auto for some of our lambda function parameters
[WebKit-https.git] / Source / WebKit2 / Shared / API / Cocoa / _WKRemoteObjectInterface.mm
index cf07fa9..b0da4b6 100644 (file)
@@ -98,7 +98,7 @@ static void initializeMethod(MethodInfo& methodInfo, Protocol *protocol, SEL sel
 
         if (*argumentType != '@') {
             // This is a non-object type; we won't allow any classes to be decoded for it.
-            allowedClasses.uncheckedAppend({ });
+            allowedClasses.append({ });
             continue;
         }
 
@@ -135,9 +135,9 @@ static void initializeMethod(MethodInfo& methodInfo, Protocol *protocol, SEL sel
     }
 
     if (forReplyBlock)
-        methodInfo.replyInfo->allowedReplyClasses = WTF::move(allowedClasses);
+        methodInfo.replyInfo->allowedReplyClasses = WTFMove(allowedClasses);
     else
-        methodInfo.allowedArgumentClasses = WTF::move(allowedClasses);
+        methodInfo.allowedArgumentClasses = WTFMove(allowedClasses);
 }
 
 static void initializeMethods(_WKRemoteObjectInterface *interface, Protocol *protocol, bool requiredMethods)
@@ -210,11 +210,11 @@ static void initializeMethods(_WKRemoteObjectInterface *interface, Protocol *pro
 {
     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 descriptionForClasses = [](auto& allowedClasses) {
         auto result = adoptNS([[NSMutableString alloc] initWithString:@"["]);
         bool needsComma = false;
 
-        auto descriptionForArgument = [](const HashSet<Class>& allowedArgumentClasses) {
+        auto descriptionForArgument = [](auto& allowedArgumentClasses) {
             auto result = adoptNS([[NSMutableString alloc] initWithString:@"{"]);
 
             Vector<Class> orderedArgumentClasses;
@@ -260,38 +260,56 @@ static void initializeMethods(_WKRemoteObjectInterface *interface, Protocol *pro
     return result.autorelease();
 }
 
-static HashSet<Class>& classesForSelectorArgument(_WKRemoteObjectInterface *interface, SEL selector, NSUInteger argumentIndex)
+static HashSet<Class>& classesForSelectorArgument(_WKRemoteObjectInterface *interface, SEL selector, NSUInteger argumentIndex, bool replyBlock)
 {
     auto it = interface->_methods.find(selector);
     if (it == interface->_methods.end())
         [NSException raise:NSInvalidArgumentException format:@"Interface does not contain selector \"%s\"", sel_getName(selector)];
 
     MethodInfo& methodInfo = it->value;
-    auto& allowedArgumentClasses = methodInfo.allowedArgumentClasses;
+    if (replyBlock) {
+        if (!methodInfo.replyInfo)
+            [NSException raise:NSInvalidArgumentException format:@"Selector \"%s\" does not have a reply block", sel_getName(selector)];
+
+        if (argumentIndex >= methodInfo.replyInfo->allowedReplyClasses.size())
+            [NSException raise:NSInvalidArgumentException format:@"Argument index %ld is out of range for reply block of selector \"%s\"", (unsigned long)argumentIndex, sel_getName(selector)];
+
+        return methodInfo.replyInfo->allowedReplyClasses[argumentIndex];
+    }
 
-    if (argumentIndex >= allowedArgumentClasses.size())
+    if (argumentIndex >= methodInfo.allowedArgumentClasses.size())
         [NSException raise:NSInvalidArgumentException format:@"Argument index %ld is out of range for selector \"%s\"", (unsigned long)argumentIndex, sel_getName(selector)];
 
-    return allowedArgumentClasses[argumentIndex];
+    return methodInfo.allowedArgumentClasses[argumentIndex];
 }
 
-- (NSSet *)classesForSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
+- (NSSet *)classesForSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex ofReply:(BOOL)ofReply
 {
     auto result = adoptNS([[NSMutableSet alloc] init]);
 
-    for (auto allowedClass : classesForSelectorArgument(self, selector, argumentIndex))
+    for (auto allowedClass : classesForSelectorArgument(self, selector, argumentIndex, ofReply))
         [result addObject:allowedClass];
 
     return result.autorelease();
 }
 
-- (void)setClasses:(NSSet *)classes forSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
+- (void)setClasses:(NSSet *)classes forSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex ofReply:(BOOL)ofReply
 {
     HashSet<Class> allowedClasses;
     for (Class allowedClass in classes)
         allowedClasses.add(allowedClass);
 
-    classesForSelectorArgument(self, selector, argumentIndex) = WTF::move(allowedClasses);
+    classesForSelectorArgument(self, selector, argumentIndex, ofReply) = WTFMove(allowedClasses);
+}
+
+- (NSSet *)classesForSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
+{
+    return [self classesForSelector:selector argumentIndex:argumentIndex ofReply:NO];
+}
+
+- (void)setClasses:(NSSet *)classes forSelector:(SEL)selector argumentIndex:(NSUInteger)argumentIndex
+{
+    [self setClasses:classes forSelector:selector argumentIndex:argumentIndex ofReply:NO];
 }
 
 static const char* methodArgumentTypeEncodingForSelector(Protocol *protocol, SEL selector)
@@ -311,6 +329,9 @@ static const char* methodArgumentTypeEncodingForSelector(Protocol *protocol, SEL
 
 - (NSMethodSignature *)_methodSignatureForSelector:(SEL)selector
 {
+    if (!_methods.contains(selector))
+        return nil;
+
     const char* types = methodArgumentTypeEncodingForSelector(_protocol, selector);
     if (!types)
         return nil;
@@ -318,6 +339,19 @@ static const char* methodArgumentTypeEncodingForSelector(Protocol *protocol, SEL
     return [NSMethodSignature signatureWithObjCTypes:types];
 }
 
+- (NSMethodSignature *)_methodSignatureForReplyBlockOfSelector:(SEL)selector
+{
+    auto it = _methods.find(selector);
+    if (it  == _methods.end())
+        return nil;
+
+    auto& methodInfo = it->value;
+    if (!methodInfo.replyInfo)
+        return nil;
+
+    return [NSMethodSignature signatureWithObjCTypes:methodInfo.replyInfo->replySignature.data()];
+}
+
 - (const Vector<HashSet<Class>>&)_allowedArgumentClassesForSelector:(SEL)selector
 {
     ASSERT(_methods.contains(selector));
@@ -325,6 +359,13 @@ static const char* methodArgumentTypeEncodingForSelector(Protocol *protocol, SEL
     return _methods.find(selector)->value.allowedArgumentClasses;
 }
 
+- (const Vector<HashSet<Class>>&)_allowedArgumentClassesForReplyBlockOfSelector:(SEL)selector
+{
+    ASSERT(_methods.contains(selector));
+
+    return _methods.find(selector)->value.replyInfo->allowedReplyClasses;
+}
+
 @end
 
 #endif // WK_API_ENABLED