| 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 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| (...skipping 4597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4608 } | 4608 } |
| 4609 RegExpTree* atom = new(zone()) RegExpBackReference(capture); | 4609 RegExpTree* atom = new(zone()) RegExpBackReference(capture); |
| 4610 builder->AddAtom(atom); | 4610 builder->AddAtom(atom); |
| 4611 break; | 4611 break; |
| 4612 } | 4612 } |
| 4613 uc32 first_digit = Next(); | 4613 uc32 first_digit = Next(); |
| 4614 if (first_digit == '8' || first_digit == '9') { | 4614 if (first_digit == '8' || first_digit == '9') { |
| 4615 // If the 'u' flag is present, only syntax characters can be escaped, | 4615 // If the 'u' flag is present, only syntax characters can be escaped, |
| 4616 // no other identity escapes are allowed. If the 'u' flag is not | 4616 // no other identity escapes are allowed. If the 'u' flag is not |
| 4617 // present, all identity escapes are allowed. | 4617 // present, all identity escapes are allowed. |
| 4618 if (!FLAG_harmony_unicode || !unicode_) { | 4618 if (!FLAG_harmony_unicode_regexps || !unicode_) { |
| 4619 builder->AddCharacter(first_digit); | 4619 builder->AddCharacter(first_digit); |
| 4620 Advance(2); | 4620 Advance(2); |
| 4621 } else { | 4621 } else { |
| 4622 return ReportError(CStrVector("Invalid escape")); | 4622 return ReportError(CStrVector("Invalid escape")); |
| 4623 } | 4623 } |
| 4624 break; | 4624 break; |
| 4625 } | 4625 } |
| 4626 } | 4626 } |
| 4627 // FALLTHROUGH | 4627 // FALLTHROUGH |
| 4628 case '0': { | 4628 case '0': { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4669 Advance(2); | 4669 Advance(2); |
| 4670 builder->AddCharacter(controlLetter & 0x1f); | 4670 builder->AddCharacter(controlLetter & 0x1f); |
| 4671 } | 4671 } |
| 4672 break; | 4672 break; |
| 4673 } | 4673 } |
| 4674 case 'x': { | 4674 case 'x': { |
| 4675 Advance(2); | 4675 Advance(2); |
| 4676 uc32 value; | 4676 uc32 value; |
| 4677 if (ParseHexEscape(2, &value)) { | 4677 if (ParseHexEscape(2, &value)) { |
| 4678 builder->AddCharacter(value); | 4678 builder->AddCharacter(value); |
| 4679 } else if (!FLAG_harmony_unicode || !unicode_) { | 4679 } else if (!FLAG_harmony_unicode_regexps || !unicode_) { |
| 4680 builder->AddCharacter('x'); | 4680 builder->AddCharacter('x'); |
| 4681 } else { | 4681 } else { |
| 4682 // If the 'u' flag is present, invalid escapes are not treated as | 4682 // If the 'u' flag is present, invalid escapes are not treated as |
| 4683 // identity escapes. | 4683 // identity escapes. |
| 4684 return ReportError(CStrVector("Invalid escape")); | 4684 return ReportError(CStrVector("Invalid escape")); |
| 4685 } | 4685 } |
| 4686 break; | 4686 break; |
| 4687 } | 4687 } |
| 4688 case 'u': { | 4688 case 'u': { |
| 4689 Advance(2); | 4689 Advance(2); |
| 4690 uc32 value; | 4690 uc32 value; |
| 4691 if (ParseUnicodeEscape(&value)) { | 4691 if (ParseUnicodeEscape(&value)) { |
| 4692 builder->AddCharacter(value); | 4692 builder->AddCharacter(value); |
| 4693 } else if (!FLAG_harmony_unicode || !unicode_) { | 4693 } else if (!FLAG_harmony_unicode_regexps || !unicode_) { |
| 4694 builder->AddCharacter('u'); | 4694 builder->AddCharacter('u'); |
| 4695 } else { | 4695 } else { |
| 4696 // If the 'u' flag is present, invalid escapes are not treated as | 4696 // If the 'u' flag is present, invalid escapes are not treated as |
| 4697 // identity escapes. | 4697 // identity escapes. |
| 4698 return ReportError(CStrVector("Invalid unicode escape")); | 4698 return ReportError(CStrVector("Invalid unicode escape")); |
| 4699 } | 4699 } |
| 4700 break; | 4700 break; |
| 4701 } | 4701 } |
| 4702 default: | 4702 default: |
| 4703 Advance(); | 4703 Advance(); |
| 4704 // If the 'u' flag is present, only syntax characters can be escaped, no | 4704 // If the 'u' flag is present, only syntax characters can be escaped, no |
| 4705 // other identity escapes are allowed. If the 'u' flag is not present, | 4705 // other identity escapes are allowed. If the 'u' flag is not present, |
| 4706 // all identity escapes are allowed. | 4706 // all identity escapes are allowed. |
| 4707 if (!FLAG_harmony_unicode || !unicode_ || | 4707 if (!FLAG_harmony_unicode_regexps || !unicode_ || |
| 4708 IsSyntaxCharacter(current())) { | 4708 IsSyntaxCharacter(current())) { |
| 4709 builder->AddCharacter(current()); | 4709 builder->AddCharacter(current()); |
| 4710 Advance(); | 4710 Advance(); |
| 4711 } else { | 4711 } else { |
| 4712 return ReportError(CStrVector("Invalid escape")); | 4712 return ReportError(CStrVector("Invalid escape")); |
| 4713 } | 4713 } |
| 4714 break; | 4714 break; |
| 4715 } | 4715 } |
| 4716 break; | 4716 break; |
| 4717 case '{': { | 4717 case '{': { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4968 } | 4968 } |
| 4969 *value = val; | 4969 *value = val; |
| 4970 return true; | 4970 return true; |
| 4971 } | 4971 } |
| 4972 | 4972 |
| 4973 | 4973 |
| 4974 bool RegExpParser::ParseUnicodeEscape(uc32* value) { | 4974 bool RegExpParser::ParseUnicodeEscape(uc32* value) { |
| 4975 // Accept both \uxxxx and \u{xxxxxx} (if harmony unicode escapes are | 4975 // Accept both \uxxxx and \u{xxxxxx} (if harmony unicode escapes are |
| 4976 // allowed). In the latter case, the number of hex digits between { } is | 4976 // allowed). In the latter case, the number of hex digits between { } is |
| 4977 // arbitrary. \ and u have already been read. | 4977 // arbitrary. \ and u have already been read. |
| 4978 if (current() == '{' && FLAG_harmony_unicode && unicode_) { | 4978 if (current() == '{' && FLAG_harmony_unicode_regexps && unicode_) { |
| 4979 int start = position(); | 4979 int start = position(); |
| 4980 Advance(); | 4980 Advance(); |
| 4981 if (ParseUnlimitedLengthHexNumber(0x10ffff, value)) { | 4981 if (ParseUnlimitedLengthHexNumber(0x10ffff, value)) { |
| 4982 if (current() == '}') { | 4982 if (current() == '}') { |
| 4983 Advance(); | 4983 Advance(); |
| 4984 return true; | 4984 return true; |
| 4985 } | 4985 } |
| 4986 } | 4986 } |
| 4987 Reset(start); | 4987 Reset(start); |
| 4988 return false; | 4988 return false; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5058 // For compatibility, we interpret a decimal escape that isn't | 5058 // For compatibility, we interpret a decimal escape that isn't |
| 5059 // a back reference (and therefore either \0 or not valid according | 5059 // a back reference (and therefore either \0 or not valid according |
| 5060 // to the specification) as a 1..3 digit octal character code. | 5060 // to the specification) as a 1..3 digit octal character code. |
| 5061 return ParseOctalLiteral(); | 5061 return ParseOctalLiteral(); |
| 5062 case 'x': { | 5062 case 'x': { |
| 5063 Advance(); | 5063 Advance(); |
| 5064 uc32 value; | 5064 uc32 value; |
| 5065 if (ParseHexEscape(2, &value)) { | 5065 if (ParseHexEscape(2, &value)) { |
| 5066 return value; | 5066 return value; |
| 5067 } | 5067 } |
| 5068 if (!FLAG_harmony_unicode || !unicode_) { | 5068 if (!FLAG_harmony_unicode_regexps || !unicode_) { |
| 5069 // If \x is not followed by a two-digit hexadecimal, treat it | 5069 // If \x is not followed by a two-digit hexadecimal, treat it |
| 5070 // as an identity escape. | 5070 // as an identity escape. |
| 5071 return 'x'; | 5071 return 'x'; |
| 5072 } | 5072 } |
| 5073 // If the 'u' flag is present, invalid escapes are not treated as | 5073 // If the 'u' flag is present, invalid escapes are not treated as |
| 5074 // identity escapes. | 5074 // identity escapes. |
| 5075 ReportError(CStrVector("Invalid escape")); | 5075 ReportError(CStrVector("Invalid escape")); |
| 5076 return 0; | 5076 return 0; |
| 5077 } | 5077 } |
| 5078 case 'u': { | 5078 case 'u': { |
| 5079 Advance(); | 5079 Advance(); |
| 5080 uc32 value; | 5080 uc32 value; |
| 5081 if (ParseUnicodeEscape(&value)) { | 5081 if (ParseUnicodeEscape(&value)) { |
| 5082 return value; | 5082 return value; |
| 5083 } | 5083 } |
| 5084 if (!FLAG_harmony_unicode || !unicode_) { | 5084 if (!FLAG_harmony_unicode_regexps || !unicode_) { |
| 5085 return 'u'; | 5085 return 'u'; |
| 5086 } | 5086 } |
| 5087 // If the 'u' flag is present, invalid escapes are not treated as | 5087 // If the 'u' flag is present, invalid escapes are not treated as |
| 5088 // identity escapes. | 5088 // identity escapes. |
| 5089 ReportError(CStrVector("Invalid unicode escape")); | 5089 ReportError(CStrVector("Invalid unicode escape")); |
| 5090 return 0; | 5090 return 0; |
| 5091 } | 5091 } |
| 5092 default: { | 5092 default: { |
| 5093 uc32 result = current(); | 5093 uc32 result = current(); |
| 5094 // If the 'u' flag is present, only syntax characters can be escaped, no | 5094 // If the 'u' flag is present, only syntax characters can be escaped, no |
| 5095 // other identity escapes are allowed. If the 'u' flag is not present, all | 5095 // other identity escapes are allowed. If the 'u' flag is not present, all |
| 5096 // identity escapes are allowed. | 5096 // identity escapes are allowed. |
| 5097 if (!FLAG_harmony_unicode || !unicode_ || IsSyntaxCharacter(result)) { | 5097 if (!FLAG_harmony_unicode_regexps || !unicode_ || |
| 5098 IsSyntaxCharacter(result)) { |
| 5098 Advance(); | 5099 Advance(); |
| 5099 return result; | 5100 return result; |
| 5100 } | 5101 } |
| 5101 ReportError(CStrVector("Invalid escape")); | 5102 ReportError(CStrVector("Invalid escape")); |
| 5102 return 0; | 5103 return 0; |
| 5103 } | 5104 } |
| 5104 } | 5105 } |
| 5105 return 0; | 5106 return 0; |
| 5106 } | 5107 } |
| 5107 | 5108 |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5412 } else { | 5413 } else { |
| 5413 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5414 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
| 5414 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5415 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
| 5415 raw_string->length()); | 5416 raw_string->length()); |
| 5416 } | 5417 } |
| 5417 } | 5418 } |
| 5418 | 5419 |
| 5419 return running_hash; | 5420 return running_hash; |
| 5420 } | 5421 } |
| 5421 } } // namespace v8::internal | 5422 } } // namespace v8::internal |
| OLD | NEW |