Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1120)

Unified Diff: runtime/vm/parser.cc

Issue 9416067: Fix cacthing exception object: a null exception is always caught. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 4404)
+++ runtime/vm/parser.cc (working copy)
@@ -4845,11 +4845,13 @@
// operator.
bool catch_seen = false;
bool generic_catch_seen = false;
+ intptr_t catch_clause_count = 0;
SequenceNode* catch_handler_list = NULL;
const intptr_t handler_pos = token_index_;
OpenBlock(); // Start the catch block sequence.
current_block_->scope->AddLabel(end_catch_label);
while (CurrentToken() == Token::kCATCH) {
+ catch_clause_count++;
catch_seen = true;
const intptr_t catch_pos = token_index_;
ConsumeToken(); // Consume the 'catch'.
@@ -4920,10 +4922,22 @@
}
AstNode* exception_type = new TypeNode(catch_pos, *exception_param.type);
AstNode* exception_var = new LoadLocalNode(catch_pos, *catch_excp_var);
- AstNode* cond_expr = new ComparisonNode(
+ AstNode* type_cond_expr = new ComparisonNode(
catch_pos, Token::kIS, exception_var, exception_type);
- current_block_->statements->Add(
- new IfNode(catch_pos, cond_expr, catch_handler, NULL));
+ if (catch_clause_count == 1) {
+ // Null is also allowed, but check only in the first clause.
+ AstNode* null_literal =
+ new LiteralNode(catch_pos, Instance::ZoneHandle(Instance::null()));
+ AstNode* null_cond_expr = new ComparisonNode(
+ catch_pos, Token::kEQ_STRICT, exception_var, null_literal);
+ AstNode* or_node = new BinaryOpNode(
+ catch_pos, Token::kOR, null_cond_expr, type_cond_expr);
+ current_block_->statements->Add(
+ new IfNode(catch_pos, or_node, catch_handler, NULL));
+ } else {
+ current_block_->statements->Add(
+ new IfNode(catch_pos, type_cond_expr, catch_handler, NULL));
+ }
} else {
// No exception type exists in the catch specifier so execute the
// catch handler code unconditionally.
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698