| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 Expression* ParseMemberExpression(bool* ok); | 151 Expression* ParseMemberExpression(bool* ok); |
| 152 Expression* ParseMemberWithNewPrefixesExpression(List<int>* new_prefixes, | 152 Expression* ParseMemberWithNewPrefixesExpression(List<int>* new_prefixes, |
| 153 bool* ok); | 153 bool* ok); |
| 154 Expression* ParsePrimaryExpression(bool* ok); | 154 Expression* ParsePrimaryExpression(bool* ok); |
| 155 Expression* ParseArrayLiteral(bool* ok); | 155 Expression* ParseArrayLiteral(bool* ok); |
| 156 Expression* ParseObjectLiteral(bool* ok); | 156 Expression* ParseObjectLiteral(bool* ok); |
| 157 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok); | 157 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok); |
| 158 | 158 |
| 159 // Decide if a property should be the object boilerplate. | 159 // Decide if a property should be the object boilerplate. |
| 160 bool IsBoilerplateProperty(ObjectLiteral::Property* property); | 160 bool IsBoilerplateProperty(ObjectLiteral::Property* property); |
| 161 // If the property is CONSTANT type, it returns the literal value, | 161 // If the property is CONSTANT type, return the literal value; |
| 162 // otherwise, it return undefined literal as the placeholder | 162 // if the property is OBJECT_LITERAL and the object literal is |
| 163 // simple return a fixed array containing the keys and values of the |
| 164 // object literal. |
| 165 // Otherwise, return undefined literal as the placeholder |
| 163 // in the object literal boilerplate. | 166 // in the object literal boilerplate. |
| 164 Literal* GetBoilerplateValue(ObjectLiteral::Property* property); | 167 Handle<Object> GetBoilerplateValue(ObjectLiteral::Property* property); |
| 165 | 168 |
| 166 enum FunctionLiteralType { | 169 enum FunctionLiteralType { |
| 167 EXPRESSION, | 170 EXPRESSION, |
| 168 DECLARATION, | 171 DECLARATION, |
| 169 NESTED | 172 NESTED |
| 170 }; | 173 }; |
| 171 | 174 |
| 172 ZoneList<Expression*>* ParseArguments(bool* ok); | 175 ZoneList<Expression*>* ParseArguments(bool* ok); |
| 173 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, | 176 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, |
| 174 int function_token_position, | 177 int function_token_position, |
| (...skipping 2901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3076 return NEW(ArrayLiteral(literals, values.elements())); | 3079 return NEW(ArrayLiteral(literals, values.elements())); |
| 3077 } | 3080 } |
| 3078 | 3081 |
| 3079 | 3082 |
| 3080 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { | 3083 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { |
| 3081 return property != NULL && | 3084 return property != NULL && |
| 3082 property->kind() != ObjectLiteral::Property::PROTOTYPE; | 3085 property->kind() != ObjectLiteral::Property::PROTOTYPE; |
| 3083 } | 3086 } |
| 3084 | 3087 |
| 3085 | 3088 |
| 3086 Literal* Parser::GetBoilerplateValue(ObjectLiteral::Property* property) { | 3089 Handle<Object> Parser::GetBoilerplateValue(ObjectLiteral::Property* property) { |
| 3087 if (property->kind() == ObjectLiteral::Property::CONSTANT) | 3090 if (property->kind() == ObjectLiteral::Property::CONSTANT) |
| 3088 return property->value()->AsLiteral(); | 3091 return property->value()->AsLiteral()->handle(); |
| 3089 return GetLiteralUndefined(); | 3092 if (property->kind() == ObjectLiteral::Property::OBJECT_LITERAL) { |
| 3093 ObjectLiteral* object_literal = property->value()->AsObjectLiteral(); |
| 3094 if (object_literal->is_simple()) { |
| 3095 return object_literal->constant_properties(); |
| 3096 } |
| 3097 } |
| 3098 return Factory::undefined_value(); |
| 3090 } | 3099 } |
| 3091 | 3100 |
| 3092 | 3101 |
| 3093 Expression* Parser::ParseObjectLiteral(bool* ok) { | 3102 Expression* Parser::ParseObjectLiteral(bool* ok) { |
| 3094 // ObjectLiteral :: | 3103 // ObjectLiteral :: |
| 3095 // '{' ( | 3104 // '{' ( |
| 3096 // ((Identifier | String | Number) ':' AssignmentExpression) | 3105 // ((Identifier | String | Number) ':' AssignmentExpression) |
| 3097 // | (('get' | 'set') FunctionLiteral) | 3106 // | (('get' | 'set') FunctionLiteral) |
| 3098 // )*[','] '}' | 3107 // )*[','] '}' |
| 3099 | 3108 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3174 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); | 3183 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); |
| 3175 } | 3184 } |
| 3176 Expect(Token::RBRACE, CHECK_OK); | 3185 Expect(Token::RBRACE, CHECK_OK); |
| 3177 // Computation of literal_index must happen before pre parse bailout. | 3186 // Computation of literal_index must happen before pre parse bailout. |
| 3178 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); | 3187 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); |
| 3179 if (is_pre_parsing_) return NULL; | 3188 if (is_pre_parsing_) return NULL; |
| 3180 | 3189 |
| 3181 Handle<FixedArray> constant_properties = | 3190 Handle<FixedArray> constant_properties = |
| 3182 Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED); | 3191 Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED); |
| 3183 int position = 0; | 3192 int position = 0; |
| 3193 bool is_simple = true; |
| 3184 for (int i = 0; i < properties.length(); i++) { | 3194 for (int i = 0; i < properties.length(); i++) { |
| 3185 ObjectLiteral::Property* property = properties.at(i); | 3195 ObjectLiteral::Property* property = properties.at(i); |
| 3186 if (!IsBoilerplateProperty(property)) continue; | 3196 if (!IsBoilerplateProperty(property)) { |
| 3197 is_simple = false; |
| 3198 continue; |
| 3199 } |
| 3187 | 3200 |
| 3188 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined | 3201 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined |
| 3189 // value for COMPUTED properties, the real value is filled in at | 3202 // value for COMPUTED properties, the real value is filled in at |
| 3190 // runtime. The enumeration order is maintained. | 3203 // runtime. The enumeration order is maintained. |
| 3191 Handle<Object> key = property->key()->handle(); | 3204 Handle<Object> key = property->key()->handle(); |
| 3192 Literal* literal = GetBoilerplateValue(property); | 3205 Handle<Object> value = GetBoilerplateValue(property); |
| 3206 is_simple = is_simple && !value->IsUndefined(); |
| 3193 | 3207 |
| 3194 // Add name, value pair to the fixed array. | 3208 // Add name, value pair to the fixed array. |
| 3195 constant_properties->set(position++, *key); | 3209 constant_properties->set(position++, *key); |
| 3196 constant_properties->set(position++, *literal->handle()); | 3210 constant_properties->set(position++, *value); |
| 3197 } | 3211 } |
| 3198 | 3212 |
| 3199 return new ObjectLiteral(constant_properties, | 3213 return new ObjectLiteral(constant_properties, |
| 3200 properties.elements(), | 3214 properties.elements(), |
| 3201 literal_index); | 3215 literal_index, |
| 3216 is_simple); |
| 3202 } | 3217 } |
| 3203 | 3218 |
| 3204 | 3219 |
| 3205 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { | 3220 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { |
| 3206 if (!scanner_.ScanRegExpPattern(seen_equal)) { | 3221 if (!scanner_.ScanRegExpPattern(seen_equal)) { |
| 3207 Next(); | 3222 Next(); |
| 3208 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); | 3223 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); |
| 3209 *ok = false; | 3224 *ok = false; |
| 3210 return NULL; | 3225 return NULL; |
| 3211 } | 3226 } |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3599 | 3614 |
| 3600 RegExpParser::RegExpParser(FlatStringReader* in, | 3615 RegExpParser::RegExpParser(FlatStringReader* in, |
| 3601 Handle<String>* error, | 3616 Handle<String>* error, |
| 3602 bool multiline) | 3617 bool multiline) |
| 3603 : current_(kEndMarker), | 3618 : current_(kEndMarker), |
| 3604 has_more_(true), | 3619 has_more_(true), |
| 3605 multiline_(multiline), | 3620 multiline_(multiline), |
| 3606 next_pos_(0), | 3621 next_pos_(0), |
| 3607 in_(in), | 3622 in_(in), |
| 3608 error_(error), | 3623 error_(error), |
| 3609 simple_(true), | 3624 simple_(false), |
| 3610 contains_anchor_(false), | 3625 contains_anchor_(false), |
| 3611 captures_(NULL), | 3626 captures_(NULL), |
| 3612 is_scanned_for_captures_(false), | 3627 is_scanned_for_captures_(false), |
| 3613 capture_count_(0), | 3628 capture_count_(0), |
| 3614 failed_(false) { | 3629 failed_(false) { |
| 3615 Advance(1); | 3630 Advance(1); |
| 3616 } | 3631 } |
| 3617 | 3632 |
| 3618 | 3633 |
| 3619 uc32 RegExpParser::Next() { | 3634 uc32 RegExpParser::Next() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3669 } | 3684 } |
| 3670 | 3685 |
| 3671 | 3686 |
| 3672 // Pattern :: | 3687 // Pattern :: |
| 3673 // Disjunction | 3688 // Disjunction |
| 3674 RegExpTree* RegExpParser::ParsePattern() { | 3689 RegExpTree* RegExpParser::ParsePattern() { |
| 3675 RegExpTree* result = ParseDisjunction(CHECK_FAILED); | 3690 RegExpTree* result = ParseDisjunction(CHECK_FAILED); |
| 3676 if (has_more()) { | 3691 if (has_more()) { |
| 3677 ReportError(CStrVector("Unmatched ')'") CHECK_FAILED); | 3692 ReportError(CStrVector("Unmatched ')'") CHECK_FAILED); |
| 3678 } | 3693 } |
| 3694 // If the result of parsing is a literal string atom, and it has the |
| 3695 // same length as the input, then the atom is identical to the input. |
| 3696 if (result->IsAtom() && result->AsAtom()->length() == in()->length()) { |
| 3697 simple_ = true; |
| 3698 } |
| 3679 return result; | 3699 return result; |
| 3680 } | 3700 } |
| 3681 | 3701 |
| 3682 | 3702 |
| 3683 bool RegExpParser::CaptureAvailable(int index) { | 3703 bool RegExpParser::CaptureAvailable(int index) { |
| 3684 if (captures_ == NULL) return false; | 3704 if (captures_ == NULL) return false; |
| 3685 if (index >= captures_->length()) return false; | 3705 if (index >= captures_->length()) return false; |
| 3686 RegExpCapture* capture = captures_->at(index); | 3706 RegExpCapture* capture = captures_->at(index); |
| 3687 return capture != NULL && capture->available() == CAPTURE_AVAILABLE; | 3707 return capture != NULL && capture->available() == CAPTURE_AVAILABLE; |
| 3688 } | 3708 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3868 builder.AddCharacter('u'); | 3888 builder.AddCharacter('u'); |
| 3869 } | 3889 } |
| 3870 break; | 3890 break; |
| 3871 } | 3891 } |
| 3872 default: | 3892 default: |
| 3873 // Identity escape. | 3893 // Identity escape. |
| 3874 builder.AddCharacter(Next()); | 3894 builder.AddCharacter(Next()); |
| 3875 Advance(2); | 3895 Advance(2); |
| 3876 break; | 3896 break; |
| 3877 } | 3897 } |
| 3878 simple_ = false; | |
| 3879 break; | 3898 break; |
| 3880 case '{': { | 3899 case '{': { |
| 3881 int dummy; | 3900 int dummy; |
| 3882 if (ParseIntervalQuantifier(&dummy, &dummy)) { | 3901 if (ParseIntervalQuantifier(&dummy, &dummy)) { |
| 3883 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED); | 3902 ReportError(CStrVector("Nothing to repeat") CHECK_FAILED); |
| 3884 } | 3903 } |
| 3885 // fallthrough | 3904 // fallthrough |
| 3886 } | 3905 } |
| 3887 default: | 3906 default: |
| 3888 builder.AddCharacter(current()); | 3907 builder.AddCharacter(current()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3925 continue; | 3944 continue; |
| 3926 } | 3945 } |
| 3927 default: | 3946 default: |
| 3928 continue; | 3947 continue; |
| 3929 } | 3948 } |
| 3930 bool is_greedy = true; | 3949 bool is_greedy = true; |
| 3931 if (current() == '?') { | 3950 if (current() == '?') { |
| 3932 is_greedy = false; | 3951 is_greedy = false; |
| 3933 Advance(); | 3952 Advance(); |
| 3934 } | 3953 } |
| 3935 simple_ = false; // Adding quantifier might *remove* look-ahead. | |
| 3936 builder.AddQuantifierToAtom(min, max, is_greedy); | 3954 builder.AddQuantifierToAtom(min, max, is_greedy); |
| 3937 } | 3955 } |
| 3938 } | 3956 } |
| 3939 | 3957 |
| 3940 class SourceCharacter { | 3958 class SourceCharacter { |
| 3941 public: | 3959 public: |
| 3942 static bool Is(uc32 c) { | 3960 static bool Is(uc32 c) { |
| 3943 switch (c) { | 3961 switch (c) { |
| 3944 // case ']': case '}': | 3962 // case ']': case '}': |
| 3945 // In spidermonkey and jsc these are treated as source characters | 3963 // In spidermonkey and jsc these are treated as source characters |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4510 start_position, | 4528 start_position, |
| 4511 is_expression); | 4529 is_expression); |
| 4512 return result; | 4530 return result; |
| 4513 } | 4531 } |
| 4514 | 4532 |
| 4515 | 4533 |
| 4516 #undef NEW | 4534 #undef NEW |
| 4517 | 4535 |
| 4518 | 4536 |
| 4519 } } // namespace v8::internal | 4537 } } // namespace v8::internal |
| OLD | NEW |