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

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: CHECK_OK fixed 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
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('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 #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());
268 DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules()); 269 DCHECK(scope_type != MODULE_SCOPE || allow_harmony_modules());
270 DCHECK((scope_type == FUNCTION_SCOPE && IsValidFunctionKind(kind)) ||
271 kind == kNormalFunction);
269 Scope* result = new (zone()) 272 Scope* result = new (zone())
270 Scope(isolate(), zone(), parent, scope_type, ast_value_factory()); 273 Scope(isolate(), zone(), parent, scope_type, ast_value_factory());
271 result->Initialize(); 274 bool uninitialized_this =
275 FLAG_experimental_classes && IsSubclassConstructor(kind);
276 result->Initialize(uninitialized_this);
272 return result; 277 return result;
273 } 278 }
274 279
275 280
276 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope, 281 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope,
277 int pos, int end_pos) { 282 int pos, int end_pos) {
278 int materialized_literal_count = -1; 283 int materialized_literal_count = -1;
279 int expected_property_count = -1; 284 int expected_property_count = -1;
280 int handler_count = 0; 285 int handler_count = 0;
281 int parameter_count = 0; 286 int parameter_count = 0;
282 const AstRawString* name = ast_value_factory()->empty_string(); 287 const AstRawString* name = ast_value_factory()->empty_string();
283 288
284 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE); 289 Scope* function_scope =
290 NewScope(scope, FUNCTION_SCOPE, FunctionKind::kDefaultConstructor);
285 function_scope->SetStrictMode(STRICT); 291 function_scope->SetStrictMode(STRICT);
286 // Set start and end position to the same value 292 // Set start and end position to the same value
287 function_scope->set_start_position(pos); 293 function_scope->set_start_position(pos);
288 function_scope->set_end_position(pos); 294 function_scope->set_end_position(pos);
289 ZoneList<Statement*>* body = NULL; 295 ZoneList<Statement*>* body = NULL;
290 296
291 { 297 {
292 AstNodeFactory function_factory(ast_value_factory()); 298 AstNodeFactory function_factory(ast_value_factory());
293 FunctionState function_state(&function_state_, &scope_, function_scope, 299 FunctionState function_state(&function_state_, &scope_, function_scope,
294 &function_factory); 300 &function_factory);
(...skipping 3327 matching lines...) Expand 10 before | Expand all | Expand 10 after
3622 // in all normal cases, function declarations are fully hoisted to a 3628 // in all normal cases, function declarations are fully hoisted to a
3623 // declaration scope and compiled relative to that. 3629 // declaration scope and compiled relative to that.
3624 // - (2) is the case iff the current declaration scope is still the original 3630 // - (2) is the case iff the current declaration scope is still the original
3625 // one relative to the deserialized scope chain. Otherwise we must be 3631 // one relative to the deserialized scope chain. Otherwise we must be
3626 // compiling a function in an inner declaration scope in the eval, e.g. a 3632 // compiling a function in an inner declaration scope in the eval, e.g. a
3627 // nested function, and hoisting works normally relative to that. 3633 // nested function, and hoisting works normally relative to that.
3628 Scope* declaration_scope = scope_->DeclarationScope(); 3634 Scope* declaration_scope = scope_->DeclarationScope();
3629 Scope* original_declaration_scope = original_scope_->DeclarationScope(); 3635 Scope* original_declaration_scope = original_scope_->DeclarationScope();
3630 Scope* scope = 3636 Scope* scope =
3631 function_type == FunctionLiteral::DECLARATION && 3637 function_type == FunctionLiteral::DECLARATION &&
3632 (!allow_harmony_scoping() || strict_mode() == SLOPPY) && 3638 (!allow_harmony_scoping() || strict_mode() == SLOPPY) &&
3633 (original_scope_ == original_declaration_scope || 3639 (original_scope_ == original_declaration_scope ||
3634 declaration_scope != original_declaration_scope) 3640 declaration_scope != original_declaration_scope)
3635 ? NewScope(declaration_scope, FUNCTION_SCOPE) 3641 ? NewScope(declaration_scope, FUNCTION_SCOPE, kind)
3636 : NewScope(scope_, FUNCTION_SCOPE); 3642 : NewScope(scope_, FUNCTION_SCOPE, kind);
3637 ZoneList<Statement*>* body = NULL; 3643 ZoneList<Statement*>* body = NULL;
3638 int materialized_literal_count = -1; 3644 int materialized_literal_count = -1;
3639 int expected_property_count = -1; 3645 int expected_property_count = -1;
3640 int handler_count = 0; 3646 int handler_count = 0;
3641 FunctionLiteral::ParameterFlag duplicate_parameters = 3647 FunctionLiteral::ParameterFlag duplicate_parameters =
3642 FunctionLiteral::kNoDuplicateParameters; 3648 FunctionLiteral::kNoDuplicateParameters;
3643 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ 3649 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_
3644 ? FunctionLiteral::kIsParenthesized 3650 ? FunctionLiteral::kIsParenthesized
3645 : FunctionLiteral::kNotParenthesized; 3651 : FunctionLiteral::kNotParenthesized;
3646 // Parse function body. 3652 // Parse function body.
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
4046 block_scope->set_start_position(scanner()->location().end_pos); 4052 block_scope->set_start_position(scanner()->location().end_pos);
4047 } 4053 }
4048 4054
4049 4055
4050 ClassLiteralChecker checker(this); 4056 ClassLiteralChecker checker(this);
4051 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); 4057 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone());
4052 FunctionLiteral* constructor = NULL; 4058 FunctionLiteral* constructor = NULL;
4053 bool has_seen_constructor = false; 4059 bool has_seen_constructor = false;
4054 4060
4055 Expect(Token::LBRACE, CHECK_OK); 4061 Expect(Token::LBRACE, CHECK_OK);
4062 const bool has_extends = extends != nullptr;
4056 while (peek() != Token::RBRACE) { 4063 while (peek() != Token::RBRACE) {
4057 if (Check(Token::SEMICOLON)) continue; 4064 if (Check(Token::SEMICOLON)) continue;
4058 if (fni_ != NULL) fni_->Enter(); 4065 if (fni_ != NULL) fni_->Enter();
4059 const bool in_class = true; 4066 const bool in_class = true;
4060 const bool is_static = false; 4067 const bool is_static = false;
4061 bool is_computed_name = false; // Classes do not care about computed 4068 bool is_computed_name = false; // Classes do not care about computed
4062 // property names here. 4069 // property names here.
4063 ObjectLiteral::Property* property = ParsePropertyDefinition( 4070 ObjectLiteral::Property* property = ParsePropertyDefinition(
4064 &checker, in_class, is_static, &is_computed_name, &has_seen_constructor, 4071 &checker, in_class, has_extends, is_static, &is_computed_name,
4065 CHECK_OK); 4072 &has_seen_constructor, CHECK_OK);
4066 4073
4067 if (has_seen_constructor && constructor == NULL) { 4074 if (has_seen_constructor && constructor == NULL) {
4068 constructor = GetPropertyValue(property)->AsFunctionLiteral(); 4075 constructor = GetPropertyValue(property)->AsFunctionLiteral();
4069 DCHECK_NOT_NULL(constructor); 4076 DCHECK_NOT_NULL(constructor);
4070 } else { 4077 } else {
4071 properties->Add(property, zone()); 4078 properties->Add(property, zone());
4072 } 4079 }
4073 4080
4074 if (fni_ != NULL) { 4081 if (fni_ != NULL) {
4075 fni_->Infer(); 4082 fni_->Infer();
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
5402 } else { 5409 } else {
5403 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); 5410 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data());
5404 running_hash = StringHasher::ComputeRunningHash(running_hash, data, 5411 running_hash = StringHasher::ComputeRunningHash(running_hash, data,
5405 raw_string->length()); 5412 raw_string->length());
5406 } 5413 }
5407 } 5414 }
5408 5415
5409 return running_hash; 5416 return running_hash;
5410 } 5417 }
5411 } } // namespace v8::internal 5418 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698