Updated Branches: refs/heads/master 9ee4e6aab -> 7b4029766
CDVDebugWebView - handle non-exceptions being thrown Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/7b402976 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/7b402976 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/7b402976 Branch: refs/heads/master Commit: 7b40297668f7413e50cb72beab8d63a83c412dea Parents: 9ee4e6a Author: Shazron Abdullah <shaz...@apache.org> Authored: Tue May 1 04:49:53 2012 -0700 Committer: Shazron Abdullah <shaz...@apache.org> Committed: Tue May 1 04:49:53 2012 -0700 ---------------------------------------------------------------------- CordovaLib/Classes/debugview/CDVDebugWebView.m | 31 ++++++++++++++++-- 1 files changed, 27 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/7b402976/CordovaLib/Classes/debugview/CDVDebugWebView.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/debugview/CDVDebugWebView.m b/CordovaLib/Classes/debugview/CDVDebugWebView.m index 8714dd7..b0fbca6 100644 --- a/CordovaLib/Classes/debugview/CDVDebugWebView.m +++ b/CordovaLib/Classes/debugview/CDVDebugWebView.m @@ -139,16 +139,39 @@ forWebFrame:(WebFrame *)webFrame { WebScriptObject* exception = [frame exception]; // this is the bound JavaScript Error object which has two properties: name and message - // we use KVC to extract the name and message - NSString* exceptionName = [exception valueForKey:@"name"]; - NSString* exceptionMessage = [exception valueForKey:@"message"]; + + NSString *exceptionName, *exceptionMessage; + + if ([exception isKindOfClass:[NSString class]]) { + exceptionName = @"string"; + exceptionMessage = (NSString*)exception; + } else if ([exception isKindOfClass:[NSNumber class]]) { + exceptionName = @"number"; + exceptionMessage = [((NSNumber*)exception) stringValue]; + } + else { + // we use KVC to extract the name and message + @try { + exceptionName = [exception valueForKey:@"name"]; + exceptionMessage = [exception valueForKey:@"message"]; + } @catch (NSException* exc) { + if ([[exc name] isEqualToString:NSUndefinedKeyException]) { + exceptionName = @"type unknown"; + exceptionMessage = @"(not an exception object)"; + } + } + } CDVDebugWebSourceData* sourceData = [self.sourceDataDict objectForKey:[NSNumber numberWithInt:sid]]; + NSUInteger max_lines = [sourceData.sourceLines count]; + if (lineno > max_lines) { + lineno = max_lines; + } NSString* url = sourceData.fromURL? [sourceData trimFilePath] : @"obj-c"; NSString* line = [sourceData.sourceLines objectAtIndex:lineno-1]; - NSLog(@"JavaScript exception: (%@):%d - %@ - %@\n\tLine: %@", url, lineno, exceptionName, exceptionMessage, line); + NSLog(@"JavaScript exception: (%@):%d - %@ - %@\n\tFunction name: '%@'\tLine: '%@'", url, lineno, exceptionName, exceptionMessage, [frame functionName], line); } @end