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

Side by Side Diff: src/preparser.cc

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/preparser.h ('k') | test/cctest/test-parsing.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 #include <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 void PreParser::ParseStatementList(int end_token, bool* ok) { 187 void PreParser::ParseStatementList(int end_token, bool* ok) {
188 // SourceElements :: 188 // SourceElements ::
189 // (Statement)* <end_token> 189 // (Statement)* <end_token>
190 190
191 bool directive_prologue = true; 191 bool directive_prologue = true;
192 while (peek() != end_token) { 192 while (peek() != end_token) {
193 if (directive_prologue && peek() != Token::STRING) { 193 if (directive_prologue && peek() != Token::STRING) {
194 directive_prologue = false; 194 directive_prologue = false;
195 } 195 }
196 Token::Value token = peek();
197 Scanner::Location old_super_loc = function_state_->super_call_location();
196 Statement statement = ParseStatementListItem(ok); 198 Statement statement = ParseStatementListItem(ok);
197 if (!*ok) return; 199 if (!*ok) return;
200 Scanner::Location super_loc = function_state_->super_call_location();
201 if (is_strong(language_mode()) &&
202 i::IsConstructor(function_state_->kind()) &&
203 !old_super_loc.IsValid() && super_loc.IsValid() &&
204 token != Token::SUPER) {
205 ReportMessageAt(super_loc, "strong_super_call_nested");
206 *ok = false;
207 return;
208 }
198 if (directive_prologue) { 209 if (directive_prologue) {
199 if (statement.IsUseStrictLiteral()) { 210 if (statement.IsUseStrictLiteral()) {
200 scope_->SetLanguageMode( 211 scope_->SetLanguageMode(
201 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT)); 212 static_cast<LanguageMode>(scope_->language_mode() | STRICT_BIT));
202 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) { 213 } else if (statement.IsUseStrongLiteral() && allow_strong_mode()) {
203 scope_->SetLanguageMode(static_cast<LanguageMode>( 214 scope_->SetLanguageMode(static_cast<LanguageMode>(
204 scope_->language_mode() | STRICT_BIT | STRONG_BIT)); 215 scope_->language_mode() | STRICT_BIT | STRONG_BIT));
205 } else if (!statement.IsStringLiteral()) { 216 } else if (!statement.IsStringLiteral()) {
206 directive_prologue = false; 217 directive_prologue = false;
207 } 218 }
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 const bool use_strict_params = is_rest || IsConciseMethod(kind); 942 const bool use_strict_params = is_rest || IsConciseMethod(kind);
932 CheckFunctionParameterNames(language_mode(), use_strict_params, 943 CheckFunctionParameterNames(language_mode(), use_strict_params,
933 eval_args_error_loc, dupe_error_loc, 944 eval_args_error_loc, dupe_error_loc,
934 reserved_error_loc, CHECK_OK); 945 reserved_error_loc, CHECK_OK);
935 946
936 if (is_strict(language_mode())) { 947 if (is_strict(language_mode())) {
937 int end_position = scanner()->location().end_pos; 948 int end_position = scanner()->location().end_pos;
938 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK); 949 CheckStrictOctalLiteral(start_position, end_position, CHECK_OK);
939 } 950 }
940 951
952 if (is_strong(language_mode()) && IsSubclassConstructor(kind)) {
953 if (!function_state.super_call_location().IsValid()) {
954 ReportMessageAt(function_name_location, "strong_super_call_missing",
955 kReferenceError);
956 *ok = false;
957 return Expression::Default();
958 }
959 }
960
941 return Expression::Default(); 961 return Expression::Default();
942 } 962 }
943 963
944 964
945 void PreParser::ParseLazyFunctionLiteralBody(bool* ok) { 965 void PreParser::ParseLazyFunctionLiteralBody(bool* ok) {
946 int body_start = position(); 966 int body_start = position();
947 ParseStatementList(Token::RBRACE, ok); 967 ParseStatementList(Token::RBRACE, ok);
948 if (!*ok) return; 968 if (!*ok) return;
949 969
950 // Position right after terminal '}'. 970 // Position right after terminal '}'.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK); 1036 ParseIdentifier(kAllowEvalOrArguments, CHECK_OK);
1017 ParseArguments(ok); 1037 ParseArguments(ok);
1018 1038
1019 return Expression::Default(); 1039 return Expression::Default();
1020 } 1040 }
1021 1041
1022 #undef CHECK_OK 1042 #undef CHECK_OK
1023 1043
1024 1044
1025 } } // v8::internal 1045 } } // v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698