OLD | NEW |
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 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 ast_value_factory_(ast_value_factory), | 85 ast_value_factory_(ast_value_factory), |
86 log_(log), | 86 log_(log), |
87 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 87 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
88 stack_limit_(stack_limit), | 88 stack_limit_(stack_limit), |
89 zone_(zone), | 89 zone_(zone), |
90 scanner_(scanner), | 90 scanner_(scanner), |
91 stack_overflow_(false), | 91 stack_overflow_(false), |
92 allow_lazy_(false), | 92 allow_lazy_(false), |
93 allow_natives_(false), | 93 allow_natives_(false), |
94 allow_harmony_arrow_functions_(false), | 94 allow_harmony_arrow_functions_(false), |
95 allow_harmony_object_literals_(false), | |
96 allow_harmony_sloppy_(false), | 95 allow_harmony_sloppy_(false), |
97 allow_harmony_computed_property_names_(false), | 96 allow_harmony_computed_property_names_(false), |
98 allow_harmony_rest_params_(false), | 97 allow_harmony_rest_params_(false), |
99 allow_harmony_spreadcalls_(false), | 98 allow_harmony_spreadcalls_(false), |
100 allow_harmony_destructuring_(false), | 99 allow_harmony_destructuring_(false), |
101 allow_harmony_spread_arrays_(false), | 100 allow_harmony_spread_arrays_(false), |
102 allow_harmony_new_target_(false), | 101 allow_harmony_new_target_(false), |
103 allow_strong_mode_(false) {} | 102 allow_strong_mode_(false) {} |
104 | 103 |
105 #define ALLOW_ACCESSORS(name) \ | 104 #define ALLOW_ACCESSORS(name) \ |
106 bool allow_##name() const { return allow_##name##_; } \ | 105 bool allow_##name() const { return allow_##name##_; } \ |
107 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 106 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
108 | 107 |
109 ALLOW_ACCESSORS(lazy); | 108 ALLOW_ACCESSORS(lazy); |
110 ALLOW_ACCESSORS(natives); | 109 ALLOW_ACCESSORS(natives); |
111 ALLOW_ACCESSORS(harmony_arrow_functions); | 110 ALLOW_ACCESSORS(harmony_arrow_functions); |
112 ALLOW_ACCESSORS(harmony_object_literals); | |
113 ALLOW_ACCESSORS(harmony_sloppy); | 111 ALLOW_ACCESSORS(harmony_sloppy); |
114 ALLOW_ACCESSORS(harmony_computed_property_names); | 112 ALLOW_ACCESSORS(harmony_computed_property_names); |
115 ALLOW_ACCESSORS(harmony_rest_params); | 113 ALLOW_ACCESSORS(harmony_rest_params); |
116 ALLOW_ACCESSORS(harmony_spreadcalls); | 114 ALLOW_ACCESSORS(harmony_spreadcalls); |
117 ALLOW_ACCESSORS(harmony_destructuring); | 115 ALLOW_ACCESSORS(harmony_destructuring); |
118 ALLOW_ACCESSORS(harmony_spread_arrays); | 116 ALLOW_ACCESSORS(harmony_spread_arrays); |
119 ALLOW_ACCESSORS(harmony_new_target); | 117 ALLOW_ACCESSORS(harmony_new_target); |
120 ALLOW_ACCESSORS(strong_mode); | 118 ALLOW_ACCESSORS(strong_mode); |
121 #undef ALLOW_ACCESSORS | 119 #undef ALLOW_ACCESSORS |
122 | 120 |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 | 769 |
772 private: | 770 private: |
773 Zone* zone_; | 771 Zone* zone_; |
774 | 772 |
775 Scanner* scanner_; | 773 Scanner* scanner_; |
776 bool stack_overflow_; | 774 bool stack_overflow_; |
777 | 775 |
778 bool allow_lazy_; | 776 bool allow_lazy_; |
779 bool allow_natives_; | 777 bool allow_natives_; |
780 bool allow_harmony_arrow_functions_; | 778 bool allow_harmony_arrow_functions_; |
781 bool allow_harmony_object_literals_; | |
782 bool allow_harmony_sloppy_; | 779 bool allow_harmony_sloppy_; |
783 bool allow_harmony_computed_property_names_; | 780 bool allow_harmony_computed_property_names_; |
784 bool allow_harmony_rest_params_; | 781 bool allow_harmony_rest_params_; |
785 bool allow_harmony_spreadcalls_; | 782 bool allow_harmony_spreadcalls_; |
786 bool allow_harmony_destructuring_; | 783 bool allow_harmony_destructuring_; |
787 bool allow_harmony_spread_arrays_; | 784 bool allow_harmony_spread_arrays_; |
788 bool allow_harmony_new_target_; | 785 bool allow_harmony_new_target_; |
789 bool allow_strong_mode_; | 786 bool allow_strong_mode_; |
790 }; | 787 }; |
791 | 788 |
(...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2472 ParserBase<Traits>::ParsePropertyDefinition( | 2469 ParserBase<Traits>::ParsePropertyDefinition( |
2473 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 2470 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
2474 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 2471 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
2475 ExpressionClassifier* classifier, bool* ok) { | 2472 ExpressionClassifier* classifier, bool* ok) { |
2476 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); | 2473 DCHECK(!in_class || is_static || has_seen_constructor != nullptr); |
2477 ExpressionT value = this->EmptyExpression(); | 2474 ExpressionT value = this->EmptyExpression(); |
2478 IdentifierT name = this->EmptyIdentifier(); | 2475 IdentifierT name = this->EmptyIdentifier(); |
2479 bool is_get = false; | 2476 bool is_get = false; |
2480 bool is_set = false; | 2477 bool is_set = false; |
2481 bool name_is_static = false; | 2478 bool name_is_static = false; |
2482 bool is_generator = allow_harmony_object_literals_ && Check(Token::MUL); | 2479 bool is_generator = Check(Token::MUL); |
2483 | 2480 |
2484 Token::Value name_token = peek(); | 2481 Token::Value name_token = peek(); |
2485 int next_beg_pos = scanner()->peek_location().beg_pos; | 2482 int next_beg_pos = scanner()->peek_location().beg_pos; |
2486 int next_end_pos = scanner()->peek_location().end_pos; | 2483 int next_end_pos = scanner()->peek_location().end_pos; |
2487 ExpressionT name_expression = ParsePropertyName( | 2484 ExpressionT name_expression = ParsePropertyName( |
2488 &name, &is_get, &is_set, &name_is_static, is_computed_name, classifier, | 2485 &name, &is_get, &is_set, &name_is_static, is_computed_name, classifier, |
2489 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2486 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2490 | 2487 |
2491 if (fni_ != nullptr && !*is_computed_name) { | 2488 if (fni_ != nullptr && !*is_computed_name) { |
2492 this->PushLiteralName(fni_, name); | 2489 this->PushLiteralName(fni_, name); |
2493 } | 2490 } |
2494 | 2491 |
2495 if (!in_class && !is_generator && peek() == Token::COLON) { | 2492 if (!in_class && !is_generator && peek() == Token::COLON) { |
2496 // PropertyDefinition : PropertyName ':' AssignmentExpression | 2493 // PropertyDefinition : PropertyName ':' AssignmentExpression |
2497 if (!*is_computed_name) { | 2494 if (!*is_computed_name) { |
2498 checker->CheckProperty(name_token, kValueProperty, is_static, | 2495 checker->CheckProperty(name_token, kValueProperty, is_static, |
2499 is_generator, | 2496 is_generator, |
2500 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2497 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2501 } | 2498 } |
2502 Consume(Token::COLON); | 2499 Consume(Token::COLON); |
2503 value = this->ParseAssignmentExpression( | 2500 value = this->ParseAssignmentExpression( |
2504 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2501 true, classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2505 | 2502 |
2506 } else if (is_generator || | 2503 } else if (is_generator || peek() == Token::LPAREN) { |
2507 (allow_harmony_object_literals_ && peek() == Token::LPAREN)) { | |
2508 // Concise Method | 2504 // Concise Method |
2509 if (!*is_computed_name) { | 2505 if (!*is_computed_name) { |
2510 checker->CheckProperty(name_token, kMethodProperty, is_static, | 2506 checker->CheckProperty(name_token, kMethodProperty, is_static, |
2511 is_generator, | 2507 is_generator, |
2512 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 2508 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
2513 } | 2509 } |
2514 | 2510 |
2515 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod | 2511 FunctionKind kind = is_generator ? FunctionKind::kConciseGeneratorMethod |
2516 : FunctionKind::kConciseMethod; | 2512 : FunctionKind::kConciseMethod; |
2517 | 2513 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2569 if (!*is_computed_name) { | 2565 if (!*is_computed_name) { |
2570 name_expression = | 2566 name_expression = |
2571 factory()->NewStringLiteral(name, name_expression->position()); | 2567 factory()->NewStringLiteral(name, name_expression->position()); |
2572 } | 2568 } |
2573 | 2569 |
2574 return factory()->NewObjectLiteralProperty( | 2570 return factory()->NewObjectLiteralProperty( |
2575 name_expression, value, | 2571 name_expression, value, |
2576 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, | 2572 is_get ? ObjectLiteralProperty::GETTER : ObjectLiteralProperty::SETTER, |
2577 is_static, *is_computed_name); | 2573 is_static, *is_computed_name); |
2578 | 2574 |
2579 } else if (!in_class && allow_harmony_object_literals_ && | 2575 } else if (!in_class && Token::IsIdentifier(name_token, language_mode(), |
2580 Token::IsIdentifier(name_token, language_mode(), | 2576 this->is_generator())) { |
2581 this->is_generator())) { | |
2582 DCHECK(!*is_computed_name); | 2577 DCHECK(!*is_computed_name); |
2583 DCHECK(!is_static); | 2578 DCHECK(!is_static); |
2584 | 2579 |
2585 if (classifier->duplicate_finder() != nullptr && | 2580 if (classifier->duplicate_finder() != nullptr && |
2586 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { | 2581 scanner()->FindSymbol(classifier->duplicate_finder(), 1) != 0) { |
2587 classifier->RecordDuplicateFormalParameterError(scanner()->location()); | 2582 classifier->RecordDuplicateFormalParameterError(scanner()->location()); |
2588 } | 2583 } |
2589 | 2584 |
2590 ExpressionT lhs = this->ExpressionFromIdentifier( | 2585 ExpressionT lhs = this->ExpressionFromIdentifier( |
2591 name, next_beg_pos, next_end_pos, scope_, factory()); | 2586 name, next_beg_pos, next_end_pos, scope_, factory()); |
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3949 *ok = false; | 3944 *ok = false; |
3950 return; | 3945 return; |
3951 } | 3946 } |
3952 has_seen_constructor_ = true; | 3947 has_seen_constructor_ = true; |
3953 return; | 3948 return; |
3954 } | 3949 } |
3955 } | 3950 } |
3956 } } // v8::internal | 3951 } } // v8::internal |
3957 | 3952 |
3958 #endif // V8_PREPARSER_H | 3953 #endif // V8_PREPARSER_H |
OLD | NEW |