You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/11/23 03:19:34 UTC

ios commit: Add argument fetching helpers to CDVInvokedUrlCommand.

Updated Branches:
  refs/heads/master b8c57f10c -> d494d7c05


Add argument fetching helpers to CDVInvokedUrlCommand.

Should cut down on errors due to NSNull != nil.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/d494d7c0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/d494d7c0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/d494d7c0

Branch: refs/heads/master
Commit: d494d7c058b071d80b4fffd1e3786b1595e2cb5e
Parents: b8c57f1
Author: Andrew Grieve <ag...@chromium.org>
Authored: Thu Nov 22 21:18:46 2012 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Nov 22 21:18:46 2012 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVInvokedUrlCommand.h   |    7 +++++++
 CordovaLib/Classes/CDVInvokedUrlCommand.m   |   14 ++++++++++++++
 CordovaLibTests/CDVInvokedUrlCommandTests.m |   11 +++++++++++
 3 files changed, 32 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/d494d7c0/CordovaLib/Classes/CDVInvokedUrlCommand.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInvokedUrlCommand.h b/CordovaLib/Classes/CDVInvokedUrlCommand.h
index 15a1df6..178b749 100644
--- a/CordovaLib/Classes/CDVInvokedUrlCommand.h
+++ b/CordovaLib/Classes/CDVInvokedUrlCommand.h
@@ -45,4 +45,11 @@
 // dict removed from it.
 - (void)legacyArguments:(NSMutableArray**)legacyArguments andDict:(NSMutableDictionary**)legacyDict;
 
+// Returns the argument at the given index.
+// If index >= the number of arguments, returns nil.
+// If the argument at the given index is NSNull, returns nil.
+- (id)argumentAtIndex:(NSUInteger)index;
+// Same as above, but returns defaultValue instead of nil.
+- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue;
+
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/d494d7c0/CordovaLib/Classes/CDVInvokedUrlCommand.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInvokedUrlCommand.m b/CordovaLib/Classes/CDVInvokedUrlCommand.m
index fe67986..b8c7d1e 100644
--- a/CordovaLib/Classes/CDVInvokedUrlCommand.m
+++ b/CordovaLib/Classes/CDVInvokedUrlCommand.m
@@ -84,4 +84,18 @@
     }
 }
 
+- (id)argumentAtIndex:(NSUInteger)index {
+    return [self argumentAtIndex:index withDefault:nil];
+}
+
+- (id)argumentAtIndex:(NSUInteger)index withDefault:(id)defaultValue {
+    if (index >= [_arguments count]) {
+        return defaultValue;
+    }
+    id ret = [_arguments objectAtIndex:index];
+    if (ret == [NSNull null]) {
+        ret = defaultValue;
+    }
+    return ret;
+}
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/d494d7c0/CordovaLibTests/CDVInvokedUrlCommandTests.m
----------------------------------------------------------------------
diff --git a/CordovaLibTests/CDVInvokedUrlCommandTests.m b/CordovaLibTests/CDVInvokedUrlCommandTests.m
index a2366fb..5e0275f 100644
--- a/CordovaLibTests/CDVInvokedUrlCommandTests.m
+++ b/CordovaLibTests/CDVInvokedUrlCommandTests.m
@@ -93,4 +93,15 @@
     STAssertEqualObjects(expected, legacyArgs, nil);
 }
 
+- (void)testArgumentAtIndex
+{
+    NSArray* jsonArr = [NSArray arrayWithObjects:[NSNull null], @"className", @"methodName", [NSArray array], nil];
+    CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonArr];
+    STAssertNil([command argumentAtIndex:0], @"NSNull to nil");
+    STAssertNil([command argumentAtIndex:100], @"Invalid index to nil");
+    STAssertEquals(@"default", [command argumentAtIndex:0 withDefault:@"default"], @"NSNull to default");
+    STAssertEquals(@"default", [command argumentAtIndex:100 withDefault:@"default"], @"Invalid index to default");
+}
+
+
 @end