OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 } | 418 } |
419 | 419 |
420 inline void CheckStrictOctalLiteral(int beg_pos, int end_pos, bool* ok) { | 420 inline void CheckStrictOctalLiteral(int beg_pos, int end_pos, bool* ok) { |
421 CheckOctalLiteral(beg_pos, end_pos, "strict_octal_literal", ok); | 421 CheckOctalLiteral(beg_pos, end_pos, "strict_octal_literal", ok); |
422 } | 422 } |
423 | 423 |
424 inline void CheckTemplateOctalLiteral(int beg_pos, int end_pos, bool* ok) { | 424 inline void CheckTemplateOctalLiteral(int beg_pos, int end_pos, bool* ok) { |
425 CheckOctalLiteral(beg_pos, end_pos, "template_octal_literal", ok); | 425 CheckOctalLiteral(beg_pos, end_pos, "template_octal_literal", ok); |
426 } | 426 } |
427 | 427 |
428 // Validates strict mode for function parameter lists. This has to be | 428 // Checking the name of a function literal. This has to be done after parsing |
429 // done after parsing the function, since the function can declare | 429 // the function, since the function can declare itself strict. |
430 // itself strict. | 430 void CheckFunctionName(LanguageMode language_mode, FunctionKind kind, |
431 void CheckStrictFunctionNameAndParameters( | 431 IdentifierT function_name, |
432 IdentifierT function_name, | 432 bool function_name_is_strict_reserved, |
433 bool function_name_is_strict_reserved, | 433 const Scanner::Location& function_name_loc, |
434 const Scanner::Location& function_name_loc, | 434 bool* ok) { |
435 const Scanner::Location& eval_args_error_loc, | 435 // Property names are never checked. |
436 const Scanner::Location& dupe_error_loc, | 436 if (IsConciseMethod(kind) || IsAccessorFunction(kind)) return; |
437 const Scanner::Location& reserved_loc, | 437 // The function name needs to be checked in strict mode. |
438 bool* ok) { | 438 if (is_sloppy(language_mode)) return; |
| 439 |
439 if (this->IsEvalOrArguments(function_name)) { | 440 if (this->IsEvalOrArguments(function_name)) { |
440 Traits::ReportMessageAt(function_name_loc, "strict_eval_arguments"); | 441 Traits::ReportMessageAt(function_name_loc, "strict_eval_arguments"); |
441 *ok = false; | 442 *ok = false; |
442 return; | 443 return; |
443 } | 444 } |
444 if (function_name_is_strict_reserved) { | 445 if (function_name_is_strict_reserved) { |
445 Traits::ReportMessageAt(function_name_loc, "unexpected_strict_reserved"); | 446 Traits::ReportMessageAt(function_name_loc, "unexpected_strict_reserved"); |
446 *ok = false; | 447 *ok = false; |
447 return; | 448 return; |
448 } | 449 } |
| 450 } |
| 451 |
| 452 // Checking the parameter names of a function literal. This has to be done |
| 453 // after parsing the function, since the function can declare itself strict. |
| 454 void CheckFunctionParameterNames(LanguageMode language_mode, |
| 455 bool strict_params, |
| 456 const Scanner::Location& eval_args_error_loc, |
| 457 const Scanner::Location& dupe_error_loc, |
| 458 const Scanner::Location& reserved_loc, |
| 459 bool* ok) { |
| 460 if (is_sloppy(language_mode) && !strict_params) return; |
| 461 |
449 if (eval_args_error_loc.IsValid()) { | 462 if (eval_args_error_loc.IsValid()) { |
450 Traits::ReportMessageAt(eval_args_error_loc, "strict_eval_arguments"); | 463 Traits::ReportMessageAt(eval_args_error_loc, "strict_eval_arguments"); |
451 *ok = false; | 464 *ok = false; |
452 return; | 465 return; |
453 } | 466 } |
| 467 // TODO(arv): When we add support for destructuring in setters we also need |
| 468 // to check for duplicate names. |
454 if (dupe_error_loc.IsValid()) { | 469 if (dupe_error_loc.IsValid()) { |
455 Traits::ReportMessageAt(dupe_error_loc, "strict_param_dupe"); | 470 Traits::ReportMessageAt(dupe_error_loc, "strict_param_dupe"); |
456 *ok = false; | 471 *ok = false; |
457 return; | 472 return; |
458 } | 473 } |
459 if (reserved_loc.IsValid()) { | 474 if (reserved_loc.IsValid()) { |
460 Traits::ReportMessageAt(reserved_loc, "unexpected_strict_reserved"); | 475 Traits::ReportMessageAt(reserved_loc, "unexpected_strict_reserved"); |
461 *ok = false; | 476 *ok = false; |
462 return; | 477 return; |
463 } | 478 } |
(...skipping 2369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2833 int materialized_literal_count = -1; | 2848 int materialized_literal_count = -1; |
2834 int expected_property_count = -1; | 2849 int expected_property_count = -1; |
2835 int handler_count = 0; | 2850 int handler_count = 0; |
2836 | 2851 |
2837 { | 2852 { |
2838 typename Traits::Type::Factory function_factory(this->ast_value_factory()); | 2853 typename Traits::Type::Factory function_factory(this->ast_value_factory()); |
2839 FunctionState function_state(&function_state_, &scope_, | 2854 FunctionState function_state(&function_state_, &scope_, |
2840 Traits::Type::ptr_to_scope(scope), | 2855 Traits::Type::ptr_to_scope(scope), |
2841 &function_factory); | 2856 &function_factory); |
2842 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 2857 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
| 2858 // TODO(arv): Pass in eval_args_error_loc and reserved_loc here. |
2843 num_parameters = Traits::DeclareArrowParametersFromExpression( | 2859 num_parameters = Traits::DeclareArrowParametersFromExpression( |
2844 params_ast, scope_, &dupe_error_loc, ok); | 2860 params_ast, scope_, &dupe_error_loc, ok); |
2845 if (!*ok) { | 2861 if (!*ok) { |
2846 ReportMessageAt( | 2862 ReportMessageAt( |
2847 Scanner::Location(start_pos, scanner()->location().beg_pos), | 2863 Scanner::Location(start_pos, scanner()->location().beg_pos), |
2848 "malformed_arrow_function_parameter_list"); | 2864 "malformed_arrow_function_parameter_list"); |
2849 return this->EmptyExpression(); | 2865 return this->EmptyExpression(); |
2850 } | 2866 } |
2851 | 2867 |
2852 if (num_parameters > Code::kMaxArguments) { | 2868 if (num_parameters > Code::kMaxArguments) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2887 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 2903 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
2888 materialized_literal_count = function_state.materialized_literal_count(); | 2904 materialized_literal_count = function_state.materialized_literal_count(); |
2889 expected_property_count = function_state.expected_property_count(); | 2905 expected_property_count = function_state.expected_property_count(); |
2890 handler_count = function_state.handler_count(); | 2906 handler_count = function_state.handler_count(); |
2891 } | 2907 } |
2892 | 2908 |
2893 scope->set_start_position(start_pos); | 2909 scope->set_start_position(start_pos); |
2894 scope->set_end_position(scanner()->location().end_pos); | 2910 scope->set_end_position(scanner()->location().end_pos); |
2895 | 2911 |
2896 // Arrow function *parameter lists* are always checked as in strict mode. | 2912 // Arrow function *parameter lists* are always checked as in strict mode. |
2897 bool function_name_is_strict_reserved = false; | 2913 // TODO(arv): eval_args_error_loc and reserved_loc needs to be set by |
2898 Scanner::Location function_name_loc = Scanner::Location::invalid(); | 2914 // DeclareArrowParametersFromExpression. |
2899 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); | 2915 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); |
2900 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 2916 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
2901 this->CheckStrictFunctionNameAndParameters( | 2917 const bool use_strict_params = true; |
2902 this->EmptyIdentifier(), function_name_is_strict_reserved, | 2918 this->CheckFunctionParameterNames(language_mode(), use_strict_params, |
2903 function_name_loc, eval_args_error_loc, dupe_error_loc, reserved_loc, | 2919 eval_args_error_loc, dupe_error_loc, reserved_loc, CHECK_OK); |
2904 CHECK_OK); | |
2905 | 2920 |
2906 // Validate strict mode. | 2921 // Validate strict mode. |
2907 if (is_strict(language_mode())) { | 2922 if (is_strict(language_mode())) { |
2908 CheckStrictOctalLiteral(start_pos, scanner()->location().end_pos, | 2923 CheckStrictOctalLiteral(start_pos, scanner()->location().end_pos, |
2909 CHECK_OK); | 2924 CHECK_OK); |
2910 } | 2925 } |
2911 | 2926 |
2912 if (allow_harmony_scoping() && is_strict(language_mode())) | 2927 if (allow_harmony_scoping() && is_strict(language_mode())) |
2913 this->CheckConflictingVarDeclarations(scope, CHECK_OK); | 2928 this->CheckConflictingVarDeclarations(scope, CHECK_OK); |
2914 } | 2929 } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3097 *ok = false; | 3112 *ok = false; |
3098 return; | 3113 return; |
3099 } | 3114 } |
3100 has_seen_constructor_ = true; | 3115 has_seen_constructor_ = true; |
3101 return; | 3116 return; |
3102 } | 3117 } |
3103 } | 3118 } |
3104 } } // v8::internal | 3119 } } // v8::internal |
3105 | 3120 |
3106 #endif // V8_PREPARSER_H | 3121 #endif // V8_PREPARSER_H |
OLD | NEW |