OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 if (num_alternatives == 0) { | 195 if (num_alternatives == 0) { |
196 return RegExpEmpty::GetInstance(); | 196 return RegExpEmpty::GetInstance(); |
197 } | 197 } |
198 if (num_alternatives == 1) { | 198 if (num_alternatives == 1) { |
199 return alternatives_.last(); | 199 return alternatives_.last(); |
200 } | 200 } |
201 return new(zone()) RegExpDisjunction(alternatives_.GetList(zone())); | 201 return new(zone()) RegExpDisjunction(alternatives_.GetList(zone())); |
202 } | 202 } |
203 | 203 |
204 | 204 |
205 void RegExpBuilder::AddQuantifierToAtom(int min, | 205 void RegExpBuilder::AddQuantifierToAtom( |
206 int max, | 206 int min, int max, RegExpQuantifier::QuantifierType quantifier_type) { |
207 RegExpQuantifier::Type type) { | |
208 if (pending_empty_) { | 207 if (pending_empty_) { |
209 pending_empty_ = false; | 208 pending_empty_ = false; |
210 return; | 209 return; |
211 } | 210 } |
212 RegExpTree* atom; | 211 RegExpTree* atom; |
213 if (characters_ != NULL) { | 212 if (characters_ != NULL) { |
214 ASSERT(last_added_ == ADD_CHAR); | 213 ASSERT(last_added_ == ADD_CHAR); |
215 // Last atom was character. | 214 // Last atom was character. |
216 Vector<const uc16> char_vector = characters_->ToConstVector(); | 215 Vector<const uc16> char_vector = characters_->ToConstVector(); |
217 int num_chars = char_vector.length(); | 216 int num_chars = char_vector.length(); |
(...skipping 19 matching lines...) Expand all Loading... |
237 return; | 236 return; |
238 } | 237 } |
239 terms_.Add(atom, zone()); | 238 terms_.Add(atom, zone()); |
240 return; | 239 return; |
241 } | 240 } |
242 } else { | 241 } else { |
243 // Only call immediately after adding an atom or character! | 242 // Only call immediately after adding an atom or character! |
244 UNREACHABLE(); | 243 UNREACHABLE(); |
245 return; | 244 return; |
246 } | 245 } |
247 terms_.Add(new(zone()) RegExpQuantifier(min, max, type, atom), zone()); | 246 terms_.Add( |
| 247 new(zone()) RegExpQuantifier(min, max, quantifier_type, atom), zone()); |
248 LAST(ADD_TERM); | 248 LAST(ADD_TERM); |
249 } | 249 } |
250 | 250 |
251 | 251 |
252 Handle<String> Parser::LookupSymbol(int symbol_id) { | 252 Handle<String> Parser::LookupSymbol(int symbol_id) { |
253 // Length of symbol cache is the number of identified symbols. | 253 // Length of symbol cache is the number of identified symbols. |
254 // If we are larger than that, or negative, it's not a cached symbol. | 254 // If we are larger than that, or negative, it's not a cached symbol. |
255 // This might also happen if there is no preparser symbol data, even | 255 // This might also happen if there is no preparser symbol data, even |
256 // if there is some preparser data. | 256 // if there is some preparser data. |
257 if (static_cast<unsigned>(symbol_id) | 257 if (static_cast<unsigned>(symbol_id) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 unsigned ScriptDataImpl::Read(int position) { | 403 unsigned ScriptDataImpl::Read(int position) { |
404 return store_[PreparseDataConstants::kHeaderSize + position]; | 404 return store_[PreparseDataConstants::kHeaderSize + position]; |
405 } | 405 } |
406 | 406 |
407 | 407 |
408 unsigned* ScriptDataImpl::ReadAddress(int position) { | 408 unsigned* ScriptDataImpl::ReadAddress(int position) { |
409 return &store_[PreparseDataConstants::kHeaderSize + position]; | 409 return &store_[PreparseDataConstants::kHeaderSize + position]; |
410 } | 410 } |
411 | 411 |
412 | 412 |
413 Scope* Parser::NewScope(Scope* parent, ScopeType type) { | 413 Scope* Parser::NewScope(Scope* parent, ScopeType scope_type) { |
414 Scope* result = new(zone()) Scope(parent, type, zone()); | 414 Scope* result = new(zone()) Scope(parent, scope_type, zone()); |
415 result->Initialize(); | 415 result->Initialize(); |
416 return result; | 416 return result; |
417 } | 417 } |
418 | 418 |
419 | 419 |
420 // ---------------------------------------------------------------------------- | 420 // ---------------------------------------------------------------------------- |
421 // Target is a support class to facilitate manipulation of the | 421 // Target is a support class to facilitate manipulation of the |
422 // Parser's target_stack_ (the stack of potential 'break' and | 422 // Parser's target_stack_ (the stack of potential 'break' and |
423 // 'continue' statement targets). Upon construction, a new target is | 423 // 'continue' statement targets). Upon construction, a new target is |
424 // added; it is removed upon destruction. | 424 // added; it is removed upon destruction. |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 if (!info()->closure().is_null()) { | 751 if (!info()->closure().is_null()) { |
752 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, | 752 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, |
753 zone()); | 753 zone()); |
754 } | 754 } |
755 FunctionState function_state(this, scope, isolate()); | 755 FunctionState function_state(this, scope, isolate()); |
756 ASSERT(scope->language_mode() != STRICT_MODE || !info()->is_classic_mode()); | 756 ASSERT(scope->language_mode() != STRICT_MODE || !info()->is_classic_mode()); |
757 ASSERT(scope->language_mode() != EXTENDED_MODE || | 757 ASSERT(scope->language_mode() != EXTENDED_MODE || |
758 info()->is_extended_mode()); | 758 info()->is_extended_mode()); |
759 ASSERT(info()->language_mode() == shared_info->language_mode()); | 759 ASSERT(info()->language_mode() == shared_info->language_mode()); |
760 scope->SetLanguageMode(shared_info->language_mode()); | 760 scope->SetLanguageMode(shared_info->language_mode()); |
761 FunctionLiteral::Type type = shared_info->is_expression() | 761 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
762 ? (shared_info->is_anonymous() | 762 ? (shared_info->is_anonymous() |
763 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 763 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
764 : FunctionLiteral::NAMED_EXPRESSION) | 764 : FunctionLiteral::NAMED_EXPRESSION) |
765 : FunctionLiteral::DECLARATION; | 765 : FunctionLiteral::DECLARATION; |
766 bool ok = true; | 766 bool ok = true; |
767 result = ParseFunctionLiteral(name, | 767 result = ParseFunctionLiteral(name, |
768 false, // Strict mode name already checked. | 768 false, // Strict mode name already checked. |
769 shared_info->is_generator(), | 769 shared_info->is_generator(), |
770 RelocInfo::kNoPosition, | 770 RelocInfo::kNoPosition, |
771 type, | 771 function_type, |
772 &ok); | 772 &ok); |
773 // Make sure the results agree. | 773 // Make sure the results agree. |
774 ASSERT(ok == (result != NULL)); | 774 ASSERT(ok == (result != NULL)); |
775 } | 775 } |
776 | 776 |
777 // Make sure the target stack is empty. | 777 // Make sure the target stack is empty. |
778 ASSERT(target_stack_ == NULL); | 778 ASSERT(target_stack_ == NULL); |
779 | 779 |
780 // If there was a stack overflow we have to get rid of AST and it is | 780 // If there was a stack overflow we have to get rid of AST and it is |
781 // not safe to do before scope has been deleted. | 781 // not safe to do before scope has been deleted. |
(...skipping 10 matching lines...) Expand all Loading... |
792 | 792 |
793 Handle<String> Parser::GetSymbol() { | 793 Handle<String> Parser::GetSymbol() { |
794 int symbol_id = -1; | 794 int symbol_id = -1; |
795 if (pre_parse_data() != NULL) { | 795 if (pre_parse_data() != NULL) { |
796 symbol_id = pre_parse_data()->GetSymbolIdentifier(); | 796 symbol_id = pre_parse_data()->GetSymbolIdentifier(); |
797 } | 797 } |
798 return LookupSymbol(symbol_id); | 798 return LookupSymbol(symbol_id); |
799 } | 799 } |
800 | 800 |
801 | 801 |
802 void Parser::ReportMessage(const char* type, Vector<const char*> args) { | 802 void Parser::ReportMessage(const char* message, Vector<const char*> args) { |
803 Scanner::Location source_location = scanner().location(); | 803 Scanner::Location source_location = scanner().location(); |
804 ReportMessageAt(source_location, type, args); | 804 ReportMessageAt(source_location, message, args); |
805 } | 805 } |
806 | 806 |
807 | 807 |
808 void Parser::ReportMessage(const char* type, Vector<Handle<String> > args) { | 808 void Parser::ReportMessage(const char* message, Vector<Handle<String> > args) { |
809 Scanner::Location source_location = scanner().location(); | 809 Scanner::Location source_location = scanner().location(); |
810 ReportMessageAt(source_location, type, args); | 810 ReportMessageAt(source_location, message, args); |
811 } | 811 } |
812 | 812 |
813 | 813 |
814 void Parser::ReportMessageAt(Scanner::Location source_location, | 814 void Parser::ReportMessageAt(Scanner::Location source_location, |
815 const char* type, | 815 const char* message, |
816 Vector<const char*> args) { | 816 Vector<const char*> args) { |
817 MessageLocation location(script_, | 817 MessageLocation location(script_, |
818 source_location.beg_pos, | 818 source_location.beg_pos, |
819 source_location.end_pos); | 819 source_location.end_pos); |
820 Factory* factory = isolate()->factory(); | 820 Factory* factory = isolate()->factory(); |
821 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); | 821 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); |
822 for (int i = 0; i < args.length(); i++) { | 822 for (int i = 0; i < args.length(); i++) { |
823 Handle<String> arg_string = factory->NewStringFromUtf8(CStrVector(args[i])); | 823 Handle<String> arg_string = factory->NewStringFromUtf8(CStrVector(args[i])); |
824 elements->set(i, *arg_string); | 824 elements->set(i, *arg_string); |
825 } | 825 } |
826 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | 826 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
827 Handle<Object> result = factory->NewSyntaxError(type, array); | 827 Handle<Object> result = factory->NewSyntaxError(message, array); |
828 isolate()->Throw(*result, &location); | 828 isolate()->Throw(*result, &location); |
829 } | 829 } |
830 | 830 |
831 | 831 |
832 void Parser::ReportMessageAt(Scanner::Location source_location, | 832 void Parser::ReportMessageAt(Scanner::Location source_location, |
833 const char* type, | 833 const char* message, |
834 Vector<Handle<String> > args) { | 834 Vector<Handle<String> > args) { |
835 MessageLocation location(script_, | 835 MessageLocation location(script_, |
836 source_location.beg_pos, | 836 source_location.beg_pos, |
837 source_location.end_pos); | 837 source_location.end_pos); |
838 Factory* factory = isolate()->factory(); | 838 Factory* factory = isolate()->factory(); |
839 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); | 839 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); |
840 for (int i = 0; i < args.length(); i++) { | 840 for (int i = 0; i < args.length(); i++) { |
841 elements->set(i, *args[i]); | 841 elements->set(i, *args[i]); |
842 } | 842 } |
843 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | 843 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
844 Handle<Object> result = factory->NewSyntaxError(type, array); | 844 Handle<Object> result = factory->NewSyntaxError(message, array); |
845 isolate()->Throw(*result, &location); | 845 isolate()->Throw(*result, &location); |
846 } | 846 } |
847 | 847 |
848 | 848 |
849 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, | 849 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, |
850 int end_token, | 850 int end_token, |
851 bool is_eval, | 851 bool is_eval, |
852 bool is_global, | 852 bool is_global, |
853 bool* ok) { | 853 bool* ok) { |
854 // SourceElements :: | 854 // SourceElements :: |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1531 if (is_extended_mode()) { | 1531 if (is_extended_mode()) { |
1532 // In harmony mode we treat re-declarations as early errors. See | 1532 // In harmony mode we treat re-declarations as early errors. See |
1533 // ES5 16 for a definition of early errors. | 1533 // ES5 16 for a definition of early errors. |
1534 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); | 1534 SmartArrayPointer<char> c_string = name->ToCString(DISALLOW_NULLS); |
1535 const char* elms[2] = { "Variable", *c_string }; | 1535 const char* elms[2] = { "Variable", *c_string }; |
1536 Vector<const char*> args(elms, 2); | 1536 Vector<const char*> args(elms, 2); |
1537 ReportMessage("redeclaration", args); | 1537 ReportMessage("redeclaration", args); |
1538 *ok = false; | 1538 *ok = false; |
1539 return; | 1539 return; |
1540 } | 1540 } |
1541 Handle<String> type_string = | 1541 Handle<String> message_string = |
1542 isolate()->factory()->NewStringFromUtf8(CStrVector("Variable"), | 1542 isolate()->factory()->NewStringFromUtf8(CStrVector("Variable"), |
1543 TENURED); | 1543 TENURED); |
1544 Expression* expression = | 1544 Expression* expression = |
1545 NewThrowTypeError(isolate()->factory()->redeclaration_string(), | 1545 NewThrowTypeError(isolate()->factory()->redeclaration_string(), |
1546 type_string, name); | 1546 message_string, name); |
1547 declaration_scope->SetIllegalRedeclaration(expression); | 1547 declaration_scope->SetIllegalRedeclaration(expression); |
1548 } | 1548 } |
1549 } | 1549 } |
1550 | 1550 |
1551 // We add a declaration node for every declaration. The compiler | 1551 // We add a declaration node for every declaration. The compiler |
1552 // will only generate code if necessary. In particular, declarations | 1552 // will only generate code if necessary. In particular, declarations |
1553 // for inner local variables that do not represent functions won't | 1553 // for inner local variables that do not represent functions won't |
1554 // result in any generated code. | 1554 // result in any generated code. |
1555 // | 1555 // |
1556 // Note that we always add an unresolved proxy even if it's not | 1556 // Note that we always add an unresolved proxy even if it's not |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2338 } | 2338 } |
2339 | 2339 |
2340 // An ECMAScript program is considered syntactically incorrect if it | 2340 // An ECMAScript program is considered syntactically incorrect if it |
2341 // contains a return statement that is not within the body of a | 2341 // contains a return statement that is not within the body of a |
2342 // function. See ECMA-262, section 12.9, page 67. | 2342 // function. See ECMA-262, section 12.9, page 67. |
2343 // | 2343 // |
2344 // To be consistent with KJS we report the syntax error at runtime. | 2344 // To be consistent with KJS we report the syntax error at runtime. |
2345 Scope* declaration_scope = top_scope_->DeclarationScope(); | 2345 Scope* declaration_scope = top_scope_->DeclarationScope(); |
2346 if (declaration_scope->is_global_scope() || | 2346 if (declaration_scope->is_global_scope() || |
2347 declaration_scope->is_eval_scope()) { | 2347 declaration_scope->is_eval_scope()) { |
2348 Handle<String> type = isolate()->factory()->illegal_return_string(); | 2348 Handle<String> message = isolate()->factory()->illegal_return_string(); |
2349 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); | 2349 Expression* throw_error = |
| 2350 NewThrowSyntaxError(message, Handle<Object>::null()); |
2350 return factory()->NewExpressionStatement(throw_error); | 2351 return factory()->NewExpressionStatement(throw_error); |
2351 } | 2352 } |
2352 return result; | 2353 return result; |
2353 } | 2354 } |
2354 | 2355 |
2355 | 2356 |
2356 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { | 2357 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { |
2357 // WithStatement :: | 2358 // WithStatement :: |
2358 // 'with' '(' Expression ')' Statement | 2359 // 'with' '(' Expression ')' Statement |
2359 | 2360 |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2730 init = variable_statement; | 2731 init = variable_statement; |
2731 } | 2732 } |
2732 } else { | 2733 } else { |
2733 Expression* expression = ParseExpression(false, CHECK_OK); | 2734 Expression* expression = ParseExpression(false, CHECK_OK); |
2734 if (peek() == Token::IN) { | 2735 if (peek() == Token::IN) { |
2735 // Signal a reference error if the expression is an invalid | 2736 // Signal a reference error if the expression is an invalid |
2736 // left-hand side expression. We could report this as a syntax | 2737 // left-hand side expression. We could report this as a syntax |
2737 // error here but for compatibility with JSC we choose to report | 2738 // error here but for compatibility with JSC we choose to report |
2738 // the error at runtime. | 2739 // the error at runtime. |
2739 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2740 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
2740 Handle<String> type = | 2741 Handle<String> message = |
2741 isolate()->factory()->invalid_lhs_in_for_in_string(); | 2742 isolate()->factory()->invalid_lhs_in_for_in_string(); |
2742 expression = NewThrowReferenceError(type); | 2743 expression = NewThrowReferenceError(message); |
2743 } | 2744 } |
2744 ForInStatement* loop = factory()->NewForInStatement(labels); | 2745 ForInStatement* loop = factory()->NewForInStatement(labels); |
2745 Target target(&this->target_stack_, loop); | 2746 Target target(&this->target_stack_, loop); |
2746 | 2747 |
2747 Expect(Token::IN, CHECK_OK); | 2748 Expect(Token::IN, CHECK_OK); |
2748 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2749 Expression* enumerable = ParseExpression(true, CHECK_OK); |
2749 Expect(Token::RPAREN, CHECK_OK); | 2750 Expect(Token::RPAREN, CHECK_OK); |
2750 | 2751 |
2751 Statement* body = ParseStatement(NULL, CHECK_OK); | 2752 Statement* body = ParseStatement(NULL, CHECK_OK); |
2752 if (loop) loop->Initialize(expression, enumerable, body); | 2753 if (loop) loop->Initialize(expression, enumerable, body); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2849 // Parsed conditional expression only (no assignment). | 2850 // Parsed conditional expression only (no assignment). |
2850 return expression; | 2851 return expression; |
2851 } | 2852 } |
2852 | 2853 |
2853 // Signal a reference error if the expression is an invalid left-hand | 2854 // Signal a reference error if the expression is an invalid left-hand |
2854 // side expression. We could report this as a syntax error here but | 2855 // side expression. We could report this as a syntax error here but |
2855 // for compatibility with JSC we choose to report the error at | 2856 // for compatibility with JSC we choose to report the error at |
2856 // runtime. | 2857 // runtime. |
2857 // TODO(ES5): Should change parsing for spec conformance. | 2858 // TODO(ES5): Should change parsing for spec conformance. |
2858 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2859 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
2859 Handle<String> type = | 2860 Handle<String> message = |
2860 isolate()->factory()->invalid_lhs_in_assignment_string(); | 2861 isolate()->factory()->invalid_lhs_in_assignment_string(); |
2861 expression = NewThrowReferenceError(type); | 2862 expression = NewThrowReferenceError(message); |
2862 } | 2863 } |
2863 | 2864 |
2864 if (!top_scope_->is_classic_mode()) { | 2865 if (!top_scope_->is_classic_mode()) { |
2865 // Assignment to eval or arguments is disallowed in strict mode. | 2866 // Assignment to eval or arguments is disallowed in strict mode. |
2866 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK); | 2867 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK); |
2867 } | 2868 } |
2868 MarkAsLValue(expression); | 2869 MarkAsLValue(expression); |
2869 | 2870 |
2870 Token::Value op = Next(); // Get assignment operator. | 2871 Token::Value op = Next(); // Get assignment operator. |
2871 int pos = scanner().location().beg_pos; | 2872 int pos = scanner().location().beg_pos; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3119 return factory()->NewUnaryOperation(op, expression, position); | 3120 return factory()->NewUnaryOperation(op, expression, position); |
3120 | 3121 |
3121 } else if (Token::IsCountOp(op)) { | 3122 } else if (Token::IsCountOp(op)) { |
3122 op = Next(); | 3123 op = Next(); |
3123 Expression* expression = ParseUnaryExpression(CHECK_OK); | 3124 Expression* expression = ParseUnaryExpression(CHECK_OK); |
3124 // Signal a reference error if the expression is an invalid | 3125 // Signal a reference error if the expression is an invalid |
3125 // left-hand side expression. We could report this as a syntax | 3126 // left-hand side expression. We could report this as a syntax |
3126 // error here but for compatibility with JSC we choose to report the | 3127 // error here but for compatibility with JSC we choose to report the |
3127 // error at runtime. | 3128 // error at runtime. |
3128 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 3129 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
3129 Handle<String> type = | 3130 Handle<String> message = |
3130 isolate()->factory()->invalid_lhs_in_prefix_op_string(); | 3131 isolate()->factory()->invalid_lhs_in_prefix_op_string(); |
3131 expression = NewThrowReferenceError(type); | 3132 expression = NewThrowReferenceError(message); |
3132 } | 3133 } |
3133 | 3134 |
3134 if (!top_scope_->is_classic_mode()) { | 3135 if (!top_scope_->is_classic_mode()) { |
3135 // Prefix expression operand in strict mode may not be eval or arguments. | 3136 // Prefix expression operand in strict mode may not be eval or arguments. |
3136 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); | 3137 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); |
3137 } | 3138 } |
3138 MarkAsLValue(expression); | 3139 MarkAsLValue(expression); |
3139 | 3140 |
3140 int position = scanner().location().beg_pos; | 3141 int position = scanner().location().beg_pos; |
3141 return factory()->NewCountOperation(op, | 3142 return factory()->NewCountOperation(op, |
(...skipping 12 matching lines...) Expand all Loading... |
3154 // LeftHandSideExpression ('++' | '--')? | 3155 // LeftHandSideExpression ('++' | '--')? |
3155 | 3156 |
3156 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); | 3157 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); |
3157 if (!scanner().HasAnyLineTerminatorBeforeNext() && | 3158 if (!scanner().HasAnyLineTerminatorBeforeNext() && |
3158 Token::IsCountOp(peek())) { | 3159 Token::IsCountOp(peek())) { |
3159 // Signal a reference error if the expression is an invalid | 3160 // Signal a reference error if the expression is an invalid |
3160 // left-hand side expression. We could report this as a syntax | 3161 // left-hand side expression. We could report this as a syntax |
3161 // error here but for compatibility with JSC we choose to report the | 3162 // error here but for compatibility with JSC we choose to report the |
3162 // error at runtime. | 3163 // error at runtime. |
3163 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 3164 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
3164 Handle<String> type = | 3165 Handle<String> message = |
3165 isolate()->factory()->invalid_lhs_in_postfix_op_string(); | 3166 isolate()->factory()->invalid_lhs_in_postfix_op_string(); |
3166 expression = NewThrowReferenceError(type); | 3167 expression = NewThrowReferenceError(message); |
3167 } | 3168 } |
3168 | 3169 |
3169 if (!top_scope_->is_classic_mode()) { | 3170 if (!top_scope_->is_classic_mode()) { |
3170 // Postfix expression operand in strict mode may not be eval or arguments. | 3171 // Postfix expression operand in strict mode may not be eval or arguments. |
3171 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); | 3172 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); |
3172 } | 3173 } |
3173 MarkAsLValue(expression); | 3174 MarkAsLValue(expression); |
3174 | 3175 |
3175 Token::Value next = Next(); | 3176 Token::Value next = Next(); |
3176 int position = scanner().location().beg_pos; | 3177 int position = scanner().location().beg_pos; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3315 if (peek() == Token::FUNCTION) { | 3316 if (peek() == Token::FUNCTION) { |
3316 Expect(Token::FUNCTION, CHECK_OK); | 3317 Expect(Token::FUNCTION, CHECK_OK); |
3317 int function_token_position = scanner().location().beg_pos; | 3318 int function_token_position = scanner().location().beg_pos; |
3318 bool is_generator = allow_generators() && Check(Token::MUL); | 3319 bool is_generator = allow_generators() && Check(Token::MUL); |
3319 Handle<String> name; | 3320 Handle<String> name; |
3320 bool is_strict_reserved_name = false; | 3321 bool is_strict_reserved_name = false; |
3321 if (peek_any_identifier()) { | 3322 if (peek_any_identifier()) { |
3322 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, | 3323 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, |
3323 CHECK_OK); | 3324 CHECK_OK); |
3324 } | 3325 } |
3325 FunctionLiteral::Type type = name.is_null() | 3326 FunctionLiteral::FunctionType function_type = name.is_null() |
3326 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 3327 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
3327 : FunctionLiteral::NAMED_EXPRESSION; | 3328 : FunctionLiteral::NAMED_EXPRESSION; |
3328 result = ParseFunctionLiteral(name, | 3329 result = ParseFunctionLiteral(name, |
3329 is_strict_reserved_name, | 3330 is_strict_reserved_name, |
3330 is_generator, | 3331 is_generator, |
3331 function_token_position, | 3332 function_token_position, |
3332 type, | 3333 function_type, |
3333 CHECK_OK); | 3334 CHECK_OK); |
3334 } else { | 3335 } else { |
3335 result = ParsePrimaryExpression(CHECK_OK); | 3336 result = ParsePrimaryExpression(CHECK_OK); |
3336 } | 3337 } |
3337 | 3338 |
3338 while (true) { | 3339 while (true) { |
3339 switch (peek()) { | 3340 switch (peek()) { |
3340 case Token::LBRACK: { | 3341 case Token::LBRACK: { |
3341 Consume(Token::LBRACK); | 3342 Consume(Token::LBRACK); |
3342 int pos = scanner().location().beg_pos; | 3343 int pos = scanner().location().beg_pos; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3651 | 3652 |
3652 | 3653 |
3653 Handle<FixedArray> CompileTimeValue::GetValue(Expression* expression) { | 3654 Handle<FixedArray> CompileTimeValue::GetValue(Expression* expression) { |
3654 Factory* factory = Isolate::Current()->factory(); | 3655 Factory* factory = Isolate::Current()->factory(); |
3655 ASSERT(IsCompileTimeValue(expression)); | 3656 ASSERT(IsCompileTimeValue(expression)); |
3656 Handle<FixedArray> result = factory->NewFixedArray(2, TENURED); | 3657 Handle<FixedArray> result = factory->NewFixedArray(2, TENURED); |
3657 ObjectLiteral* object_literal = expression->AsObjectLiteral(); | 3658 ObjectLiteral* object_literal = expression->AsObjectLiteral(); |
3658 if (object_literal != NULL) { | 3659 if (object_literal != NULL) { |
3659 ASSERT(object_literal->is_simple()); | 3660 ASSERT(object_literal->is_simple()); |
3660 if (object_literal->fast_elements()) { | 3661 if (object_literal->fast_elements()) { |
3661 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_FAST_ELEMENTS)); | 3662 result->set(kLiteralTypeSlot, Smi::FromInt(OBJECT_LITERAL_FAST_ELEMENTS)); |
3662 } else { | 3663 } else { |
3663 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_SLOW_ELEMENTS)); | 3664 result->set(kLiteralTypeSlot, Smi::FromInt(OBJECT_LITERAL_SLOW_ELEMENTS)); |
3664 } | 3665 } |
3665 result->set(kElementsSlot, *object_literal->constant_properties()); | 3666 result->set(kElementsSlot, *object_literal->constant_properties()); |
3666 } else { | 3667 } else { |
3667 ArrayLiteral* array_literal = expression->AsArrayLiteral(); | 3668 ArrayLiteral* array_literal = expression->AsArrayLiteral(); |
3668 ASSERT(array_literal != NULL && array_literal->is_simple()); | 3669 ASSERT(array_literal != NULL && array_literal->is_simple()); |
3669 result->set(kTypeSlot, Smi::FromInt(ARRAY_LITERAL)); | 3670 result->set(kLiteralTypeSlot, Smi::FromInt(ARRAY_LITERAL)); |
3670 result->set(kElementsSlot, *array_literal->constant_elements()); | 3671 result->set(kElementsSlot, *array_literal->constant_elements()); |
3671 } | 3672 } |
3672 return result; | 3673 return result; |
3673 } | 3674 } |
3674 | 3675 |
3675 | 3676 |
3676 CompileTimeValue::Type CompileTimeValue::GetType(Handle<FixedArray> value) { | 3677 CompileTimeValue::LiteralType CompileTimeValue::GetLiteralType( |
3677 Smi* type_value = Smi::cast(value->get(kTypeSlot)); | 3678 Handle<FixedArray> value) { |
3678 return static_cast<Type>(type_value->value()); | 3679 Smi* literal_type = Smi::cast(value->get(kLiteralTypeSlot)); |
| 3680 return static_cast<LiteralType>(literal_type->value()); |
3679 } | 3681 } |
3680 | 3682 |
3681 | 3683 |
3682 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { | 3684 Handle<FixedArray> CompileTimeValue::GetElements(Handle<FixedArray> value) { |
3683 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); | 3685 return Handle<FixedArray>(FixedArray::cast(value->get(kElementsSlot))); |
3684 } | 3686 } |
3685 | 3687 |
3686 | 3688 |
3687 Handle<Object> Parser::GetBoilerplateValue(Expression* expression) { | 3689 Handle<Object> Parser::GetBoilerplateValue(Expression* expression) { |
3688 if (expression->AsLiteral() != NULL) { | 3690 if (expression->AsLiteral() != NULL) { |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4156 // For function entries. | 4158 // For function entries. |
4157 int literals_; | 4159 int literals_; |
4158 int properties_; | 4160 int properties_; |
4159 LanguageMode mode_; | 4161 LanguageMode mode_; |
4160 // For error messages. | 4162 // For error messages. |
4161 const char* message_; | 4163 const char* message_; |
4162 const char* argument_opt_; | 4164 const char* argument_opt_; |
4163 }; | 4165 }; |
4164 | 4166 |
4165 | 4167 |
4166 FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name, | 4168 FunctionLiteral* Parser::ParseFunctionLiteral( |
4167 bool name_is_strict_reserved, | 4169 Handle<String> function_name, |
4168 bool is_generator, | 4170 bool name_is_strict_reserved, |
4169 int function_token_position, | 4171 bool is_generator, |
4170 FunctionLiteral::Type type, | 4172 int function_token_position, |
4171 bool* ok) { | 4173 FunctionLiteral::FunctionType function_type, |
| 4174 bool* ok) { |
4172 // Function :: | 4175 // Function :: |
4173 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 4176 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
4174 | 4177 |
4175 // Anonymous functions were passed either the empty symbol or a null | 4178 // Anonymous functions were passed either the empty symbol or a null |
4176 // handle as the function name. Remember if we were passed a non-empty | 4179 // handle as the function name. Remember if we were passed a non-empty |
4177 // handle to decide whether to invoke function name inference. | 4180 // handle to decide whether to invoke function name inference. |
4178 bool should_infer_name = function_name.is_null(); | 4181 bool should_infer_name = function_name.is_null(); |
4179 | 4182 |
4180 // We want a non-null handle as the function name. | 4183 // We want a non-null handle as the function name. |
4181 if (should_infer_name) { | 4184 if (should_infer_name) { |
4182 function_name = isolate()->factory()->empty_string(); | 4185 function_name = isolate()->factory()->empty_string(); |
4183 } | 4186 } |
4184 | 4187 |
4185 int num_parameters = 0; | 4188 int num_parameters = 0; |
4186 // Function declarations are function scoped in normal mode, so they are | 4189 // Function declarations are function scoped in normal mode, so they are |
4187 // hoisted. In harmony block scoping mode they are block scoped, so they | 4190 // hoisted. In harmony block scoping mode they are block scoped, so they |
4188 // are not hoisted. | 4191 // are not hoisted. |
4189 Scope* scope = (type == FunctionLiteral::DECLARATION && !is_extended_mode()) | 4192 Scope* scope = |
| 4193 (function_type == FunctionLiteral::DECLARATION && !is_extended_mode()) |
4190 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) | 4194 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) |
4191 : NewScope(top_scope_, FUNCTION_SCOPE); | 4195 : NewScope(top_scope_, FUNCTION_SCOPE); |
4192 ZoneList<Statement*>* body = NULL; | 4196 ZoneList<Statement*>* body = NULL; |
4193 int materialized_literal_count = -1; | 4197 int materialized_literal_count = -1; |
4194 int expected_property_count = -1; | 4198 int expected_property_count = -1; |
4195 int handler_count = 0; | 4199 int handler_count = 0; |
4196 FunctionLiteral::ParameterFlag duplicate_parameters = | 4200 FunctionLiteral::ParameterFlag duplicate_parameters = |
4197 FunctionLiteral::kNoDuplicateParameters; | 4201 FunctionLiteral::kNoDuplicateParameters; |
4198 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ | 4202 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ |
4199 ? FunctionLiteral::kIsParenthesized | 4203 ? FunctionLiteral::kIsParenthesized |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4265 Expect(Token::LBRACE, CHECK_OK); | 4269 Expect(Token::LBRACE, CHECK_OK); |
4266 | 4270 |
4267 // If we have a named function expression, we add a local variable | 4271 // If we have a named function expression, we add a local variable |
4268 // declaration to the body of the function with the name of the | 4272 // declaration to the body of the function with the name of the |
4269 // function and let it refer to the function itself (closure). | 4273 // function and let it refer to the function itself (closure). |
4270 // NOTE: We create a proxy and resolve it here so that in the | 4274 // NOTE: We create a proxy and resolve it here so that in the |
4271 // future we can change the AST to only refer to VariableProxies | 4275 // future we can change the AST to only refer to VariableProxies |
4272 // instead of Variables and Proxis as is the case now. | 4276 // instead of Variables and Proxis as is the case now. |
4273 Variable* fvar = NULL; | 4277 Variable* fvar = NULL; |
4274 Token::Value fvar_init_op = Token::INIT_CONST; | 4278 Token::Value fvar_init_op = Token::INIT_CONST; |
4275 if (type == FunctionLiteral::NAMED_EXPRESSION) { | 4279 if (function_type == FunctionLiteral::NAMED_EXPRESSION) { |
4276 if (is_extended_mode()) fvar_init_op = Token::INIT_CONST_HARMONY; | 4280 if (is_extended_mode()) fvar_init_op = Token::INIT_CONST_HARMONY; |
4277 VariableMode fvar_mode = is_extended_mode() ? CONST_HARMONY : CONST; | 4281 VariableMode fvar_mode = is_extended_mode() ? CONST_HARMONY : CONST; |
4278 fvar = new(zone()) Variable(top_scope_, | 4282 fvar = new(zone()) Variable(top_scope_, |
4279 function_name, fvar_mode, true /* is valid LHS */, | 4283 function_name, fvar_mode, true /* is valid LHS */, |
4280 Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); | 4284 Variable::NORMAL, kCreatedInitialized, Interface::NewConst()); |
4281 VariableProxy* proxy = factory()->NewVariableProxy(fvar); | 4285 VariableProxy* proxy = factory()->NewVariableProxy(fvar); |
4282 VariableDeclaration* fvar_declaration = | 4286 VariableDeclaration* fvar_declaration = |
4283 factory()->NewVariableDeclaration(proxy, fvar_mode, top_scope_); | 4287 factory()->NewVariableDeclaration(proxy, fvar_mode, top_scope_); |
4284 top_scope_->DeclareFunctionVar(fvar_declaration); | 4288 top_scope_->DeclareFunctionVar(fvar_declaration); |
4285 } | 4289 } |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4469 | 4473 |
4470 FunctionLiteral* function_literal = | 4474 FunctionLiteral* function_literal = |
4471 factory()->NewFunctionLiteral(function_name, | 4475 factory()->NewFunctionLiteral(function_name, |
4472 scope, | 4476 scope, |
4473 body, | 4477 body, |
4474 materialized_literal_count, | 4478 materialized_literal_count, |
4475 expected_property_count, | 4479 expected_property_count, |
4476 handler_count, | 4480 handler_count, |
4477 num_parameters, | 4481 num_parameters, |
4478 duplicate_parameters, | 4482 duplicate_parameters, |
4479 type, | 4483 function_type, |
4480 FunctionLiteral::kIsFunction, | 4484 FunctionLiteral::kIsFunction, |
4481 parenthesized, | 4485 parenthesized, |
4482 generator); | 4486 generator); |
4483 function_literal->set_function_token_position(function_token_position); | 4487 function_literal->set_function_token_position(function_token_position); |
4484 function_literal->set_ast_properties(&ast_properties); | 4488 function_literal->set_ast_properties(&ast_properties); |
4485 | 4489 |
4486 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); | 4490 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); |
4487 return function_literal; | 4491 return function_literal; |
4488 } | 4492 } |
4489 | 4493 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4815 // Register that a break target found at the given stop in the | 4819 // Register that a break target found at the given stop in the |
4816 // target stack has been used from the top of the target stack. Add | 4820 // target stack has been used from the top of the target stack. Add |
4817 // the break target to any TargetCollectors passed on the stack. | 4821 // the break target to any TargetCollectors passed on the stack. |
4818 for (Target* t = target_stack_; t != stop; t = t->previous()) { | 4822 for (Target* t = target_stack_; t != stop; t = t->previous()) { |
4819 TargetCollector* collector = t->node()->AsTargetCollector(); | 4823 TargetCollector* collector = t->node()->AsTargetCollector(); |
4820 if (collector != NULL) collector->AddTarget(target, zone()); | 4824 if (collector != NULL) collector->AddTarget(target, zone()); |
4821 } | 4825 } |
4822 } | 4826 } |
4823 | 4827 |
4824 | 4828 |
4825 Expression* Parser::NewThrowReferenceError(Handle<String> type) { | 4829 Expression* Parser::NewThrowReferenceError(Handle<String> message) { |
4826 return NewThrowError(isolate()->factory()->MakeReferenceError_string(), | 4830 return NewThrowError(isolate()->factory()->MakeReferenceError_string(), |
4827 type, HandleVector<Object>(NULL, 0)); | 4831 message, HandleVector<Object>(NULL, 0)); |
4828 } | 4832 } |
4829 | 4833 |
4830 | 4834 |
4831 Expression* Parser::NewThrowSyntaxError(Handle<String> type, | 4835 Expression* Parser::NewThrowSyntaxError(Handle<String> message, |
4832 Handle<Object> first) { | 4836 Handle<Object> first) { |
4833 int argc = first.is_null() ? 0 : 1; | 4837 int argc = first.is_null() ? 0 : 1; |
4834 Vector< Handle<Object> > arguments = HandleVector<Object>(&first, argc); | 4838 Vector< Handle<Object> > arguments = HandleVector<Object>(&first, argc); |
4835 return NewThrowError( | 4839 return NewThrowError( |
4836 isolate()->factory()->MakeSyntaxError_string(), type, arguments); | 4840 isolate()->factory()->MakeSyntaxError_string(), message, arguments); |
4837 } | 4841 } |
4838 | 4842 |
4839 | 4843 |
4840 Expression* Parser::NewThrowTypeError(Handle<String> type, | 4844 Expression* Parser::NewThrowTypeError(Handle<String> message, |
4841 Handle<Object> first, | 4845 Handle<Object> first, |
4842 Handle<Object> second) { | 4846 Handle<Object> second) { |
4843 ASSERT(!first.is_null() && !second.is_null()); | 4847 ASSERT(!first.is_null() && !second.is_null()); |
4844 Handle<Object> elements[] = { first, second }; | 4848 Handle<Object> elements[] = { first, second }; |
4845 Vector< Handle<Object> > arguments = | 4849 Vector< Handle<Object> > arguments = |
4846 HandleVector<Object>(elements, ARRAY_SIZE(elements)); | 4850 HandleVector<Object>(elements, ARRAY_SIZE(elements)); |
4847 return NewThrowError( | 4851 return NewThrowError( |
4848 isolate()->factory()->MakeTypeError_string(), type, arguments); | 4852 isolate()->factory()->MakeTypeError_string(), message, arguments); |
4849 } | 4853 } |
4850 | 4854 |
4851 | 4855 |
4852 Expression* Parser::NewThrowError(Handle<String> constructor, | 4856 Expression* Parser::NewThrowError(Handle<String> constructor, |
4853 Handle<String> type, | 4857 Handle<String> message, |
4854 Vector< Handle<Object> > arguments) { | 4858 Vector< Handle<Object> > arguments) { |
4855 int argc = arguments.length(); | 4859 int argc = arguments.length(); |
4856 Handle<FixedArray> elements = isolate()->factory()->NewFixedArray(argc, | 4860 Handle<FixedArray> elements = isolate()->factory()->NewFixedArray(argc, |
4857 TENURED); | 4861 TENURED); |
4858 for (int i = 0; i < argc; i++) { | 4862 for (int i = 0; i < argc; i++) { |
4859 Handle<Object> element = arguments[i]; | 4863 Handle<Object> element = arguments[i]; |
4860 if (!element.is_null()) { | 4864 if (!element.is_null()) { |
4861 elements->set(i, *element); | 4865 elements->set(i, *element); |
4862 } | 4866 } |
4863 } | 4867 } |
4864 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements( | 4868 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements( |
4865 elements, FAST_ELEMENTS, TENURED); | 4869 elements, FAST_ELEMENTS, TENURED); |
4866 | 4870 |
4867 ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2, zone()); | 4871 ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2, zone()); |
4868 args->Add(factory()->NewLiteral(type), zone()); | 4872 args->Add(factory()->NewLiteral(message), zone()); |
4869 args->Add(factory()->NewLiteral(array), zone()); | 4873 args->Add(factory()->NewLiteral(array), zone()); |
4870 CallRuntime* call_constructor = | 4874 CallRuntime* call_constructor = |
4871 factory()->NewCallRuntime(constructor, NULL, args); | 4875 factory()->NewCallRuntime(constructor, NULL, args); |
4872 return factory()->NewThrow(call_constructor, scanner().location().beg_pos); | 4876 return factory()->NewThrow(call_constructor, scanner().location().beg_pos); |
4873 } | 4877 } |
4874 | 4878 |
4875 // ---------------------------------------------------------------------------- | 4879 // ---------------------------------------------------------------------------- |
4876 // Regular expressions | 4880 // Regular expressions |
4877 | 4881 |
4878 | 4882 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4999 ASSERT_NE(INITIAL, stored_state->group_type()); | 5003 ASSERT_NE(INITIAL, stored_state->group_type()); |
5000 | 5004 |
5001 Advance(); | 5005 Advance(); |
5002 // End disjunction parsing and convert builder content to new single | 5006 // End disjunction parsing and convert builder content to new single |
5003 // regexp atom. | 5007 // regexp atom. |
5004 RegExpTree* body = builder->ToRegExp(); | 5008 RegExpTree* body = builder->ToRegExp(); |
5005 | 5009 |
5006 int end_capture_index = captures_started(); | 5010 int end_capture_index = captures_started(); |
5007 | 5011 |
5008 int capture_index = stored_state->capture_index(); | 5012 int capture_index = stored_state->capture_index(); |
5009 SubexpressionType type = stored_state->group_type(); | 5013 SubexpressionType group_type = stored_state->group_type(); |
5010 | 5014 |
5011 // Restore previous state. | 5015 // Restore previous state. |
5012 stored_state = stored_state->previous_state(); | 5016 stored_state = stored_state->previous_state(); |
5013 builder = stored_state->builder(); | 5017 builder = stored_state->builder(); |
5014 | 5018 |
5015 // Build result of subexpression. | 5019 // Build result of subexpression. |
5016 if (type == CAPTURE) { | 5020 if (group_type == CAPTURE) { |
5017 RegExpCapture* capture = new(zone()) RegExpCapture(body, capture_index); | 5021 RegExpCapture* capture = new(zone()) RegExpCapture(body, capture_index); |
5018 captures_->at(capture_index - 1) = capture; | 5022 captures_->at(capture_index - 1) = capture; |
5019 body = capture; | 5023 body = capture; |
5020 } else if (type != GROUPING) { | 5024 } else if (group_type != GROUPING) { |
5021 ASSERT(type == POSITIVE_LOOKAHEAD || type == NEGATIVE_LOOKAHEAD); | 5025 ASSERT(group_type == POSITIVE_LOOKAHEAD || |
5022 bool is_positive = (type == POSITIVE_LOOKAHEAD); | 5026 group_type == NEGATIVE_LOOKAHEAD); |
| 5027 bool is_positive = (group_type == POSITIVE_LOOKAHEAD); |
5023 body = new(zone()) RegExpLookahead(body, | 5028 body = new(zone()) RegExpLookahead(body, |
5024 is_positive, | 5029 is_positive, |
5025 end_capture_index - capture_index, | 5030 end_capture_index - capture_index, |
5026 capture_index); | 5031 capture_index); |
5027 } | 5032 } |
5028 builder->AddAtom(body); | 5033 builder->AddAtom(body); |
5029 // For compatability with JSC and ES3, we allow quantifiers after | 5034 // For compatability with JSC and ES3, we allow quantifiers after |
5030 // lookaheads, and break in all cases. | 5035 // lookaheads, and break in all cases. |
5031 break; | 5036 break; |
5032 } | 5037 } |
(...skipping 13 matching lines...) Expand all Loading... |
5046 new(zone()) RegExpAssertion(RegExpAssertion::START_OF_LINE)); | 5051 new(zone()) RegExpAssertion(RegExpAssertion::START_OF_LINE)); |
5047 } else { | 5052 } else { |
5048 builder->AddAssertion( | 5053 builder->AddAssertion( |
5049 new(zone()) RegExpAssertion(RegExpAssertion::START_OF_INPUT)); | 5054 new(zone()) RegExpAssertion(RegExpAssertion::START_OF_INPUT)); |
5050 set_contains_anchor(); | 5055 set_contains_anchor(); |
5051 } | 5056 } |
5052 continue; | 5057 continue; |
5053 } | 5058 } |
5054 case '$': { | 5059 case '$': { |
5055 Advance(); | 5060 Advance(); |
5056 RegExpAssertion::Type type = | 5061 RegExpAssertion::AssertionType assertion_type = |
5057 multiline_ ? RegExpAssertion::END_OF_LINE : | 5062 multiline_ ? RegExpAssertion::END_OF_LINE : |
5058 RegExpAssertion::END_OF_INPUT; | 5063 RegExpAssertion::END_OF_INPUT; |
5059 builder->AddAssertion(new(zone()) RegExpAssertion(type)); | 5064 builder->AddAssertion(new(zone()) RegExpAssertion(assertion_type)); |
5060 continue; | 5065 continue; |
5061 } | 5066 } |
5062 case '.': { | 5067 case '.': { |
5063 Advance(); | 5068 Advance(); |
5064 // everything except \x0a, \x0d, \u2028 and \u2029 | 5069 // everything except \x0a, \x0d, \u2028 and \u2029 |
5065 ZoneList<CharacterRange>* ranges = | 5070 ZoneList<CharacterRange>* ranges = |
5066 new(zone()) ZoneList<CharacterRange>(2, zone()); | 5071 new(zone()) ZoneList<CharacterRange>(2, zone()); |
5067 CharacterRange::AddClassEscape('.', ranges, zone()); | 5072 CharacterRange::AddClassEscape('.', ranges, zone()); |
5068 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); | 5073 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); |
5069 builder->AddAtom(atom); | 5074 builder->AddAtom(atom); |
5070 break; | 5075 break; |
5071 } | 5076 } |
5072 case '(': { | 5077 case '(': { |
5073 SubexpressionType type = CAPTURE; | 5078 SubexpressionType subexpr_type = CAPTURE; |
5074 Advance(); | 5079 Advance(); |
5075 if (current() == '?') { | 5080 if (current() == '?') { |
5076 switch (Next()) { | 5081 switch (Next()) { |
5077 case ':': | 5082 case ':': |
5078 type = GROUPING; | 5083 subexpr_type = GROUPING; |
5079 break; | 5084 break; |
5080 case '=': | 5085 case '=': |
5081 type = POSITIVE_LOOKAHEAD; | 5086 subexpr_type = POSITIVE_LOOKAHEAD; |
5082 break; | 5087 break; |
5083 case '!': | 5088 case '!': |
5084 type = NEGATIVE_LOOKAHEAD; | 5089 subexpr_type = NEGATIVE_LOOKAHEAD; |
5085 break; | 5090 break; |
5086 default: | 5091 default: |
5087 ReportError(CStrVector("Invalid group") CHECK_FAILED); | 5092 ReportError(CStrVector("Invalid group") CHECK_FAILED); |
5088 break; | 5093 break; |
5089 } | 5094 } |
5090 Advance(2); | 5095 Advance(2); |
5091 } else { | 5096 } else { |
5092 if (captures_ == NULL) { | 5097 if (captures_ == NULL) { |
5093 captures_ = new(zone()) ZoneList<RegExpCapture*>(2, zone()); | 5098 captures_ = new(zone()) ZoneList<RegExpCapture*>(2, zone()); |
5094 } | 5099 } |
5095 if (captures_started() >= kMaxCaptures) { | 5100 if (captures_started() >= kMaxCaptures) { |
5096 ReportError(CStrVector("Too many captures") CHECK_FAILED); | 5101 ReportError(CStrVector("Too many captures") CHECK_FAILED); |
5097 } | 5102 } |
5098 captures_->Add(NULL, zone()); | 5103 captures_->Add(NULL, zone()); |
5099 } | 5104 } |
5100 // Store current state and begin new disjunction parsing. | 5105 // Store current state and begin new disjunction parsing. |
5101 stored_state = new(zone()) RegExpParserState(stored_state, type, | 5106 stored_state = new(zone()) RegExpParserState(stored_state, subexpr_type, |
5102 captures_started(), zone()); | 5107 captures_started(), zone()); |
5103 builder = stored_state->builder(); | 5108 builder = stored_state->builder(); |
5104 continue; | 5109 continue; |
5105 } | 5110 } |
5106 case '[': { | 5111 case '[': { |
5107 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED); | 5112 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED); |
5108 builder->AddAtom(atom); | 5113 builder->AddAtom(atom); |
5109 break; | 5114 break; |
5110 } | 5115 } |
5111 // Atom :: | 5116 // Atom :: |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5279 ReportError(CStrVector("numbers out of order in {} quantifier.") | 5284 ReportError(CStrVector("numbers out of order in {} quantifier.") |
5280 CHECK_FAILED); | 5285 CHECK_FAILED); |
5281 } | 5286 } |
5282 break; | 5287 break; |
5283 } else { | 5288 } else { |
5284 continue; | 5289 continue; |
5285 } | 5290 } |
5286 default: | 5291 default: |
5287 continue; | 5292 continue; |
5288 } | 5293 } |
5289 RegExpQuantifier::Type type = RegExpQuantifier::GREEDY; | 5294 RegExpQuantifier::QuantifierType quantifier_type = RegExpQuantifier::GREEDY; |
5290 if (current() == '?') { | 5295 if (current() == '?') { |
5291 type = RegExpQuantifier::NON_GREEDY; | 5296 quantifier_type = RegExpQuantifier::NON_GREEDY; |
5292 Advance(); | 5297 Advance(); |
5293 } else if (FLAG_regexp_possessive_quantifier && current() == '+') { | 5298 } else if (FLAG_regexp_possessive_quantifier && current() == '+') { |
5294 // FLAG_regexp_possessive_quantifier is a debug-only flag. | 5299 // FLAG_regexp_possessive_quantifier is a debug-only flag. |
5295 type = RegExpQuantifier::POSSESSIVE; | 5300 quantifier_type = RegExpQuantifier::POSSESSIVE; |
5296 Advance(); | 5301 Advance(); |
5297 } | 5302 } |
5298 builder->AddQuantifierToAtom(min, max, type); | 5303 builder->AddQuantifierToAtom(min, max, quantifier_type); |
5299 } | 5304 } |
5300 } | 5305 } |
5301 | 5306 |
5302 | 5307 |
5303 #ifdef DEBUG | 5308 #ifdef DEBUG |
5304 // Currently only used in an ASSERT. | 5309 // Currently only used in an ASSERT. |
5305 static bool IsSpecialClassEscape(uc32 c) { | 5310 static bool IsSpecialClassEscape(uc32 c) { |
5306 switch (c) { | 5311 switch (c) { |
5307 case 'd': case 'D': | 5312 case 'd': case 'D': |
5308 case 's': case 'S': | 5313 case 's': case 'S': |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5823 ASSERT(info()->isolate()->has_pending_exception()); | 5828 ASSERT(info()->isolate()->has_pending_exception()); |
5824 } else { | 5829 } else { |
5825 result = ParseProgram(); | 5830 result = ParseProgram(); |
5826 } | 5831 } |
5827 } | 5832 } |
5828 info()->SetFunction(result); | 5833 info()->SetFunction(result); |
5829 return (result != NULL); | 5834 return (result != NULL); |
5830 } | 5835 } |
5831 | 5836 |
5832 } } // namespace v8::internal | 5837 } } // namespace v8::internal |
OLD | NEW |