From eb443a99b9a7b32ccce4b5ab1e70fa5aad6b1f61 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 14 Jan 2011 12:17:11 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20'suppressExceptionAlert'=20JavaScri?= =?UTF-8?q?pt=20function=20for=20window.system=20bridge;=20if=20called=20J?= =?UTF-8?q?S=20exceptions=20won't=20be=20alerted=20instead=20written=20to?= =?UTF-8?q?=20Console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPBundleHTMLOutputController.h | 2 ++ Source/SPBundleHTMLOutputController.m | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Source/SPBundleHTMLOutputController.h b/Source/SPBundleHTMLOutputController.h index ea0b96da..3665fc8e 100644 --- a/Source/SPBundleHTMLOutputController.h +++ b/Source/SPBundleHTMLOutputController.h @@ -33,6 +33,7 @@ NSString *initHTMLSourceString; NSString *windowUUID; NSString *docUUID; + BOOL suppressExceptionAlert; WebPreferences *webPreferences; } @@ -41,6 +42,7 @@ @property(readwrite,retain) NSString *initHTMLSourceString; @property(readwrite,retain) NSString *windowUUID; @property(readwrite,retain) NSString *docUUID; +@property(assign) BOOL suppressExceptionAlert; - (IBAction)printDocument:(id)sender; diff --git a/Source/SPBundleHTMLOutputController.m b/Source/SPBundleHTMLOutputController.m index 12af6bcf..3c47964a 100644 --- a/Source/SPBundleHTMLOutputController.m +++ b/Source/SPBundleHTMLOutputController.m @@ -33,6 +33,7 @@ @synthesize initHTMLSourceString; @synthesize windowUUID; @synthesize docUUID; +@synthesize suppressExceptionAlert; /** * Initialisation @@ -50,6 +51,7 @@ [webView setEditable:NO]; [webView setShouldCloseWithWindow:YES]; [webView setShouldUpdateWhileOffscreen:NO]; + suppressExceptionAlert = NO; } @@ -374,6 +376,8 @@ return @"makeHTMLOutputWindowKeyWindow"; if (aSelector == @selector(closeHTMLOutputWindow)) return @"closeHTMLOutputWindow"; + if (aSelector == @selector(suppressExceptionAlert)) + return @"suppressExceptionAlert"; return @""; } @@ -399,6 +403,9 @@ if (selector == @selector(closeHTMLOutputWindow)) { return NO; } + if (selector == @selector(suppressExceptionAlert)) { + return NO; + } return YES; } @@ -440,8 +447,14 @@ - (void)webView:(WebView *)webView exceptionWasRaised:(WebScriptCallFrame *)frame sourceId:(NSInteger)sid line:(NSInteger)lineno forWebFrame:(WebFrame *)webFrame { + NSString *mes = [NSString stringWithFormat:@"Exception:\nline = %ld\nfunction = %@\ncaller = %@\nexception = %@", lineno, [frame functionName], [frame caller], [frame userInfo], [frame exception]]; + if([self suppressExceptionAlert]) { + NSLog(@"%@", mes); + return; + } + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"JavaScript Exception", @"javascript exception") defaultButton:NSLocalizedString(@"OK", @"OK button") alternateButton:nil @@ -524,6 +537,15 @@ NSBeep(); } +/** + * JavaScript window.system.suppressExceptionAlert() function + * to suppress an exception alert, instead write the message to NSLog + */ +- (void)suppressExceptionAlert +{ + [self setSuppressExceptionAlert:YES]; +} + /** * JavaScript window.system.run('a_command'|new Array('a_command', 'uuid')) function * to return the result of the BASH command a_command -- cgit v1.2.3