Commit 4cd39f12 authored by lrn@chromium.org's avatar lrn@chromium.org

Fix bug in RegExp first-character-lookahead.

Review URL: http://codereview.chromium.org/1253008

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4267 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 41830911
...@@ -4987,7 +4987,9 @@ int AssertionNode::ComputeFirstCharacterSet(int budget) { ...@@ -4987,7 +4987,9 @@ int AssertionNode::ComputeFirstCharacterSet(int budget) {
case AFTER_WORD_CHARACTER: { case AFTER_WORD_CHARACTER: {
ASSERT_NOT_NULL(on_success()); ASSERT_NOT_NULL(on_success());
budget = on_success()->ComputeFirstCharacterSet(budget); budget = on_success()->ComputeFirstCharacterSet(budget);
if (budget >= 0) {
set_first_character_set(on_success()->first_character_set()); set_first_character_set(on_success()->first_character_set());
}
break; break;
} }
} }
...@@ -5013,6 +5015,10 @@ int ActionNode::ComputeFirstCharacterSet(int budget) { ...@@ -5013,6 +5015,10 @@ int ActionNode::ComputeFirstCharacterSet(int budget) {
int BackReferenceNode::ComputeFirstCharacterSet(int budget) { int BackReferenceNode::ComputeFirstCharacterSet(int budget) {
// We don't know anything about the first character of a backreference // We don't know anything about the first character of a backreference
// at this point. // at this point.
// The potential first characters are the first characters of the capture,
// and the first characters of the on_success node, depending on whether the
// capture can be empty and whether it is known to be participating or known
// not to be.
return kComputeFirstCharacterSetFail; return kComputeFirstCharacterSetFail;
} }
...@@ -5032,8 +5038,11 @@ int TextNode::ComputeFirstCharacterSet(int budget) { ...@@ -5032,8 +5038,11 @@ int TextNode::ComputeFirstCharacterSet(int budget) {
} else { } else {
ASSERT(text.type == TextElement::CHAR_CLASS); ASSERT(text.type == TextElement::CHAR_CLASS);
RegExpCharacterClass* char_class = text.data.u_char_class; RegExpCharacterClass* char_class = text.data.u_char_class;
if (char_class->is_negated()) {
ZoneList<CharacterRange>* ranges = char_class->ranges(); ZoneList<CharacterRange>* ranges = char_class->ranges();
// TODO(lrn): Canonicalize ranges when they are created
// instead of waiting until now.
CharacterRange::Canonicalize(ranges);
if (char_class->is_negated()) {
int length = ranges->length(); int length = ranges->length();
int new_length = length + 1; int new_length = length + 1;
if (length > 0) { if (length > 0) {
...@@ -5047,7 +5056,7 @@ int TextNode::ComputeFirstCharacterSet(int budget) { ...@@ -5047,7 +5056,7 @@ int TextNode::ComputeFirstCharacterSet(int budget) {
CharacterRange::Negate(ranges, negated_ranges); CharacterRange::Negate(ranges, negated_ranges);
set_first_character_set(negated_ranges); set_first_character_set(negated_ranges);
} else { } else {
set_first_character_set(char_class->ranges()); set_first_character_set(ranges);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment