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

Unified Diff: src/preparser.h

Issue 899363002: Allow eval and arguments as property names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Cleanup based on code review Created 5 years, 10 months 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
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 29a2b55e83e89719ee6472c35f9826765adb5be6..59b6e26f83fe30481cfc36b506a5735e5995ed63 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -425,17 +425,18 @@ class ParserBase : public Traits {
CheckOctalLiteral(beg_pos, end_pos, "template_octal_literal", ok);
}
- // Validates strict mode for function parameter lists. This has to be
- // done after parsing the function, since the function can declare
- // itself strict.
- void CheckStrictFunctionNameAndParameters(
- IdentifierT function_name,
- bool function_name_is_strict_reserved,
- const Scanner::Location& function_name_loc,
- const Scanner::Location& eval_args_error_loc,
- const Scanner::Location& dupe_error_loc,
- const Scanner::Location& reserved_loc,
- bool* ok) {
+ // Checking the name of a function literal. This has to be done after parsing
+ // the function, since the function can declare itself strict.
+ void CheckFunctionName(LanguageMode language_mode, FunctionKind kind,
+ IdentifierT function_name,
+ bool function_name_is_strict_reserved,
+ const Scanner::Location& function_name_loc,
+ bool* ok) {
+ // Property names are never checked.
+ if (IsConciseMethod(kind) || IsAccessorFunction(kind)) return;
+ // The function name needs to be checked in strict mode.
+ if (is_sloppy(language_mode)) return;
+
if (this->IsEvalOrArguments(function_name)) {
Traits::ReportMessageAt(function_name_loc, "strict_eval_arguments");
*ok = false;
@@ -446,11 +447,25 @@ class ParserBase : public Traits {
*ok = false;
return;
}
+ }
+
+ // Checking the parameter names of a function literal. This has to be done
+ // after parsing the function, since the function can declare itself strict.
+ void CheckFunctionParameterNames(LanguageMode language_mode,
+ bool strict_params,
+ const Scanner::Location& eval_args_error_loc,
+ const Scanner::Location& dupe_error_loc,
+ const Scanner::Location& reserved_loc,
+ bool* ok) {
+ if (is_sloppy(language_mode) && !strict_params) return;
+
if (eval_args_error_loc.IsValid()) {
Traits::ReportMessageAt(eval_args_error_loc, "strict_eval_arguments");
*ok = false;
return;
}
+ // TODO(arv): When we add support for destructuring in setters we also need
+ // to check for duplicate names.
if (dupe_error_loc.IsValid()) {
Traits::ReportMessageAt(dupe_error_loc, "strict_param_dupe");
*ok = false;
@@ -2840,6 +2855,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
Traits::Type::ptr_to_scope(scope),
&function_factory);
Scanner::Location dupe_error_loc = Scanner::Location::invalid();
+ // TODO(arv): Pass in eval_args_error_loc and reserved_loc here.
num_parameters = Traits::DeclareArrowParametersFromExpression(
params_ast, scope_, &dupe_error_loc, ok);
if (!*ok) {
@@ -2894,14 +2910,13 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos,
scope->set_end_position(scanner()->location().end_pos);
// Arrow function *parameter lists* are always checked as in strict mode.
- bool function_name_is_strict_reserved = false;
- Scanner::Location function_name_loc = Scanner::Location::invalid();
+ // TODO(arv): eval_args_error_loc and reserved_loc needs to be set by
+ // DeclareArrowParametersFromExpression.
Scanner::Location eval_args_error_loc = Scanner::Location::invalid();
Scanner::Location reserved_loc = Scanner::Location::invalid();
- this->CheckStrictFunctionNameAndParameters(
- this->EmptyIdentifier(), function_name_is_strict_reserved,
- function_name_loc, eval_args_error_loc, dupe_error_loc, reserved_loc,
- CHECK_OK);
+ const bool use_strict_params = true;
+ this->CheckFunctionParameterNames(language_mode(), use_strict_params,
+ eval_args_error_loc, dupe_error_loc, reserved_loc, CHECK_OK);
// Validate strict mode.
if (is_strict(language_mode())) {
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698