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(
if (!in_class && !is_generator) {
DCHECK(!IsStaticMethod(method_kind));
if (peek() == Token::COLON) {
// PropertyDefinition
// PropertyName ':' AssignmentExpression
......@@ -2008,6 +2007,12 @@ ParserBase<Traits>::ParsePropertyDefinition(
scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) {
classifier->RecordDuplicateFormalParameterError(scanner()->location());
}
if (this->IsEvalOrArguments(*name) && is_strict(language_mode())) {
classifier->RecordBindingPatternError(
scanner()->location(), MessageTemplate::kStrictEvalArguments);
}
if (name_token == Token::LET) {
classifier->RecordLetPatternError(
scanner()->location(), MessageTemplate::kLetInLexicalBinding);
......
......@@ -6342,9 +6342,46 @@ TEST(DestructuringPositiveTests) {
"[...rest]",
"[a,b,...rest]",
"[a,,...rest]",
"{arguments: x}",
"{eval: x}",
NULL};
// clang-format on
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) {
{ // Strict mode.
const char* context_data[][2] = {
{"'use strict'; var ", " = {};"},
{"'use strict'; let ", " = {};"},
{"'use strict'; const ", " = {};"},
{"'use strict'; function f(", ") {}"},
......@@ -6465,10 +6503,18 @@ TEST(DestructuringNegativeTests) {
// clang-format off
const char* data[] = {
"[arguments]",
"[eval]",
"{ a : arguments }",
"{ a : eval }",
"[public]",
"{ x : private }",
"{ x : arguments }",
"{ x : eval }",
"{ arguments }",
"{ eval }",
"{ arguments = false }"
"{ eval = false }",
NULL};
// clang-format on
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