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

Side by Side Diff: src/preparser.h

Issue 1002253002: [strong] Check super constructor calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Should be ReferenceError Created 5 years, 9 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 unified diff | Download patch
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 int materialized_literal_count() { 210 int materialized_literal_count() {
211 return next_materialized_literal_index_; 211 return next_materialized_literal_index_;
212 } 212 }
213 213
214 int NextHandlerIndex() { return next_handler_index_++; } 214 int NextHandlerIndex() { return next_handler_index_++; }
215 int handler_count() { return next_handler_index_; } 215 int handler_count() { return next_handler_index_; }
216 216
217 void AddProperty() { expected_property_count_++; } 217 void AddProperty() { expected_property_count_++; }
218 int expected_property_count() { return expected_property_count_; } 218 int expected_property_count() { return expected_property_count_; }
219 219
220 Scanner::Location super_call_location() const {
221 return super_call_location_;
222 }
223 void set_super_call_location(Scanner::Location location) {
224 super_call_location_ = location;
225 }
226
220 bool is_generator() const { return IsGeneratorFunction(kind_); } 227 bool is_generator() const { return IsGeneratorFunction(kind_); }
221 228
222 FunctionKind kind() const { return kind_; } 229 FunctionKind kind() const { return kind_; }
223 FunctionState* outer() const { return outer_function_state_; } 230 FunctionState* outer() const { return outer_function_state_; }
224 231
225 void set_generator_object_variable( 232 void set_generator_object_variable(
226 typename Traits::Type::GeneratorVariable* variable) { 233 typename Traits::Type::GeneratorVariable* variable) {
227 DCHECK(variable != NULL); 234 DCHECK(variable != NULL);
228 DCHECK(is_generator()); 235 DCHECK(is_generator());
229 generator_object_variable_ = variable; 236 generator_object_variable_ = variable;
(...skipping 10 matching lines...) Expand all
240 // the function. Includes regexp literals, and boilerplate for object and 247 // the function. Includes regexp literals, and boilerplate for object and
241 // array literals. 248 // array literals.
242 int next_materialized_literal_index_; 249 int next_materialized_literal_index_;
243 250
244 // Used to assign a per-function index to try and catch handlers. 251 // Used to assign a per-function index to try and catch handlers.
245 int next_handler_index_; 252 int next_handler_index_;
246 253
247 // Properties count estimation. 254 // Properties count estimation.
248 int expected_property_count_; 255 int expected_property_count_;
249 256
257 // Location of call to the "super" constructor (invalid if none).
258 Scanner::Location super_call_location_;
259
250 FunctionKind kind_; 260 FunctionKind kind_;
251 // For generators, this variable may hold the generator object. It variable 261 // For generators, this variable may hold the generator object. It variable
252 // is used by yield expressions and return statements. It is not necessary 262 // is used by yield expressions and return statements. It is not necessary
253 // for generator functions to have this variable set. 263 // for generator functions to have this variable set.
254 Variable* generator_object_variable_; 264 Variable* generator_object_variable_;
255 265
256 FunctionState** function_state_stack_; 266 FunctionState** function_state_stack_;
257 FunctionState* outer_function_state_; 267 FunctionState* outer_function_state_;
258 Scope** scope_stack_; 268 Scope** scope_stack_;
259 Scope* outer_scope_; 269 Scope* outer_scope_;
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 } 1660 }
1651 1661
1652 1662
1653 template <class Traits> 1663 template <class Traits>
1654 ParserBase<Traits>::FunctionState::FunctionState( 1664 ParserBase<Traits>::FunctionState::FunctionState(
1655 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, 1665 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope,
1656 FunctionKind kind, typename Traits::Type::Factory* factory) 1666 FunctionKind kind, typename Traits::Type::Factory* factory)
1657 : next_materialized_literal_index_(0), 1667 : next_materialized_literal_index_(0),
1658 next_handler_index_(0), 1668 next_handler_index_(0),
1659 expected_property_count_(0), 1669 expected_property_count_(0),
1670 super_call_location_(Scanner::Location::invalid()),
1660 kind_(kind), 1671 kind_(kind),
1661 generator_object_variable_(NULL), 1672 generator_object_variable_(NULL),
1662 function_state_stack_(function_state_stack), 1673 function_state_stack_(function_state_stack),
1663 outer_function_state_(*function_state_stack), 1674 outer_function_state_(*function_state_stack),
1664 scope_stack_(scope_stack), 1675 scope_stack_(scope_stack),
1665 outer_scope_(*scope_stack), 1676 outer_scope_(*scope_stack),
1666 factory_(factory) { 1677 factory_(factory) {
1667 *scope_stack_ = scope; 1678 *scope_stack_ = scope;
1668 *function_state_stack = this; 1679 *function_state_stack = this;
1669 } 1680 }
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2774 FunctionKind kind = function_state->kind(); 2785 FunctionKind kind = function_state->kind();
2775 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || 2786 if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
2776 i::IsConstructor(kind)) { 2787 i::IsConstructor(kind)) {
2777 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { 2788 if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
2778 scope_->RecordSuperPropertyUsage(); 2789 scope_->RecordSuperPropertyUsage();
2779 return this->SuperReference(scope_, factory()); 2790 return this->SuperReference(scope_, factory());
2780 } 2791 }
2781 // new super() is never allowed. 2792 // new super() is never allowed.
2782 // super() is only allowed in derived constructor 2793 // super() is only allowed in derived constructor
2783 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { 2794 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) {
2795 if (is_strong(language_mode()) &&
2796 function_state->super_call_location().IsValid()) {
2797 ReportMessageAt(scanner()->location(), "strong_super_call_duplicate");
2798 *ok = false;
2799 return this->EmptyExpression();
2800 }
2801 function_state->set_super_call_location(scanner()->location());
2784 return this->SuperReference(scope_, factory()); 2802 return this->SuperReference(scope_, factory());
2785 } 2803 }
2786 } 2804 }
2787 2805
2788 ReportMessageAt(scanner()->location(), "unexpected_super"); 2806 ReportMessageAt(scanner()->location(), "unexpected_super");
2789 *ok = false; 2807 *ok = false;
2790 return this->EmptyExpression(); 2808 return this->EmptyExpression();
2791 } 2809 }
2792 2810
2793 2811
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
2859 *ok = false; 2877 *ok = false;
2860 return this->EmptyExpression(); 2878 return this->EmptyExpression();
2861 } 2879 }
2862 2880
2863 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); 2881 Scope* scope = this->NewScope(scope_, ARROW_SCOPE);
2864 typename Traits::Type::StatementList body; 2882 typename Traits::Type::StatementList body;
2865 int num_parameters = -1; 2883 int num_parameters = -1;
2866 int materialized_literal_count = -1; 2884 int materialized_literal_count = -1;
2867 int expected_property_count = -1; 2885 int expected_property_count = -1;
2868 int handler_count = 0; 2886 int handler_count = 0;
2887 Scanner::Location super_loc;
2869 2888
2870 { 2889 {
2871 typename Traits::Type::Factory function_factory(ast_value_factory()); 2890 typename Traits::Type::Factory function_factory(ast_value_factory());
2872 FunctionState function_state(&function_state_, &scope_, scope, 2891 FunctionState function_state(&function_state_, &scope_, scope,
2873 kArrowFunction, &function_factory); 2892 kArrowFunction, &function_factory);
2874 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 2893 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
2875 // TODO(arv): Pass in eval_args_error_loc and reserved_loc here. 2894 // TODO(arv): Pass in eval_args_error_loc and reserved_loc here.
2876 num_parameters = Traits::DeclareArrowParametersFromExpression( 2895 num_parameters = Traits::DeclareArrowParametersFromExpression(
2877 params_ast, scope_, &dupe_error_loc, ok); 2896 params_ast, scope_, &dupe_error_loc, ok);
2878 if (!*ok) { 2897 if (!*ok) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2914 // Single-expression body 2933 // Single-expression body
2915 int pos = position(); 2934 int pos = position();
2916 parenthesized_function_ = false; 2935 parenthesized_function_ = false;
2917 ExpressionT expression = ParseAssignmentExpression(true, CHECK_OK); 2936 ExpressionT expression = ParseAssignmentExpression(true, CHECK_OK);
2918 body = this->NewStatementList(1, zone()); 2937 body = this->NewStatementList(1, zone());
2919 body->Add(factory()->NewReturnStatement(expression, pos), zone()); 2938 body->Add(factory()->NewReturnStatement(expression, pos), zone());
2920 materialized_literal_count = function_state.materialized_literal_count(); 2939 materialized_literal_count = function_state.materialized_literal_count();
2921 expected_property_count = function_state.expected_property_count(); 2940 expected_property_count = function_state.expected_property_count();
2922 handler_count = function_state.handler_count(); 2941 handler_count = function_state.handler_count();
2923 } 2942 }
2943 super_loc = function_state.super_call_location();
2924 2944
2925 scope->set_start_position(start_pos); 2945 scope->set_start_position(start_pos);
2926 scope->set_end_position(scanner()->location().end_pos); 2946 scope->set_end_position(scanner()->location().end_pos);
2927 2947
2928 // Arrow function *parameter lists* are always checked as in strict mode. 2948 // Arrow function *parameter lists* are always checked as in strict mode.
2929 // TODO(arv): eval_args_error_loc and reserved_loc needs to be set by 2949 // TODO(arv): eval_args_error_loc and reserved_loc needs to be set by
2930 // DeclareArrowParametersFromExpression. 2950 // DeclareArrowParametersFromExpression.
2931 Scanner::Location eval_args_error_loc = Scanner::Location::invalid(); 2951 Scanner::Location eval_args_error_loc = Scanner::Location::invalid();
2932 Scanner::Location reserved_loc = Scanner::Location::invalid(); 2952 Scanner::Location reserved_loc = Scanner::Location::invalid();
2933 const bool use_strict_params = true; 2953 const bool use_strict_params = true;
(...skipping 10 matching lines...) Expand all
2944 2964
2945 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( 2965 FunctionLiteralT function_literal = factory()->NewFunctionLiteral(
2946 this->EmptyIdentifierString(), ast_value_factory(), scope, body, 2966 this->EmptyIdentifierString(), ast_value_factory(), scope, body,
2947 materialized_literal_count, expected_property_count, handler_count, 2967 materialized_literal_count, expected_property_count, handler_count,
2948 num_parameters, FunctionLiteral::kNoDuplicateParameters, 2968 num_parameters, FunctionLiteral::kNoDuplicateParameters,
2949 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, 2969 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
2950 FunctionLiteral::kNotParenthesized, FunctionKind::kArrowFunction, 2970 FunctionLiteral::kNotParenthesized, FunctionKind::kArrowFunction,
2951 start_pos); 2971 start_pos);
2952 2972
2953 function_literal->set_function_token_position(start_pos); 2973 function_literal->set_function_token_position(start_pos);
2974 if (super_loc.IsValid()) function_state_->set_super_call_location(super_loc);
2954 2975
2955 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); 2976 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal);
2956 2977
2957 return function_literal; 2978 return function_literal;
2958 } 2979 }
2959 2980
2960 2981
2961 template <typename Traits> 2982 template <typename Traits>
2962 typename ParserBase<Traits>::ExpressionT 2983 typename ParserBase<Traits>::ExpressionT
2963 ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) { 2984 ParserBase<Traits>::ParseTemplateLiteral(ExpressionT tag, int start, bool* ok) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
3128 *ok = false; 3149 *ok = false;
3129 return; 3150 return;
3130 } 3151 }
3131 has_seen_constructor_ = true; 3152 has_seen_constructor_ = true;
3132 return; 3153 return;
3133 } 3154 }
3134 } 3155 }
3135 } } // v8::internal 3156 } } // v8::internal
3136 3157
3137 #endif // V8_PREPARSER_H 3158 #endif // V8_PREPARSER_H
OLDNEW
« 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