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

Side by Side Diff: src/parser.cc

Issue 700523003: Classes: Partial fix for constructor not calling super (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { 269 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) {
270 DCHECK(ast_value_factory()); 270 DCHECK(ast_value_factory());
271 Scope* result = 271 Scope* result =
272 new (zone()) Scope(parent, scope_type, ast_value_factory(), zone()); 272 new (zone()) Scope(parent, scope_type, ast_value_factory(), zone());
273 result->Initialize(); 273 result->Initialize();
274 return result; 274 return result;
275 } 275 }
276 276
277 277
278 FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope) {
279 int materialized_literal_count = -1;
280 int expected_property_count = -1;
281 int handler_count = 0;
282 int parameter_count = 0;
283 AstProperties ast_properties;
284 BailoutReason dont_optimize_reason = kNoReason;
285 const AstRawString* name = ast_value_factory()->empty_string();
286 FunctionKind kind = call_super ? FunctionKind::kDefaultConstructorCallSuper
287 : FunctionKind::kDefaultConstructor;
288
289 Scope* function_scope = NewScope(scope, FUNCTION_SCOPE);
290 function_scope->SetStrictMode(STRICT);
291 ZoneList<Statement*>* body = NULL;
292 int pos = RelocInfo::kNoPosition;
293
294 {
295 AstNodeFactory<AstConstructionVisitor> function_factory(
296 ast_value_factory());
297 FunctionState function_state(&function_state_, &scope_, function_scope,
298 &function_factory);
299
300 body = new (zone()) ZoneList<Statement*>(1, zone());
301 if (call_super) {
302 Expression* prop = SuperReference(function_scope, factory(), pos);
303 ZoneList<Expression*>* args =
304 new (zone()) ZoneList<Expression*>(0, zone());
305 Call* call = factory()->NewCall(prop, args, pos);
306
307 DCHECK(call->GetCallType(isolate()) == Call::SUPER_CALL);
308
309 body->Add(factory()->NewExpressionStatement(call, pos), zone());
310 }
311
312 materialized_literal_count = function_state.materialized_literal_count();
313 expected_property_count = function_state.expected_property_count();
314 handler_count = function_state.handler_count();
315
316 ast_properties = *factory()->visitor()->ast_properties();
317 dont_optimize_reason = factory()->visitor()->dont_optimize_reason();
318 }
319
320 FunctionLiteral* function_literal = factory()->NewFunctionLiteral(
321 name, ast_value_factory(), function_scope, body,
322 materialized_literal_count, expected_property_count, handler_count,
323 parameter_count, FunctionLiteral::kNoDuplicateParameters,
324 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction,
325 FunctionLiteral::kNotParenthesized, kind, pos);
326
327 function_literal->set_ast_properties(&ast_properties);
328 function_literal->set_dont_optimize_reason(dont_optimize_reason);
329
330 return function_literal;
331 }
332
333
278 // ---------------------------------------------------------------------------- 334 // ----------------------------------------------------------------------------
279 // Target is a support class to facilitate manipulation of the 335 // Target is a support class to facilitate manipulation of the
280 // Parser's target_stack_ (the stack of potential 'break' and 336 // Parser's target_stack_ (the stack of potential 'break' and
281 // 'continue' statement targets). Upon construction, a new target is 337 // 'continue' statement targets). Upon construction, a new target is
282 // added; it is removed upon destruction. 338 // added; it is removed upon destruction.
283 339
284 class Target BASE_EMBEDDED { 340 class Target BASE_EMBEDDED {
285 public: 341 public:
286 Target(Target** variable, AstNode* node) 342 Target(Target** variable, AstNode* node)
287 : variable_(variable), node_(node), previous_(*variable) { 343 : variable_(variable), node_(node), previous_(*variable) {
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 } 697 }
642 698
643 Expression* ParserTraits::ClassExpression( 699 Expression* ParserTraits::ClassExpression(
644 const AstRawString* name, Expression* extends, Expression* constructor, 700 const AstRawString* name, Expression* extends, Expression* constructor,
645 ZoneList<ObjectLiteral::Property*>* properties, int start_position, 701 ZoneList<ObjectLiteral::Property*>* properties, int start_position,
646 int end_position, AstNodeFactory<AstConstructionVisitor>* factory) { 702 int end_position, AstNodeFactory<AstConstructionVisitor>* factory) {
647 return factory->NewClassLiteral(name, extends, constructor, properties, 703 return factory->NewClassLiteral(name, extends, constructor, properties,
648 start_position, end_position); 704 start_position, end_position);
649 } 705 }
650 706
707
708 Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope) {
709 return parser_->DefaultConstructor(call_super, scope);
710 }
711
712
651 Literal* ParserTraits::ExpressionFromLiteral( 713 Literal* ParserTraits::ExpressionFromLiteral(
652 Token::Value token, int pos, 714 Token::Value token, int pos,
653 Scanner* scanner, 715 Scanner* scanner,
654 AstNodeFactory<AstConstructionVisitor>* factory) { 716 AstNodeFactory<AstConstructionVisitor>* factory) {
655 switch (token) { 717 switch (token) {
656 case Token::NULL_LITERAL: 718 case Token::NULL_LITERAL:
657 return factory->NewNullLiteral(pos); 719 return factory->NewNullLiteral(pos);
658 case Token::TRUE_LITERAL: 720 case Token::TRUE_LITERAL:
659 return factory->NewBooleanLiteral(true, pos); 721 return factory->NewBooleanLiteral(true, pos);
660 case Token::FALSE_LITERAL: 722 case Token::FALSE_LITERAL:
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 // the main thread. 990 // the main thread.
929 HistogramTimerScope timer_scope(isolate()->counters()->parse_lazy()); 991 HistogramTimerScope timer_scope(isolate()->counters()->parse_lazy());
930 Handle<String> source(String::cast(script()->source())); 992 Handle<String> source(String::cast(script()->source()));
931 isolate()->counters()->total_parse_size()->Increment(source->length()); 993 isolate()->counters()->total_parse_size()->Increment(source->length());
932 base::ElapsedTimer timer; 994 base::ElapsedTimer timer;
933 if (FLAG_trace_parse) { 995 if (FLAG_trace_parse) {
934 timer.Start(); 996 timer.Start();
935 } 997 }
936 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); 998 Handle<SharedFunctionInfo> shared_info = info()->shared_info();
937 999
938 // Initialize parser state.
939 source = String::Flatten(source);
940 FunctionLiteral* result; 1000 FunctionLiteral* result;
941 if (source->IsExternalTwoByteString()) { 1001 if (shared_info->is_default_constructor() ||
942 ExternalTwoByteStringUtf16CharacterStream stream( 1002 shared_info->is_default_constructor_call_super()) {
943 Handle<ExternalTwoByteString>::cast(source), 1003 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
944 shared_info->start_position(), 1004 Scope* scope = NewScope(scope_, GLOBAL_SCOPE);
945 shared_info->end_position()); 1005 info()->SetGlobalScope(scope);
946 result = ParseLazy(&stream); 1006 if (!info()->closure().is_null()) {
1007 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope,
1008 zone());
1009 }
1010 original_scope_ = scope;
1011 AstNodeFactory<AstConstructionVisitor> function_factory(
1012 ast_value_factory());
1013 FunctionState function_state(&function_state_, &scope_, scope,
1014 &function_factory);
1015 result = DefaultConstructor(
1016 shared_info->is_default_constructor_call_super(), scope);
Dmitry Lomov (no reviews) 2014/11/07 07:01:11 I believe if you set positions correctly all this
947 } else { 1017 } else {
948 GenericStringUtf16CharacterStream stream(source, 1018 // Initialize parser state.
949 shared_info->start_position(), 1019 source = String::Flatten(source);
950 shared_info->end_position()); 1020 if (source->IsExternalTwoByteString()) {
951 result = ParseLazy(&stream); 1021 ExternalTwoByteStringUtf16CharacterStream stream(
1022 Handle<ExternalTwoByteString>::cast(source),
1023 shared_info->start_position(), shared_info->end_position());
1024 result = ParseLazy(&stream);
1025 } else {
1026 GenericStringUtf16CharacterStream stream(
1027 source, shared_info->start_position(), shared_info->end_position());
1028 result = ParseLazy(&stream);
1029 }
952 } 1030 }
953 1031
954 if (FLAG_trace_parse && result != NULL) { 1032 if (FLAG_trace_parse && result != NULL) {
955 double ms = timer.Elapsed().InMillisecondsF(); 1033 double ms = timer.Elapsed().InMillisecondsF();
956 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); 1034 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString();
957 PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms); 1035 PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms);
958 } 1036 }
959 return result; 1037 return result;
960 } 1038 }
961 1039
(...skipping 3993 matching lines...) Expand 10 before | Expand all | Expand 10 after
4955 5033
4956 // We cannot internalize on a background thread; a foreground task will take 5034 // We cannot internalize on a background thread; a foreground task will take
4957 // care of calling Parser::Internalize just before compilation. 5035 // care of calling Parser::Internalize just before compilation.
4958 5036
4959 if (compile_options() == ScriptCompiler::kProduceParserCache) { 5037 if (compile_options() == ScriptCompiler::kProduceParserCache) {
4960 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); 5038 if (result != NULL) *info_->cached_data() = recorder.GetScriptData();
4961 log_ = NULL; 5039 log_ = NULL;
4962 } 5040 }
4963 } 5041 }
4964 } } // namespace v8::internal 5042 } } // namespace v8::internal
OLDNEW
« src/arm/full-codegen-arm.cc ('K') | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698