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

Side by Side Diff: src/parser.cc

Issue 867153003: new classes: special construct stub for derived classs and TDZ for `this`. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: CR feedback 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 unified diff | Download patch
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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 cached_parse_data_ = NULL; 256 cached_parse_data_ = NULL;
257 } else { 257 } else {
258 DCHECK(info_->cached_data() != NULL); 258 DCHECK(info_->cached_data() != NULL);
259 if (compile_options() == ScriptCompiler::kConsumeParserCache) { 259 if (compile_options() == ScriptCompiler::kConsumeParserCache) {
260 cached_parse_data_ = ParseData::FromCachedData(*info_->cached_data()); 260 cached_parse_data_ = ParseData::FromCachedData(*info_->cached_data());
261 } 261 }
262 } 262 }
263 } 263 }
264 264
265 265
266 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { 266 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type,
267 FunctionKind kind) {
267 DCHECK(ast_value_factory()); 268 DCHECK(ast_value_factory());
269 DCHECK((scope_type == FUNCTION_SCOPE && IsValidFunctionKind(kind)) ||
270 kind == kNormalFunction);
268 Scope* result = 271 Scope* result =
269 new (zone()) Scope(parent, scope_type, ast_value_factory(), zone()); 272 new (zone()) Scope(parent, scope_type, ast_value_factory(), zone());
270 result->Initialize(); 273 bool uninitialized_this =
274 FLAG_experimental_classes && IsSubclassConstructor(kind);
275 result->Initialize(uninitialized_this);
271 return result; 276 return result;
272 } 277 }
273 278
274 279
275 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, 280 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
276 int pos, int end_pos) { 281 int pos, int end_pos) {
277 int materialized_literal_count = -1; 282 int materialized_literal_count = -1;
278 int expected_property_count = -1; 283 int expected_property_count = -1;
279 int handler_count = 0; 284 int handler_count = 0;
280 int parameter_count = 0; 285 int parameter_count = 0;
281 const AstRawString* name = ast_value_factory()->empty_string(); 286 const AstRawString* name = ast_value_factory()->empty_string();
282 287
283 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE); 288 Scope* function_scope =
289 NewScope(scope, FUNCTION_SCOPE, FunctionKind::kDefaultConstructor);
284 function_scope->SetStrictMode(STRICT); 290 function_scope->SetStrictMode(STRICT);
285 // Set start and end position to the same value 291 // Set start and end position to the same value
286 function_scope->set_start_position(pos); 292 function_scope->set_start_position(pos);
287 function_scope->set_end_position(pos); 293 function_scope->set_end_position(pos);
288 ZoneList<Statement*>* body = NULL; 294 ZoneList<Statement*>* body = NULL;
289 295
290 { 296 {
291 AstNodeFactory function_factory(ast_value_factory()); 297 AstNodeFactory function_factory(ast_value_factory());
292 FunctionState function_state(&function_state_, &scope_, function_scope, 298 FunctionState function_state(&function_state_, &scope_, function_scope,
293 &function_factory); 299 &function_factory);
(...skipping 3307 matching lines...) Expand 10 before | Expand all | Expand 10 after
3601 // in all normal cases, function declarations are fully hoisted to a 3607 // in all normal cases, function declarations are fully hoisted to a
3602 // declaration scope and compiled relative to that. 3608 // declaration scope and compiled relative to that.
3603 // - (2) is the case iff the current declaration scope is still the original 3609 // - (2) is the case iff the current declaration scope is still the original
3604 // one relative to the deserialized scope chain. Otherwise we must be 3610 // one relative to the deserialized scope chain. Otherwise we must be
3605 // compiling a function in an inner declaration scope in the eval, e.g. a 3611 // compiling a function in an inner declaration scope in the eval, e.g. a
3606 // nested function, and hoisting works normally relative to that. 3612 // nested function, and hoisting works normally relative to that.
3607 Scope* declaration_scope = scope_->DeclarationScope(); 3613 Scope* declaration_scope = scope_->DeclarationScope();
3608 Scope* original_declaration_scope = original_scope_->DeclarationScope(); 3614 Scope* original_declaration_scope = original_scope_->DeclarationScope();
3609 Scope* scope = 3615 Scope* scope =
3610 function_type == FunctionLiteral::DECLARATION && 3616 function_type == FunctionLiteral::DECLARATION &&
3611 (!allow_harmony_scoping() || strict_mode() == SLOPPY) && 3617 (!allow_harmony_scoping() || strict_mode() == SLOPPY) &&
3612 (original_scope_ == original_declaration_scope || 3618 (original_scope_ == original_declaration_scope ||
3613 declaration_scope != original_declaration_scope) 3619 declaration_scope != original_declaration_scope)
3614 ? NewScope(declaration_scope, FUNCTION_SCOPE) 3620 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind)
3615 : NewScope(scope_, FUNCTION_SCOPE); 3621 : NewScope(scope_, FUNCTION_SCOPE, kind);
3616 ZoneList<Statement*>* body = NULL; 3622 ZoneList<Statement*>* body = NULL;
3617 int materialized_literal_count = -1; 3623 int materialized_literal_count = -1;
3618 int expected_property_count = -1; 3624 int expected_property_count = -1;
3619 int handler_count = 0; 3625 int handler_count = 0;
3620 FunctionLiteral::ParameterFlag duplicate_parameters = 3626 FunctionLiteral::ParameterFlag duplicate_parameters =
3621 FunctionLiteral::kNoDuplicateParameters; 3627 FunctionLiteral::kNoDuplicateParameters;
3622 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ 3628 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_
3623 ? FunctionLiteral::kIsParenthesized 3629 ? FunctionLiteral::kIsParenthesized
3624 : FunctionLiteral::kNotParenthesized; 3630 : FunctionLiteral::kNotParenthesized;
3625 // Parse function body. 3631 // Parse function body.
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
4005 extends = ParseLeftHandSideExpression(CHECK_OK); 4011 extends = ParseLeftHandSideExpression(CHECK_OK);
4006 } else { 4012 } else {
4007 block_scope->set_start_position(scanner()->location().end_pos); 4013 block_scope->set_start_position(scanner()->location().end_pos);
4008 } 4014 }
4009 4015
4010 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); 4016 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone());
4011 FunctionLiteral* constructor = NULL; 4017 FunctionLiteral* constructor = NULL;
4012 bool has_seen_constructor = false; 4018 bool has_seen_constructor = false;
4013 4019
4014 Expect(Token::LBRACE, CHECK_OK); 4020 Expect(Token::LBRACE, CHECK_OK);
4021 const bool has_extends = extends != nullptr;
4015 while (peek() != Token::RBRACE) { 4022 while (peek() != Token::RBRACE) {
4016 if (Check(Token::SEMICOLON)) continue; 4023 if (Check(Token::SEMICOLON)) continue;
4017 if (fni_ != NULL) fni_->Enter(); 4024 if (fni_ != NULL) fni_->Enter();
4018 const bool in_class = true; 4025 const bool in_class = true;
4019 const bool is_static = false; 4026 const bool is_static = false;
4020 bool is_computed_name = false; // Classes do not care about computed 4027 bool is_computed_name = false; // Classes do not care about computed
4021 // property names here. 4028 // property names here.
4022 ObjectLiteral::Property* property = 4029 ObjectLiteral::Property* property = ParsePropertyDefinition(
4023 ParsePropertyDefinition(NULL, in_class, is_static, &is_computed_name, 4030 nullptr, in_class, has_extends, is_static, &is_computed_name,
4024 &has_seen_constructor, CHECK_OK); 4031 &has_seen_constructor, CHECK_OK);
4025 4032
4026 if (has_seen_constructor && constructor == NULL) { 4033 if (has_seen_constructor && constructor == NULL) {
4027 constructor = GetPropertyValue(property)->AsFunctionLiteral(); 4034 constructor = GetPropertyValue(property)->AsFunctionLiteral();
4028 DCHECK_NOT_NULL(constructor); 4035 DCHECK_NOT_NULL(constructor);
4029 } else { 4036 } else {
4030 properties->Add(property, zone()); 4037 properties->Add(property, zone());
4031 } 4038 }
4032 4039
4033 if (fni_ != NULL) { 4040 if (fni_ != NULL) {
4034 fni_->Infer(); 4041 fni_->Infer();
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after
5341 } else { 5348 } else {
5342 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5349 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5343 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5350 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5344 raw_string->length()); 5351 raw_string->length());
5345 } 5352 }
5346 } 5353 }
5347 5354
5348 return running_hash; 5355 return running_hash;
5349 } 5356 }
5350 } } // namespace v8::internal 5357 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698