Commit 443e645a authored by marja@chromium.org's avatar marja@chromium.org

Tests and fixes for (pre)parse errors related to strict reserved words.

This contains the following fixes:

- We had strict_reserved_word and unexpected_strict_reserved, which one to use
was totally mixed in Parser and PreParser. Removed strict_reserved_word.
- When we saw a strict future reserved word when expecting something completely
different (such as "(" in "function foo interface"), Parser reports unexpected
identifier, whereas PreParser used to report unexpected strict reserved
word. Fixed PreParser to report unexpected identifier too.
- Unified parser and preparser error locations when the name of a function is a
strict reserved word. Now both point to the name.

BUG=3126
LOG=N
R=ulan@chromium.org

Review URL: https://codereview.chromium.org/149253010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e5c7f4ef
......@@ -170,7 +170,6 @@ var kMessages = {
strict_lhs_assignment: ["Assignment to eval or arguments is not allowed in strict mode"],
strict_lhs_postfix: ["Postfix increment/decrement may not have eval or arguments operand in strict mode"],
strict_lhs_prefix: ["Prefix increment/decrement may not have eval or arguments operand in strict mode"],
strict_reserved_word: ["Use of future reserved word in strict mode"],
strict_delete: ["Delete of an unqualified identifier in strict mode."],
strict_delete_property: ["Cannot delete property '", "%0", "' of ", "%1"],
strict_const: ["Use of const in strict mode."],
......
......@@ -4321,17 +4321,13 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
return NULL;
}
if (name_is_strict_reserved) {
int start_pos = scope->start_position();
int position = function_token_pos != RelocInfo::kNoPosition
? function_token_pos : (start_pos > 0 ? start_pos - 1 : start_pos);
Scanner::Location location = Scanner::Location(position, start_pos);
ReportMessageAt(location, "strict_reserved_word",
ReportMessageAt(function_name_location, "unexpected_strict_reserved",
Vector<const char*>::empty());
*ok = false;
return NULL;
}
if (reserved_loc.IsValid()) {
ReportMessageAt(reserved_loc, "strict_reserved_word",
ReportMessageAt(reserved_loc, "unexpected_strict_reserved",
Vector<const char*>::empty());
*ok = false;
return NULL;
......
......@@ -121,7 +121,9 @@ void PreParser::ReportUnexpectedToken(Token::Value token) {
return ReportMessageAt(source_location, "unexpected_reserved", NULL);
case Token::FUTURE_STRICT_RESERVED_WORD:
return ReportMessageAt(source_location,
"unexpected_strict_reserved", NULL);
is_classic_mode() ? "unexpected_token_identifier"
: "unexpected_strict_reserved",
NULL);
default:
const char* name = Token::String(token);
ReportMessageAt(source_location, "unexpected_token", name);
......@@ -304,7 +306,7 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
// as name of strict function.
const char* type = "strict_function_name";
if (identifier.IsFutureStrictReserved() || identifier.IsYield()) {
type = "strict_reserved_word";
type = "unexpected_strict_reserved";
}
ReportMessageAt(location, type, NULL);
*ok = false;
......@@ -1511,7 +1513,7 @@ PreParser::Identifier PreParser::ParseIdentifier(bool* ok) {
if (!is_classic_mode()) {
Scanner::Location location = scanner()->location();
ReportMessageAt(location.beg_pos, location.end_pos,
"strict_reserved_word", NULL);
"unexpected_strict_reserved", NULL);
*ok = false;
}
// FALLTHROUGH
......@@ -1565,7 +1567,7 @@ void PreParser::StrictModeIdentifierViolation(Scanner::Location location,
if (identifier.IsFutureReserved()) {
type = "reserved_word";
} else if (identifier.IsFutureStrictReserved() || identifier.IsYield()) {
type = "strict_reserved_word";
type = "unexpected_strict_reserved";
}
if (!is_classic_mode()) {
ReportMessageAt(location, type, NULL);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment