Index: src/parsing/parser-base.h |
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h |
index 025f1d72ca301ed89fd7676084a68c81746b3276..ce0bf2889d0b5b2d2bbafd15c658d10b1e309231 100644 |
--- a/src/parsing/parser-base.h |
+++ b/src/parsing/parser-base.h |
@@ -209,6 +209,7 @@ class ParserBase { |
scanner_(scanner), |
stack_overflow_(false), |
default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), |
+ function_literal_id_(0), |
allow_natives_(false), |
allow_tailcalls_(false), |
allow_harmony_do_expressions_(false), |
@@ -246,6 +247,13 @@ class ParserBase { |
return default_eager_compile_hint_; |
} |
+ int GetNextFunctionLiteralId() { return ++function_literal_id_; } |
+ int GetLastFunctionLiteralId() const { return function_literal_id_; } |
+ |
+ void SkipFunctionLiterals(int delta) { function_literal_id_ += delta; } |
+ |
+ void ResetFunctionLiteralId() { function_literal_id_ = 0; } |
+ |
Zone* zone() const { return zone_; } |
protected: |
@@ -1159,7 +1167,8 @@ class ParserBase { |
ExpressionT ParseObjectLiteral(bool* ok); |
ClassLiteralPropertyT ParseClassPropertyDefinition( |
ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, |
- bool* has_seen_constructor, bool* ok); |
+ bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind, |
+ bool* is_static, bool* ok); |
FunctionLiteralT ParseClassFieldForInitializer(bool has_initializer, |
bool* ok); |
ObjectLiteralPropertyT ParseObjectPropertyDefinition( |
@@ -1443,6 +1452,8 @@ class ParserBase { |
FunctionLiteral::EagerCompileHint default_eager_compile_hint_; |
+ int function_literal_id_; |
+ |
bool allow_natives_; |
bool allow_tailcalls_; |
bool allow_harmony_do_expressions_; |
@@ -2127,17 +2138,17 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName( |
template <typename Impl> |
typename ParserBase<Impl>::ClassLiteralPropertyT |
-ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, |
- bool has_extends, |
- bool* is_computed_name, |
- bool* has_seen_constructor, |
- bool* ok) { |
+ParserBase<Impl>::ParseClassPropertyDefinition( |
+ ClassLiteralChecker* checker, bool has_extends, bool* is_computed_name, |
+ bool* has_seen_constructor, ClassLiteralProperty::Kind* property_kind, |
+ bool* is_static, bool* ok) { |
DCHECK(has_seen_constructor != nullptr); |
bool is_get = false; |
bool is_set = false; |
bool is_generator = false; |
bool is_async = false; |
- bool is_static = false; |
+ *is_static = false; |
+ *property_kind = ClassLiteralProperty::METHOD; |
PropertyKind kind = PropertyKind::kNotSet; |
Token::Value name_token = peek(); |
@@ -2155,7 +2166,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, |
name = impl()->GetSymbol(); // TODO(bakkot) specialize on 'static' |
name_expression = factory()->NewStringLiteral(name, position()); |
} else { |
- is_static = true; |
+ *is_static = true; |
name_expression = ParsePropertyName( |
&name, &kind, &is_generator, &is_get, &is_set, &is_async, |
is_computed_name, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
@@ -2182,9 +2193,10 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, |
ExpressionT function_literal = ParseClassFieldForInitializer( |
has_initializer, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
ExpectSemicolon(CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
+ *property_kind = ClassLiteralProperty::FIELD; |
return factory()->NewClassLiteralProperty( |
- name_expression, function_literal, ClassLiteralProperty::FIELD, |
- is_static, *is_computed_name); |
+ name_expression, function_literal, *property_kind, *is_static, |
+ *is_computed_name); |
} else { |
ReportUnexpectedToken(Next()); |
*ok = false; |
@@ -2201,7 +2213,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, |
if (!*is_computed_name) { |
checker->CheckClassMethodName( |
name_token, PropertyKind::kMethodProperty, is_generator, is_async, |
- is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
+ *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
} |
FunctionKind kind = is_generator |
@@ -2209,7 +2221,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, |
: is_async ? FunctionKind::kAsyncConciseMethod |
: FunctionKind::kConciseMethod; |
- if (!is_static && impl()->IsConstructor(name)) { |
+ if (!*is_static && impl()->IsConstructor(name)) { |
*has_seen_constructor = true; |
kind = has_extends ? FunctionKind::kSubclassConstructor |
: FunctionKind::kBaseConstructor; |
@@ -2220,9 +2232,10 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, |
kNoSourcePosition, FunctionLiteral::kAccessorOrMethod, |
language_mode(), CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
+ *property_kind = ClassLiteralProperty::METHOD; |
return factory()->NewClassLiteralProperty(name_expression, value, |
- ClassLiteralProperty::METHOD, |
- is_static, *is_computed_name); |
+ *property_kind, *is_static, |
+ *is_computed_name); |
} |
case PropertyKind::kAccessorProperty: { |
@@ -2231,7 +2244,7 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, |
if (!*is_computed_name) { |
checker->CheckClassMethodName( |
name_token, PropertyKind::kAccessorProperty, false, false, |
- is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
+ *is_static, CHECK_OK_CUSTOM(EmptyClassLiteralProperty)); |
// Make sure the name expression is a string since we need a Name for |
// Runtime_DefineAccessorPropertyUnchecked and since we can determine |
// this statically we can skip the extra runtime check. |
@@ -2251,10 +2264,11 @@ ParserBase<Impl>::ParseClassPropertyDefinition(ClassLiteralChecker* checker, |
impl()->AddAccessorPrefixToFunctionName(is_get, value, name); |
} |
- return factory()->NewClassLiteralProperty( |
- name_expression, value, |
- is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER, |
- is_static, *is_computed_name); |
+ *property_kind = |
+ is_get ? ClassLiteralProperty::GETTER : ClassLiteralProperty::SETTER; |
+ return factory()->NewClassLiteralProperty(name_expression, value, |
+ *property_kind, *is_static, |
+ *is_computed_name); |
} |
} |
UNREACHABLE(); |
@@ -2292,7 +2306,7 @@ ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer, |
initializer_state.expected_property_count(), 0, 0, |
FunctionLiteral::kNoDuplicateParameters, |
FunctionLiteral::kAnonymousExpression, default_eager_compile_hint_, |
- initializer_scope->start_position(), true); |
+ initializer_scope->start_position(), true, GetNextFunctionLiteralId()); |
function_literal->set_is_class_field_initializer(true); |
return function_literal; |
} |
@@ -3930,6 +3944,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( |
StatementListT body = impl()->NullStatementList(); |
int materialized_literal_count = -1; |
int expected_property_count = -1; |
+ int function_literal_id = GetNextFunctionLiteralId(); |
FunctionKind kind = formal_parameters.scope->function_kind(); |
FunctionLiteral::EagerCompileHint eager_compile_hint = |
@@ -4067,7 +4082,8 @@ ParserBase<Impl>::ParseArrowFunctionLiteral( |
formal_parameters.num_parameters(), formal_parameters.function_length, |
FunctionLiteral::kNoDuplicateParameters, |
FunctionLiteral::kAnonymousExpression, eager_compile_hint, |
- formal_parameters.scope->start_position(), has_braces); |
+ formal_parameters.scope->start_position(), has_braces, |
+ function_literal_id); |
function_literal->set_function_token_position( |
formal_parameters.scope->start_position()); |
@@ -4125,14 +4141,21 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral( |
FuncNameInferrer::State fni_state(fni_); |
bool is_computed_name = false; // Classes do not care about computed |
// property names here. |
+ bool is_static; |
+ ClassLiteralProperty::Kind property_kind; |
ExpressionClassifier property_classifier(this); |
+ // If we haven't seen the constructor yet, it potentially is the next |
+ // property. |
+ bool is_constructor = !class_info.has_seen_constructor; |
ClassLiteralPropertyT property = ParseClassPropertyDefinition( |
Toon Verwaest
2016/11/28 11:12:34
This is getting a little out of hand, but I guess
|
&checker, has_extends, &is_computed_name, |
- &class_info.has_seen_constructor, CHECK_OK); |
+ &class_info.has_seen_constructor, &property_kind, &is_static, CHECK_OK); |
+ is_constructor &= class_info.has_seen_constructor; |
impl()->RewriteNonPattern(CHECK_OK); |
impl()->AccumulateFormalParameterContainmentErrors(); |
- impl()->DeclareClassProperty(name, property, &class_info, CHECK_OK); |
+ impl()->DeclareClassProperty(name, property, property_kind, is_static, |
+ is_constructor, &class_info, CHECK_OK); |
impl()->InferFunctionName(); |
} |