Changeset 3450
- Timestamp:
- 12/10/06 13:26:55 (2 years ago)
- Files:
-
- trunk/Models/JVChatEvent.m (modified) (1 diff)
- trunk/Models/JVChatMessage.m (modified) (1 diff)
- trunk/Plug-Ins/JavaScript Support/JVJavaScriptChatPlugin.h (modified) (3 diffs)
- trunk/Plug-Ins/JavaScript Support/JVJavaScriptChatPlugin.m (modified) (3 diffs)
- trunk/Plug-Ins/JavaScript Support/plugin.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Models/JVChatEvent.m
r3345 r3450 246 246 247 247 - (id) init { 248 if( ( self = [super init] ) ) _doc = NULL; 249 return self; 250 } 251 252 - (id) initWithName:(NSString *) name andMessage:(id) message { 253 if( ( self = [self init] ) ) { 248 if( ( self = [super init] ) ) { 254 249 _loadedMessage = YES; 255 250 _loadedAttributes = YES; 256 251 _loadedSmall = YES; 257 252 [self setDate:[NSDate date]]; 253 [self setEventIdentifier:[NSString locallyUniqueString]]; 254 } 255 256 return self; 257 } 258 259 - (id) initWithName:(NSString *) name andMessage:(id) message { 260 if( ( self = [self init] ) ) { 258 261 [self setName:name]; 259 262 [self setMessage:message]; 260 [self setEventIdentifier:[NSString locallyUniqueString]];261 263 } 262 264 trunk/Models/JVChatMessage.m
r3259 r3450 382 382 #pragma mark - 383 383 384 - (id) init WithText:(id) body sender:(id) sender{385 if( ( self = [s elfinit] ) ) {384 - (id) init { 385 if( ( self = [super init] ) ) { 386 386 _loaded = YES; 387 387 _bodyLoaded = YES; 388 388 _senderLoaded = YES; 389 389 [self setDate:[NSDate date]]; 390 [self setMessageIdentifier:[NSString locallyUniqueString]]; 391 } 392 393 return self; 394 } 395 396 - (id) initWithText:(id) body sender:(id) sender { 397 if( ( self = [self init] ) ) { 390 398 [self setBody:body]; 391 399 [self setSender:sender]; 392 [self setMessageIdentifier:[NSString locallyUniqueString]];393 400 } 394 401 trunk/Plug-Ins/JavaScript Support/JVJavaScriptChatPlugin.h
r3439 r3450 3 3 extern NSString *JVJavaScriptErrorDomain; 4 4 5 @class WebScriptCallFrame; 5 6 @class WebView; 6 7 … … 11 12 WebView *_webview; 12 13 NSString *_currentFunction; 14 id _currentException; 13 15 BOOL _loading; 14 16 } … … 21 23 - (void) setupScriptGlobalsForWebView:(WebView *) webView; 22 24 25 - (void) reportErrorForCallFrame:(WebScriptCallFrame *) frame lineNumber:(unsigned int) line; 23 26 - (void) reportError:(NSDictionary *) error inFunction:(NSString *) functionName whileLoading:(BOOL) whileLoading; 24 27 - (id) callScriptFunctionNamed:(NSString *) functionName withArguments:(NSArray *) arguments forSelector:(SEL) selector; trunk/Plug-Ins/JavaScript Support/JVJavaScriptChatPlugin.m
r3449 r3450 216 216 } 217 217 218 - (void) webView:(WebView *) sender didEnterCallFrame:(WebScriptCallFrame *) frame sourceId:(int) sid line:(int) line forWebFrame:(WebFrame *) webFrame { 219 [_currentException release]; 220 _currentException = nil; 221 } 222 218 223 - (void) webView:(WebView *) sender willLeaveCallFrame:(WebScriptCallFrame *) frame sourceId:(int) sid line:(int) line forWebFrame:(WebFrame *) webFrame { 219 if( ! [[frame userInfo] isEqual:@"handled"] && [frame exception] ) { 220 id exception = [frame exception]; 221 NSString *sourceURL = nil; 222 @try { 223 sourceURL = [exception valueForKey:@"sourceURL"]; 224 } @catch( NSException *e ) { 225 sourceURL = nil; 226 } 227 228 NSDictionary *error = [[NSDictionary allocWithZone:nil] initWithObjectsAndKeys:[exception valueForKey:@"message"], @"message", [exception valueForKey:@"line"], @"lineNumber", sourceURL, @"sourceURL", nil]; 229 [self reportError:error inFunction:_currentFunction whileLoading:_loading]; 230 [error release]; 231 } 224 if( [frame exception] ) [self reportErrorForCallFrame:frame lineNumber:line]; 232 225 } 233 226 234 227 - (void) webView:(WebView *) sender exceptionWasRaised:(WebScriptCallFrame *) frame sourceId:(int) sid line:(int) line forWebFrame:(WebFrame *) webFrame { 235 [frame setUserInfo:@"handled"]; 236 237 id exception = [frame exception]; 238 NSString *sourceURL = nil; 239 @try { 240 sourceURL = [exception valueForKey:@"sourceURL"]; 241 } @catch( NSException *e ) { 242 sourceURL = nil; 243 } 244 245 NSDictionary *error = [[NSDictionary allocWithZone:nil] initWithObjectsAndKeys:[exception valueForKey:@"message"], @"message", [exception valueForKey:@"line"], @"lineNumber", sourceURL, @"sourceURL", nil]; 246 [self reportError:error inFunction:_currentFunction whileLoading:_loading]; 247 [error release]; 228 if( [frame exception] ) [self reportErrorForCallFrame:frame lineNumber:line]; 248 229 } 249 230 … … 264 245 265 246 - (id) allocInstance:(NSString *) class { 266 return [ NSClassFromString(class) allocWithZone:nil];247 return [[NSClassFromString(class) allocWithZone:nil] autorelease]; 267 248 } 268 249 … … 324 305 #pragma mark - 325 306 307 - (void) reportErrorForCallFrame:(WebScriptCallFrame *) frame lineNumber:(unsigned int) line { 308 id handled = nil; 309 id exception = [frame exception]; 310 @try { handled = [exception valueForKey:@"handled"]; } @catch( NSException *e ) { handled = nil; } 311 312 if( exception && ! handled && ! [_currentException isEqual:exception] ) { 313 [_currentException release]; 314 _currentException = [exception retain]; 315 316 NSNumber *lineNumber = ( line ? [NSNumber numberWithUnsignedInt:line] : nil ); 317 NSString *sourceURL = nil; 318 NSString *message = exception; 319 320 if( [exception isKindOfClass:[WebScriptObject class]] ) { 321 [exception setValue:[NSNumber numberWithBool:YES] forKey:@"handled"]; 322 323 @try { lineNumber = [exception valueForKey:@"line"]; } @catch( NSException *e ) { lineNumber = nil; } 324 @try { sourceURL = [exception valueForKey:@"sourceURL"]; } @catch( NSException *e ) { sourceURL = nil; } 325 @try { message = [exception valueForKey:@"message"]; } @catch( NSException *e ) { message = exception; } 326 } 327 328 NSDictionary *error = [[NSDictionary allocWithZone:nil] initWithObjectsAndKeys:message, @"message", lineNumber, @"lineNumber", sourceURL, @"sourceURL", nil]; 329 [self reportError:error inFunction:_currentFunction whileLoading:_loading]; 330 [error release]; 331 } 332 } 333 326 334 - (void) reportError:(NSDictionary *) error inFunction:(NSString *) functionName whileLoading:(BOOL) whileLoading { 327 335 NSMutableString *errorDesc = [[NSMutableString alloc] initWithCapacity:64]; trunk/Plug-Ins/JavaScript Support/plugin.html
r3449 r3450 5 5 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 6 6 <script> 7 String.prototype.fourCharCode = function() { 8 var result = 0; 9 var spaceCode = ' '.charCodeAt(0); 10 11 if( this.length >= 1 ) result |= ( this.charCodeAt(0) & 0x00ff ) << 24; 12 else result |= spaceCode << 24; 13 14 if( this.length >= 2 ) result |= ( this.charCodeAt(1) & 0x00ff ) << 16; 15 else result |= spaceCode << 16; 16 17 if( this.length >= 3 ) result |= ( this.charCodeAt(2) & 0x00ff ) << 8; 18 else result |= spaceCode << 8; 19 20 if( this.length >= 4 ) result |= ( this.charCodeAt(3) & 0x00ff ); 21 else result |= spaceCode; 22 23 return result; 24 } 25 26 JVChatMessageNormalType = 'noMt'.fourCharCode(); 27 JVChatMessageNoticeType = 'nTMt'.fourCharCode(); 28 29 function JVChatMessage() { 30 throw "Can't create a JVChatMessage directly, use JVMutableChatMessage."; 31 } 32 7 33 function JVMutableChatMessage(text, sender) { 8 34 var obj = Plugin.allocInstance('JVMutableChatMessage'); 9 return obj.initWithText(text, sender); 35 if( text !== undefined && sender !== undefined ) 36 return obj.initWithText(text, sender); 37 return obj.init(); 38 } 39 40 function JVChatEvent() { 41 throw "Can't create a JVChatEvent directly, use JVMutableChatEvent."; 42 } 43 44 function JVMutableChatEvent(name, message) { 45 var obj = Plugin.allocInstance('JVMutableChatEvent'); 46 if( name !== undefined && message !== undefined ) 47 return obj.initWithName(name, message); 48 return obj.init(); 10 49 } 11 50 </script>
