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

Unified Diff: src/parsing/parser.cc

Issue 2156303002: Implement new Function.prototype.toString and fix CreateDynamicFunction parsing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years 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 012bc6e00ed3ea3284d2cdce57e99a12af6dea20..bb33a4419d3b3c2c29597ac4babb2ed20d558161 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -586,7 +586,8 @@ Parser::Parser(ParseInfo* info)
cached_parse_data_(nullptr),
total_preparse_skipped_(0),
temp_zoned_(false),
- log_(nullptr) {
+ log_(nullptr),
+ parameters_end_pos_(info->parameters_end_pos()) {
// Even though we were passed ParseInfo, we should not store it in
// Parser - this makes sure that Isolate is not accidentally accessed via
// ParseInfo during background parsing.
@@ -3166,8 +3167,27 @@ ZoneList<Statement*>* Parser::ParseFunction(
if (IsGeneratorFunction(kind)) PrepareGeneratorVariables(&function_state);
+ int expected_parameters_end_pos = parameters_end_pos_;
+ if (expected_parameters_end_pos != kNoSourcePosition) {
+ // This is the first function encountered in an only-single-function eval.
Dan Ehrenberg 2016/12/06 00:32:13 I thought this happens only in the Function constr
jwolfe 2017/01/13 00:28:48 Updated comment to be more clear.
+ parameters_end_pos_ = kNoSourcePosition;
+ // The function name should have been ignored, giving us null here.
+ DCHECK_NULL(function_name);
+ }
+
ParserFormalParameters formals(function_scope);
ParseFormalParameterList(&formals, CHECK_OK);
+ if (expected_parameters_end_pos != kNoSourcePosition) {
+ // Check for '(' or ')' shenanigans in the parameter string for dynamic
+ // functions.
+ if (peek_position() != expected_parameters_end_pos) {
+ ReportMessageAt(Scanner::Location(expected_parameters_end_pos,
+ expected_parameters_end_pos + 1),
+ MessageTemplate::kExpectedEndOfParameters);
Dan Ehrenberg 2016/12/06 00:32:13 Will CreateDynamicFunction always trigger eager co
jwolfe 2017/01/13 00:28:47 Done. It looks like it's always eagerly parsed. I
+ *ok = false;
+ return nullptr;
+ }
+ }
Expect(Token::RPAREN, CHECK_OK);
int formals_end_position = scanner()->location().end_pos;
*num_parameters = formals.num_parameters();
« src/parsing/parser.h ('K') | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698