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

Unified Diff: src/parser.cc

Issue 1399893002: [es7] implement |do| expressions proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Less code duplication in Rewriter Created 5 years, 2 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/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index be80956b69323bd8890d0da824f5f83cbfa2c36f..940fae83a00fd0638069afcdce04b1b0cd40da34 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -15,6 +15,7 @@
#include "src/compiler.h"
#include "src/messages.h"
#include "src/preparser.h"
+#include "src/rewriter.h"
#include "src/runtime/runtime.h"
#include "src/scanner-character-streams.h"
#include "src/scopeinfo.h"
@@ -924,6 +925,7 @@ Parser::Parser(ParseInfo* info)
set_allow_harmony_new_target(FLAG_harmony_new_target);
set_allow_strong_mode(FLAG_strong_mode);
set_allow_legacy_const(FLAG_legacy_const);
+ set_allow_harmony_do_expressions(FLAG_harmony_do_expressions);
for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
++feature) {
use_counts_[feature] = 0;
@@ -4027,6 +4029,24 @@ void ParserTraits::ParseArrowFunctionFormalParameters(
}
+DoExpression* Parser::ParseDoExpression(bool* ok) {
+ // AssignmentExpression ::
+ // do '{' StatementList '}'
+ int pos = peek_position();
+
+ Expect(Token::DO, CHECK_OK);
+ Variable* result =
+ scope_->NewTemporary(ast_value_factory()->dot_result_string());
+ Block* block = ParseScopedBlock(nullptr, CHECK_OK);
+ DoExpression* expr = factory()->NewDoExpression(block, result, pos);
+ if (!Rewriter::Rewrite(this, expr, ast_value_factory())) {
+ *ok = false;
+ return nullptr;
+ }
+ return expr;
+}
+
+
void ParserTraits::ParseArrowFunctionFormalParameterList(
ParserFormalParameters* parameters, Expression* expr,
const Scanner::Location& params_loc,
@@ -4766,6 +4786,7 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
SET_ALLOW(harmony_spread_arrays);
SET_ALLOW(harmony_new_target);
SET_ALLOW(strong_mode);
+ SET_ALLOW(harmony_do_expressions);
#undef SET_ALLOW
}
PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(

Powered by Google App Engine
This is Rietveld 408576698