summaryrefslogtreecommitdiff
path: root/deps/v8/src/preparser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/preparser.cc')
-rw-r--r--deps/v8/src/preparser.cc82
1 files changed, 77 insertions, 5 deletions
diff --git a/deps/v8/src/preparser.cc b/deps/v8/src/preparser.cc
index 9fd6e23d3a..b552676753 100644
--- a/deps/v8/src/preparser.cc
+++ b/deps/v8/src/preparser.cc
@@ -105,7 +105,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
StrictMode strict_mode, bool is_generator, ParserRecorder* log) {
log_ = log;
// Lazy functions always have trivial outer scopes (no with/catch scopes).
- PreParserScope top_scope(scope_, GLOBAL_SCOPE);
+ PreParserScope top_scope(scope_, SCRIPT_SCOPE);
PreParserFactory top_factory(NULL);
FunctionState top_state(&function_state_, &scope_, &top_scope, &top_factory);
scope_->SetStrictMode(strict_mode);
@@ -125,13 +125,21 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
DCHECK_EQ(Token::RBRACE, scanner()->peek());
if (scope_->strict_mode() == STRICT) {
int end_pos = scanner()->location().end_pos;
- CheckOctalLiteral(start_position, end_pos, &ok);
+ CheckStrictOctalLiteral(start_position, end_pos, &ok);
}
}
return kPreParseSuccess;
}
+PreParserExpression PreParserTraits::ParseClassLiteral(
+ PreParserIdentifier name, Scanner::Location class_name_location,
+ bool name_is_strict_reserved, int pos, bool* ok) {
+ return pre_parser_->ParseClassLiteral(name, class_name_location,
+ name_is_strict_reserved, pos, ok);
+}
+
+
// Preparsing checks a JavaScript program and emits preparse-data that helps
// a later parsing to be faster.
// See preparser-data.h for the data.
@@ -342,6 +350,12 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
PreParser::Statement PreParser::ParseClassDeclaration(bool* ok) {
Expect(Token::CLASS, CHECK_OK);
+ if (!allow_harmony_sloppy() && strict_mode() == SLOPPY) {
+ ReportMessage("sloppy_lexical");
+ *ok = false;
+ return Statement::Default();
+ }
+
int pos = position();
bool is_strict_reserved = false;
Identifier name =
@@ -501,6 +515,13 @@ PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) {
// accept "native function" in the preparser.
}
// Parsed expression statement.
+ // Detect attempts at 'let' declarations in sloppy mode.
+ if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY &&
+ expr.IsIdentifier() && expr.AsIdentifier().IsLet()) {
+ ReportMessage("sloppy_lexical", NULL);
+ *ok = false;
+ return Statement::Default();
+ }
ExpectSemicolon(CHECK_OK);
return Statement::ExpressionStatement(expr);
}
@@ -680,6 +701,7 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
Expect(Token::FOR, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK);
+ bool is_let_identifier_expression = false;
if (peek() != Token::SEMICOLON) {
if (peek() == Token::VAR || peek() == Token::CONST ||
(peek() == Token::LET && strict_mode() == STRICT)) {
@@ -701,6 +723,8 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
} else {
Expression lhs = ParseExpression(false, CHECK_OK);
+ is_let_identifier_expression =
+ lhs.IsIdentifier() && lhs.AsIdentifier().IsLet();
if (CheckInOrOf(lhs.IsIdentifier())) {
ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
@@ -712,6 +736,13 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
// Parsed initializer at this point.
+ // Detect attempts at 'let' declarations in sloppy mode.
+ if (peek() == Token::IDENTIFIER && strict_mode() == SLOPPY &&
+ is_let_identifier_expression) {
+ ReportMessage("sloppy_lexical", NULL);
+ *ok = false;
+ return Statement::Default();
+ }
Expect(Token::SEMICOLON, CHECK_OK);
if (peek() != Token::SEMICOLON) {
@@ -863,7 +894,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// See Parser::ParseFunctionLiteral for more information about lazy parsing
// and lazy compilation.
- bool is_lazily_parsed = (outer_scope_type == GLOBAL_SCOPE && allow_lazy() &&
+ bool is_lazily_parsed = (outer_scope_type == SCRIPT_SCOPE && allow_lazy() &&
!parenthesized_function_);
parenthesized_function_ = false;
@@ -906,7 +937,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
}
int end_position = scanner()->location().end_pos;
- CheckOctalLiteral(start_position, end_position, CHECK_OK);
+ CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
}
return Expression::Default();
@@ -928,11 +959,52 @@ void PreParser::ParseLazyFunctionLiteralBody(bool* ok) {
}
+PreParserExpression PreParser::ParseClassLiteral(
+ PreParserIdentifier name, Scanner::Location class_name_location,
+ bool name_is_strict_reserved, int pos, bool* ok) {
+ // All parts of a ClassDeclaration and ClassExpression are strict code.
+ if (name_is_strict_reserved) {
+ ReportMessageAt(class_name_location, "unexpected_strict_reserved");
+ *ok = false;
+ return EmptyExpression();
+ }
+ if (IsEvalOrArguments(name)) {
+ ReportMessageAt(class_name_location, "strict_eval_arguments");
+ *ok = false;
+ return EmptyExpression();
+ }
+
+ PreParserScope scope = NewScope(scope_, BLOCK_SCOPE);
+ BlockState block_state(&scope_, &scope);
+ scope_->SetStrictMode(STRICT);
+ scope_->SetScopeName(name);
+
+ if (Check(Token::EXTENDS)) {
+ ParseLeftHandSideExpression(CHECK_OK);
+ }
+
+ bool has_seen_constructor = false;
+
+ Expect(Token::LBRACE, CHECK_OK);
+ while (peek() != Token::RBRACE) {
+ if (Check(Token::SEMICOLON)) continue;
+ const bool in_class = true;
+ const bool is_static = false;
+ ParsePropertyDefinition(NULL, in_class, is_static, &has_seen_constructor,
+ CHECK_OK);
+ }
+
+ Expect(Token::RBRACE, CHECK_OK);
+
+ return Expression::Default();
+}
+
+
PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) {
// CallRuntime ::
// '%' Identifier Arguments
Expect(Token::MOD, CHECK_OK);
- if (!allow_natives_syntax()) {
+ if (!allow_natives()) {
*ok = false;
return Expression::Default();
}