Index: src/parser.cc |
diff --git a/src/parser.cc b/src/parser.cc |
index c5bf0d977708df914299099f36f197a0e5b55eca..ef2ec38a24ab4480ab98cc3db79c01373ac5ad2a 100644 |
--- a/src/parser.cc |
+++ b/src/parser.cc |
@@ -275,6 +275,62 @@ Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { |
} |
+FunctionLiteral* Parser::DefaultConstructor(bool call_super, Scope* scope) { |
+ int materialized_literal_count = -1; |
+ int expected_property_count = -1; |
+ int handler_count = 0; |
+ int parameter_count = 0; |
+ AstProperties ast_properties; |
+ BailoutReason dont_optimize_reason = kNoReason; |
+ const AstRawString* name = ast_value_factory()->empty_string(); |
+ FunctionKind kind = call_super ? FunctionKind::kDefaultConstructorCallSuper |
+ : FunctionKind::kDefaultConstructor; |
+ |
+ Scope* function_scope = NewScope(scope, FUNCTION_SCOPE); |
+ function_scope->SetStrictMode(STRICT); |
+ ZoneList<Statement*>* body = NULL; |
+ int pos = RelocInfo::kNoPosition; |
+ |
+ { |
+ AstNodeFactory<AstConstructionVisitor> function_factory( |
+ ast_value_factory()); |
+ FunctionState function_state(&function_state_, &scope_, function_scope, |
+ &function_factory); |
+ |
+ body = new (zone()) ZoneList<Statement*>(1, zone()); |
+ if (call_super) { |
+ Expression* prop = SuperReference(function_scope, factory(), pos); |
+ ZoneList<Expression*>* args = |
+ new (zone()) ZoneList<Expression*>(0, zone()); |
+ Call* call = factory()->NewCall(prop, args, pos); |
+ |
+ DCHECK(call->GetCallType(isolate()) == Call::SUPER_CALL); |
+ |
+ body->Add(factory()->NewExpressionStatement(call, pos), zone()); |
+ } |
+ |
+ materialized_literal_count = function_state.materialized_literal_count(); |
+ expected_property_count = function_state.expected_property_count(); |
+ handler_count = function_state.handler_count(); |
+ |
+ ast_properties = *factory()->visitor()->ast_properties(); |
+ dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); |
+ } |
+ |
+ FunctionLiteral* function_literal = factory()->NewFunctionLiteral( |
+ name, ast_value_factory(), function_scope, body, |
+ materialized_literal_count, expected_property_count, handler_count, |
+ parameter_count, FunctionLiteral::kNoDuplicateParameters, |
+ FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
+ FunctionLiteral::kNotParenthesized, kind, pos); |
+ |
+ function_literal->set_ast_properties(&ast_properties); |
+ function_literal->set_dont_optimize_reason(dont_optimize_reason); |
+ |
+ return function_literal; |
+} |
+ |
+ |
// ---------------------------------------------------------------------------- |
// Target is a support class to facilitate manipulation of the |
// Parser's target_stack_ (the stack of potential 'break' and |
@@ -648,6 +704,12 @@ Expression* ParserTraits::ClassExpression( |
start_position, end_position); |
} |
+ |
+Expression* ParserTraits::DefaultConstructor(bool call_super, Scope* scope) { |
+ return parser_->DefaultConstructor(call_super, scope); |
+} |
+ |
+ |
Literal* ParserTraits::ExpressionFromLiteral( |
Token::Value token, int pos, |
Scanner* scanner, |
@@ -935,20 +997,36 @@ FunctionLiteral* Parser::ParseLazy() { |
} |
Handle<SharedFunctionInfo> shared_info = info()->shared_info(); |
- // Initialize parser state. |
- source = String::Flatten(source); |
FunctionLiteral* result; |
- if (source->IsExternalTwoByteString()) { |
- ExternalTwoByteStringUtf16CharacterStream stream( |
- Handle<ExternalTwoByteString>::cast(source), |
- shared_info->start_position(), |
- shared_info->end_position()); |
- result = ParseLazy(&stream); |
+ if (shared_info->is_default_constructor() || |
+ shared_info->is_default_constructor_call_super()) { |
+ ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
+ Scope* scope = NewScope(scope_, GLOBAL_SCOPE); |
+ info()->SetGlobalScope(scope); |
+ if (!info()->closure().is_null()) { |
+ scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, |
+ zone()); |
+ } |
+ original_scope_ = scope; |
+ AstNodeFactory<AstConstructionVisitor> function_factory( |
+ ast_value_factory()); |
+ FunctionState function_state(&function_state_, &scope_, scope, |
+ &function_factory); |
+ result = DefaultConstructor( |
+ 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
|
} else { |
- GenericStringUtf16CharacterStream stream(source, |
- shared_info->start_position(), |
- shared_info->end_position()); |
- result = ParseLazy(&stream); |
+ // Initialize parser state. |
+ source = String::Flatten(source); |
+ if (source->IsExternalTwoByteString()) { |
+ ExternalTwoByteStringUtf16CharacterStream stream( |
+ Handle<ExternalTwoByteString>::cast(source), |
+ shared_info->start_position(), shared_info->end_position()); |
+ result = ParseLazy(&stream); |
+ } else { |
+ GenericStringUtf16CharacterStream stream( |
+ source, shared_info->start_position(), shared_info->end_position()); |
+ result = ParseLazy(&stream); |
+ } |
} |
if (FLAG_trace_parse && result != NULL) { |