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 203 matching lines...) Loading... |
214 int materialized_literal_count() { | 214 int materialized_literal_count() { |
215 return next_materialized_literal_index_; | 215 return next_materialized_literal_index_; |
216 } | 216 } |
217 | 217 |
218 int NextHandlerIndex() { return next_handler_index_++; } | 218 int NextHandlerIndex() { return next_handler_index_++; } |
219 int handler_count() { return next_handler_index_; } | 219 int handler_count() { return next_handler_index_; } |
220 | 220 |
221 void AddProperty() { expected_property_count_++; } | 221 void AddProperty() { expected_property_count_++; } |
222 int expected_property_count() { return expected_property_count_; } | 222 int expected_property_count() { return expected_property_count_; } |
223 | 223 |
| 224 Scanner::Location super_call_location() const { |
| 225 return super_call_location_; |
| 226 } |
| 227 void set_super_call_location(Scanner::Location location) { |
| 228 super_call_location_ = location; |
| 229 } |
| 230 |
224 bool is_generator() const { return IsGeneratorFunction(kind_); } | 231 bool is_generator() const { return IsGeneratorFunction(kind_); } |
225 | 232 |
226 FunctionKind kind() const { return kind_; } | 233 FunctionKind kind() const { return kind_; } |
227 FunctionState* outer() const { return outer_function_state_; } | 234 FunctionState* outer() const { return outer_function_state_; } |
228 | 235 |
229 void set_generator_object_variable( | 236 void set_generator_object_variable( |
230 typename Traits::Type::GeneratorVariable* variable) { | 237 typename Traits::Type::GeneratorVariable* variable) { |
231 DCHECK(variable != NULL); | 238 DCHECK(variable != NULL); |
232 DCHECK(is_generator()); | 239 DCHECK(is_generator()); |
233 generator_object_variable_ = variable; | 240 generator_object_variable_ = variable; |
(...skipping 10 matching lines...) Loading... |
244 // the function. Includes regexp literals, and boilerplate for object and | 251 // the function. Includes regexp literals, and boilerplate for object and |
245 // array literals. | 252 // array literals. |
246 int next_materialized_literal_index_; | 253 int next_materialized_literal_index_; |
247 | 254 |
248 // Used to assign a per-function index to try and catch handlers. | 255 // Used to assign a per-function index to try and catch handlers. |
249 int next_handler_index_; | 256 int next_handler_index_; |
250 | 257 |
251 // Properties count estimation. | 258 // Properties count estimation. |
252 int expected_property_count_; | 259 int expected_property_count_; |
253 | 260 |
| 261 // Location of call to the "super" constructor (invalid if none). |
| 262 Scanner::Location super_call_location_; |
| 263 |
254 FunctionKind kind_; | 264 FunctionKind kind_; |
255 // For generators, this variable may hold the generator object. It variable | 265 // For generators, this variable may hold the generator object. It variable |
256 // is used by yield expressions and return statements. It is not necessary | 266 // is used by yield expressions and return statements. It is not necessary |
257 // for generator functions to have this variable set. | 267 // for generator functions to have this variable set. |
258 Variable* generator_object_variable_; | 268 Variable* generator_object_variable_; |
259 | 269 |
260 FunctionState** function_state_stack_; | 270 FunctionState** function_state_stack_; |
261 FunctionState* outer_function_state_; | 271 FunctionState* outer_function_state_; |
262 Scope** scope_stack_; | 272 Scope** scope_stack_; |
263 Scope* outer_scope_; | 273 Scope* outer_scope_; |
(...skipping 1390 matching lines...) Loading... |
1654 } | 1664 } |
1655 | 1665 |
1656 | 1666 |
1657 template <class Traits> | 1667 template <class Traits> |
1658 ParserBase<Traits>::FunctionState::FunctionState( | 1668 ParserBase<Traits>::FunctionState::FunctionState( |
1659 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, | 1669 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, |
1660 FunctionKind kind, typename Traits::Type::Factory* factory) | 1670 FunctionKind kind, typename Traits::Type::Factory* factory) |
1661 : next_materialized_literal_index_(0), | 1671 : next_materialized_literal_index_(0), |
1662 next_handler_index_(0), | 1672 next_handler_index_(0), |
1663 expected_property_count_(0), | 1673 expected_property_count_(0), |
| 1674 super_call_location_(Scanner::Location::invalid()), |
1664 kind_(kind), | 1675 kind_(kind), |
1665 generator_object_variable_(NULL), | 1676 generator_object_variable_(NULL), |
1666 function_state_stack_(function_state_stack), | 1677 function_state_stack_(function_state_stack), |
1667 outer_function_state_(*function_state_stack), | 1678 outer_function_state_(*function_state_stack), |
1668 scope_stack_(scope_stack), | 1679 scope_stack_(scope_stack), |
1669 outer_scope_(*scope_stack), | 1680 outer_scope_(*scope_stack), |
1670 factory_(factory) { | 1681 factory_(factory) { |
1671 *scope_stack_ = scope; | 1682 *scope_stack_ = scope; |
1672 *function_state_stack = this; | 1683 *function_state_stack = this; |
1673 } | 1684 } |
(...skipping 1121 matching lines...) Loading... |
2795 FunctionKind kind = function_state->kind(); | 2806 FunctionKind kind = function_state->kind(); |
2796 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 2807 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
2797 i::IsConstructor(kind)) { | 2808 i::IsConstructor(kind)) { |
2798 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 2809 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
2799 scope_->RecordSuperPropertyUsage(); | 2810 scope_->RecordSuperPropertyUsage(); |
2800 return this->SuperReference(scope_, factory()); | 2811 return this->SuperReference(scope_, factory()); |
2801 } | 2812 } |
2802 // new super() is never allowed. | 2813 // new super() is never allowed. |
2803 // super() is only allowed in derived constructor | 2814 // super() is only allowed in derived constructor |
2804 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { | 2815 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { |
| 2816 if (is_strong(language_mode()) && |
| 2817 function_state->super_call_location().IsValid()) { |
| 2818 ReportMessageAt(scanner()->location(), "strong_super_call_duplicate"); |
| 2819 *ok = false; |
| 2820 return this->EmptyExpression(); |
| 2821 } |
| 2822 function_state->set_super_call_location(scanner()->location()); |
2805 return this->SuperReference(scope_, factory()); | 2823 return this->SuperReference(scope_, factory()); |
2806 } | 2824 } |
2807 } | 2825 } |
2808 | 2826 |
2809 ReportMessageAt(scanner()->location(), "unexpected_super"); | 2827 ReportMessageAt(scanner()->location(), "unexpected_super"); |
2810 *ok = false; | 2828 *ok = false; |
2811 return this->EmptyExpression(); | 2829 return this->EmptyExpression(); |
2812 } | 2830 } |
2813 | 2831 |
2814 | 2832 |
(...skipping 49 matching lines...) Loading... |
2864 *ok = false; | 2882 *ok = false; |
2865 return this->EmptyExpression(); | 2883 return this->EmptyExpression(); |
2866 } | 2884 } |
2867 | 2885 |
2868 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); | 2886 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); |
2869 typename Traits::Type::StatementList body; | 2887 typename Traits::Type::StatementList body; |
2870 int num_parameters = -1; | 2888 int num_parameters = -1; |
2871 int materialized_literal_count = -1; | 2889 int materialized_literal_count = -1; |
2872 int expected_property_count = -1; | 2890 int expected_property_count = -1; |
2873 int handler_count = 0; | 2891 int handler_count = 0; |
| 2892 Scanner::Location super_loc; |
2874 | 2893 |
2875 { | 2894 { |
2876 typename Traits::Type::Factory function_factory(ast_value_factory()); | 2895 typename Traits::Type::Factory function_factory(ast_value_factory()); |
2877 FunctionState function_state(&function_state_, &scope_, scope, | 2896 FunctionState function_state(&function_state_, &scope_, scope, |
2878 kArrowFunction, &function_factory); | 2897 kArrowFunction, &function_factory); |
2879 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); | 2898 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); |
2880 // TODO(arv): Pass in eval_args_error_loc and reserved_loc here. | 2899 // TODO(arv): Pass in eval_args_error_loc and reserved_loc here. |
2881 num_parameters = Traits::DeclareArrowParametersFromExpression( | 2900 num_parameters = Traits::DeclareArrowParametersFromExpression( |
2882 params_ast, scope_, &dupe_error_loc, ok); | 2901 params_ast, scope_, &dupe_error_loc, ok); |
2883 if (!*ok) { | 2902 if (!*ok) { |
(...skipping 35 matching lines...) Loading... |
2919 // Single-expression body | 2938 // Single-expression body |
2920 int pos = position(); | 2939 int pos = position(); |
2921 parenthesized_function_ = false; | 2940 parenthesized_function_ = false; |
2922 ExpressionT expression = ParseAssignmentExpression(true, CHECK_OK); | 2941 ExpressionT expression = ParseAssignmentExpression(true, CHECK_OK); |
2923 body = this->NewStatementList(1, zone()); | 2942 body = this->NewStatementList(1, zone()); |
2924 body->Add(factory()->NewReturnStatement(expression, pos), zone()); | 2943 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
2925 materialized_literal_count = function_state.materialized_literal_count(); | 2944 materialized_literal_count = function_state.materialized_literal_count(); |
2926 expected_property_count = function_state.expected_property_count(); | 2945 expected_property_count = function_state.expected_property_count(); |
2927 handler_count = function_state.handler_count(); | 2946 handler_count = function_state.handler_count(); |
2928 } | 2947 } |
| 2948 super_loc = function_state.super_call_location(); |
2929 | 2949 |
2930 scope->set_start_position(start_pos); | 2950 scope->set_start_position(start_pos); |
2931 scope->set_end_position(scanner()->location().end_pos); | 2951 scope->set_end_position(scanner()->location().end_pos); |
2932 | 2952 |
2933 // Arrow function *parameter lists* are always checked as in strict mode. | 2953 // Arrow function *parameter lists* are always checked as in strict mode. |
2934 // TODO(arv): eval_args_error_loc and reserved_loc needs to be set by | 2954 // TODO(arv): eval_args_error_loc and reserved_loc needs to be set by |
2935 // DeclareArrowParametersFromExpression. | 2955 // DeclareArrowParametersFromExpression. |
2936 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); | 2956 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); |
2937 Scanner::Location reserved_loc = Scanner::Location::invalid(); | 2957 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
2938 const bool use_strict_params = true; | 2958 const bool use_strict_params = true; |
2939 this->CheckFunctionParameterNames(language_mode(), use_strict_params, | 2959 this->CheckFunctionParameterNames(language_mode(), use_strict_params, |
2940 eval_args_error_loc, dupe_error_loc, reserved_loc, CHECK_OK); | 2960 eval_args_error_loc, dupe_error_loc, reserved_loc, CHECK_OK); |
2941 | 2961 |
2942 // Validate strict mode. | 2962 // Validate strict mode. |
2943 if (is_strict(language_mode())) { | 2963 if (is_strict(language_mode())) { |
2944 CheckStrictOctalLiteral(start_pos, scanner()->location().end_pos, | 2964 CheckStrictOctalLiteral(start_pos, scanner()->location().end_pos, |
2945 CHECK_OK); | 2965 CHECK_OK); |
2946 } | 2966 } |
2947 | 2967 |
2948 if (allow_harmony_scoping() && is_strict(language_mode())) | 2968 if (allow_harmony_scoping() && is_strict(language_mode())) { |
2949 this->CheckConflictingVarDeclarations(scope, CHECK_OK); | 2969 this->CheckConflictingVarDeclarations(scope, CHECK_OK); |
| 2970 } |
2950 } | 2971 } |
2951 | 2972 |
2952 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 2973 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
2953 this->EmptyIdentifierString(), ast_value_factory(), scope, body, | 2974 this->EmptyIdentifierString(), ast_value_factory(), scope, body, |
2954 materialized_literal_count, expected_property_count, handler_count, | 2975 materialized_literal_count, expected_property_count, handler_count, |
2955 num_parameters, FunctionLiteral::kNoDuplicateParameters, | 2976 num_parameters, FunctionLiteral::kNoDuplicateParameters, |
2956 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 2977 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
2957 FunctionLiteral::kNotParenthesized, FunctionKind::kArrowFunction, | 2978 FunctionLiteral::kNotParenthesized, FunctionKind::kArrowFunction, |
2958 start_pos); | 2979 start_pos); |
2959 | 2980 |
2960 function_literal->set_function_token_position(start_pos); | 2981 function_literal->set_function_token_position(start_pos); |
| 2982 if (super_loc.IsValid()) function_state_->set_super_call_location(super_loc); |
2961 | 2983 |
2962 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); | 2984 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
2963 | 2985 |
2964 return function_literal; | 2986 return function_literal; |
2965 } | 2987 } |
2966 | 2988 |
2967 | 2989 |
2968 template <typename Traits> | 2990 template <typename Traits> |
2969 typename ParserBase<Traits>::ExpressionT | 2991 typename ParserBase<Traits>::ExpressionT |
2970 ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) { | 2992 ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) { |
(...skipping 164 matching lines...) Loading... |
3135 *ok = false; | 3157 *ok = false; |
3136 return; | 3158 return; |
3137 } | 3159 } |
3138 has_seen_constructor_ = true; | 3160 has_seen_constructor_ = true; |
3139 return; | 3161 return; |
3140 } | 3162 } |
3141 } | 3163 } |
3142 } } // v8::internal | 3164 } } // v8::internal |
3143 | 3165 |
3144 #endif // V8_PREPARSER_H | 3166 #endif // V8_PREPARSER_H |
OLD | NEW |