Skip to content

Commit

Permalink
Simplify no-handler case: throw exception any time there is no handle…
Browse files Browse the repository at this point in the history
…r for a message. Similarly, let runtime exceptions inside handlers bubble up and be caught by webkit instead of simply logging them in WVJB. References GH PR marcuswestin#97
  • Loading branch information
marcuswestin committed Aug 27, 2014
1 parent c8e4234 commit 9294201
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions WebViewJavascriptBridge/WebViewJavascriptBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,15 @@ - (void)_flushMessageQueue {
WVJBHandler handler;
if (message[@"handlerName"]) {
handler = _messageHandlers[message[@"handlerName"]];
if (!handler) {
NSLog(@"WVJB Warning: No handler for %@", message[@"handlerName"]);
return responseCallback(@{});
}
} else {
handler = _messageHandler;
if (!handler) {
NSLog(@"WVJB Warning: No handler for message from JS: %@", message);
return responseCallback(@{});
}
}

@try {
id data = message[@"data"];
handler(data, responseCallback);
}
@catch (NSException *exception) {
NSLog(@"WebViewJavascriptBridge: WARNING: objc handler threw. %@ %@", message, exception);

if (!handler) {
[NSException raise:@"WVJBNoHandlerException" format:@"No handler for message from JS: %@", message];
}

handler(message[@"data"], responseCallback);
}
}
}
Expand Down

0 comments on commit 9294201

Please sign in to comment.