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

Unified Diff: src/parsing/parser.cc

Issue 1842953003: Preserve exception message in iterator finalization. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index e3063d8b1fc251ddc5b493391e5fbb858ad097ad..ab19fd202f3373ff178b865501832308c8c8de60 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -3007,9 +3007,9 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
if (catch_block != NULL && finally_block != NULL) {
// If we have both, create an inner try/catch.
DCHECK(catch_scope != NULL && catch_variable != NULL);
- TryCatchStatement* statement =
- factory()->NewTryCatchStatement(try_block, catch_scope, catch_variable,
- catch_block, RelocInfo::kNoPosition);
+ TryCatchStatement* statement = factory()->NewTryCatchStatement(
+ try_block, catch_scope, catch_variable, catch_block, true,
+ RelocInfo::kNoPosition);
try_block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition);
try_block->statements()->Add(statement, zone());
catch_block = NULL; // Clear to indicate it's been handled.
@@ -3024,8 +3024,8 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
DCHECK(finally_block == NULL);
DCHECK(catch_scope != NULL && catch_variable != NULL);
- result = factory()->NewTryCatchStatement(try_block, catch_scope,
- catch_variable, catch_block, pos);
+ result = factory()->NewTryCatchStatement(
+ try_block, catch_scope, catch_variable, catch_block, true, pos);
} else {
DCHECK(finally_block != NULL);
result = factory()->NewTryFinallyStatement(try_block, finally_block, pos);
@@ -6058,7 +6058,7 @@ Expression* ParserTraits::RewriteYieldStar(
Variable::NORMAL);
try_catch = factory->NewTryCatchStatement(
- try_block, catch_scope, catch_variable, catch_block, nopos);
+ try_block, catch_scope, catch_variable, catch_block, true, nopos);
}
@@ -6464,7 +6464,7 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
// iterator_use
// } catch(e) {
// if (completion === kAbruptCompletion) completion = kThrowCompletion;
- // throw e;
+ // %ReThrow(e);
// }
// } finally {
// if (condition) {
@@ -6525,7 +6525,7 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
// try { #try_block }
// catch(e) {
// #set_completion_throw;
- // throw e;
+ // %ReThrow(e);
// }
Statement* try_catch;
{
@@ -6535,10 +6535,14 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
kCreatedInitialized, Variable::NORMAL);
Statement* rethrow;
+ // We use %ReThrow rather than the ordinary throw because we want to
+ // keep the original exception message. This is also why we create the
+ // TryCatchStatement below with clear_pending_message set to false.
{
- Expression* proxy = factory->NewVariableProxy(catch_variable);
- rethrow = factory->NewExpressionStatement(factory->NewThrow(proxy, nopos),
- nopos);
+ auto args = new (zone) ZoneList<Expression*>(1, zone);
+ args->Add(factory->NewVariableProxy(catch_variable), zone);
+ rethrow = factory->NewExpressionStatement(
+ factory->NewCallRuntime(Runtime::kReThrow, args, nopos), nopos);
}
Block* catch_block = factory->NewBlock(nullptr, 2, false, nopos);
@@ -6546,7 +6550,7 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
catch_block->statements()->Add(rethrow, zone);
try_catch = factory->NewTryCatchStatement(
- iterator_use, catch_scope, catch_variable, catch_block, nopos);
+ iterator_use, catch_scope, catch_variable, catch_block, false, nopos);
}
// try { #try_catch } finally { #maybe_close }
@@ -6641,7 +6645,7 @@ void ParserTraits::BuildIteratorCloseForCompletion(
Variable::NORMAL);
try_call_return = factory->NewTryCatchStatement(
- try_block, catch_scope, catch_variable, catch_block, nopos);
+ try_block, catch_scope, catch_variable, catch_block, true, nopos);
}
// let output = %_Call(iteratorReturn, iterator);
@@ -6741,7 +6745,7 @@ Statement* ParserTraits::FinalizeForOfStatement(ForOfStatement* loop, int pos) {
// #loop;
// } catch(e) {
// if (completion === kAbruptCompletion) completion = kThrowCompletion;
- // throw e;
+ // %ReThrow(e);
// }
// } finally {
// if (!(completion === kNormalCompletion || IS_UNDEFINED(#iterator))) {

Powered by Google App Engine
This is Rietveld 408576698