Reviewers: Erik Corry, sandholm,

Message:
Small review.

Description:
Fix bug in word-boundary-lookahead followed by end-of-input assertion.

Please review this at http://codereview.chromium.org/1712013/show

Affected files:
  M src/jsregexp.cc
  M src/regexp-macro-assembler-tracer.cc
  M test/mjsunit/regexp.js


Index: src/jsregexp.cc
diff --git a/src/jsregexp.cc b/src/jsregexp.cc
index 0ae8bd34df23641bebf25bf497423e309c6d0119..9a1f1f114c0145de49657882f6df3868d5a8db78 100644
--- a/src/jsregexp.cc
+++ b/src/jsregexp.cc
@@ -4872,17 +4872,18 @@ void Analysis::VisitAssertion(AssertionNode* that) {

     SetRelation word_relation =
         CharacterRange::WordCharacterRelation(following_chars);
-    if (word_relation.ContainedIn()) {
-      // Following character is definitely a word character.
+    if (word_relation.Disjoint()) {
+ // Includes the case where following_chars is empty (e.g., end-of-input).
+      // Following character is definitely *not* a word character.
       type = (type == AssertionNode::AT_BOUNDARY) ?
-                  AssertionNode::AFTER_NONWORD_CHARACTER :
-                  AssertionNode::AFTER_WORD_CHARACTER;
+                 AssertionNode::AFTER_WORD_CHARACTER :
+                 AssertionNode::AFTER_NONWORD_CHARACTER;
       that->set_type(type);
-    } else if (word_relation.Disjoint()) {
-      // Following character is definitely *not* a word character.
+    } else if (word_relation.ContainedIn()) {
+      // Following character is definitely a word character.
       type = (type == AssertionNode::AT_BOUNDARY) ?
-                  AssertionNode::AFTER_WORD_CHARACTER :
-                  AssertionNode::AFTER_NONWORD_CHARACTER;
+                 AssertionNode::AFTER_NONWORD_CHARACTER :
+                 AssertionNode::AFTER_WORD_CHARACTER;
       that->set_type(type);
     }
   }
Index: src/regexp-macro-assembler-tracer.cc
diff --git a/src/regexp-macro-assembler-tracer.cc b/src/regexp-macro-assembler-tracer.cc index c5c2919c3fb9d5bf71fd1357c99dacc19cd70c1a..522042262f58e561c88f9f00464b7ad5685b9078 100644
--- a/src/regexp-macro-assembler-tracer.cc
+++ b/src/regexp-macro-assembler-tracer.cc
@@ -37,8 +37,8 @@ RegExpMacroAssemblerTracer::RegExpMacroAssemblerTracer(
     RegExpMacroAssembler* assembler) :
   assembler_(assembler) {
   unsigned int type = assembler->Implementation();
-  ASSERT(type < 3);
-  const char* impl_names[3] = {"IA32", "ARM", "Bytecode"};
+  ASSERT(type < 4);
+  const char* impl_names[3] = {"IA32", "ARM", "X64", "Bytecode"};
   PrintF("RegExpMacroAssembler%s();\n", impl_names[type]);
 }

Index: test/mjsunit/regexp.js
diff --git a/test/mjsunit/regexp.js b/test/mjsunit/regexp.js
index c8dcc6fe89ce443d0ee8f5674faeaa06b1c9282d..81e1d2c62b3290b3f2890e91b6dcb128aa3e4c27 100644
--- a/test/mjsunit/regexp.js
+++ b/test/mjsunit/regexp.js
@@ -436,3 +436,14 @@ assertTrue(re.multiline);
 assertEquals(0, re.lastIndex);
 assertEquals(37, re.someOtherProperty);
 assertEquals(37, re[42]);
+
+// Test boundary-checks.
+assertTrue(/b\b/.test("b"));
+assertTrue(/b\b$/.test("b"));
+assertTrue(/\bb/.test("b"));
+assertTrue(/^\bb/.test("b"));
+assertFalse(/,\b/.test(","));
+assertFalse(/,\b$/.test(","));
+assertFalse(/\b,/.test(","));
+assertFalse(/^\b,/.test(","));
+


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to