Commit 0c95efb7 authored by lpy's avatar lpy Committed by Commit bot

Fix not throwing error when redefine eval or arguments in strict mode.

Currently when redefining eval or arguments in non-simple parameter list and
destructuring binding, V8 doesn't throw any error, this patch fixes it.

BUG=v8:5201
LOG=N

Review-Url: https://codereview.chromium.org/2185223002
Cr-Commit-Position: refs/heads/master@{#38762}
parent d814ca8d
...@@ -1975,7 +1975,6 @@ ParserBase<Traits>::ParsePropertyDefinition( ...@@ -1975,7 +1975,6 @@ ParserBase<Traits>::ParsePropertyDefinition(
if (!in_class && !is_generator) { if (!in_class && !is_generator) {
DCHECK(!IsStaticMethod(method_kind)); DCHECK(!IsStaticMethod(method_kind));
if (peek() == Token::COLON) { if (peek() == Token::COLON) {
// PropertyDefinition // PropertyDefinition
// PropertyName ':' AssignmentExpression // PropertyName ':' AssignmentExpression
...@@ -2008,6 +2007,12 @@ ParserBase<Traits>::ParsePropertyDefinition( ...@@ -2008,6 +2007,12 @@ ParserBase<Traits>::ParsePropertyDefinition(
scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) {
classifier->RecordDuplicateFormalParameterError(scanner()->location()); classifier->RecordDuplicateFormalParameterError(scanner()->location());
} }
if (this->IsEvalOrArguments(*name) && is_strict(language_mode())) {
classifier->RecordBindingPatternError(
scanner()->location(), MessageTemplate::kStrictEvalArguments);
}
if (name_token == Token::LET) { if (name_token == Token::LET) {
classifier->RecordLetPatternError( classifier->RecordLetPatternError(
scanner()->location(), MessageTemplate::kLetInLexicalBinding); scanner()->location(), MessageTemplate::kLetInLexicalBinding);
......
...@@ -6342,9 +6342,46 @@ TEST(DestructuringPositiveTests) { ...@@ -6342,9 +6342,46 @@ TEST(DestructuringPositiveTests) {
"[...rest]", "[...rest]",
"[a,b,...rest]", "[a,b,...rest]",
"[a,,...rest]", "[a,,...rest]",
"{arguments: x}",
"{eval: x}",
NULL}; NULL};
// clang-format on // clang-format on
RunParserSyncTest(context_data, data, kSuccess); RunParserSyncTest(context_data, data, kSuccess);
// v8:5201
// TODO(lpy): The two test sets below should be merged once
// we fix https://bugs.chromium.org/p/v8/issues/detail?id=4577
{
const char* sloppy_context_data1[][2] = {
{"var ", " = {};"},
{"function f(", ") {}"},
{"function f(argument1, ", ") {}"},
{"var f = (", ") => {};"},
{"var f = (argument1,", ") => {};"},
{"try {} catch(", ") {}"},
{NULL, NULL}
};
const char* data1[] = {
"{eval}",
"{x: eval}",
"{eval = false}",
NULL
};
RunParserSyncTest(sloppy_context_data1, data1, kSuccess);
const char* sloppy_context_data2[][2] = {
{"var ", " = {};"},
{"try {} catch(", ") {}"},
{NULL, NULL}
};
const char* data2[] = {
"{arguments}",
"{x: arguments}",
"{arguments = false}",
NULL,
};
RunParserSyncTest(sloppy_context_data2, data2, kSuccess);
}
} }
...@@ -6457,6 +6494,7 @@ TEST(DestructuringNegativeTests) { ...@@ -6457,6 +6494,7 @@ TEST(DestructuringNegativeTests) {
{ // Strict mode. { // Strict mode.
const char* context_data[][2] = { const char* context_data[][2] = {
{"'use strict'; var ", " = {};"},
{"'use strict'; let ", " = {};"}, {"'use strict'; let ", " = {};"},
{"'use strict'; const ", " = {};"}, {"'use strict'; const ", " = {};"},
{"'use strict'; function f(", ") {}"}, {"'use strict'; function f(", ") {}"},
...@@ -6465,10 +6503,18 @@ TEST(DestructuringNegativeTests) { ...@@ -6465,10 +6503,18 @@ TEST(DestructuringNegativeTests) {
// clang-format off // clang-format off
const char* data[] = { const char* data[] = {
"[arguments]",
"[eval]", "[eval]",
"{ a : arguments }", "{ a : arguments }",
"{ a : eval }",
"[public]", "[public]",
"{ x : private }", "{ x : private }",
"{ x : arguments }",
"{ x : eval }",
"{ arguments }",
"{ eval }",
"{ arguments = false }"
"{ eval = false }",
NULL}; NULL};
// clang-format on // clang-format on
RunParserSyncTest(context_data, data, kError); RunParserSyncTest(context_data, data, kError);
......
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