Commit 65d3009e authored by yangguo's avatar yangguo Committed by Commit bot

[regexp] clear QuickCheckDetails for backward reads.

R=erik.corry@gmail.com
BUG=chromium:570241
LOG=N

Review URL: https://codereview.chromium.org/1528333002

Cr-Commit-Position: refs/heads/master@{#32898}
parent 2bb6e197
......@@ -2327,8 +2327,7 @@ int TextNode::EatsAtLeast(int still_to_find,
}
int NegativeLookaheadChoiceNode::EatsAtLeast(int still_to_find,
int budget,
int NegativeLookaroundChoiceNode::EatsAtLeast(int still_to_find, int budget,
bool not_at_start) {
if (budget <= 0) return 0;
// Alternative 0 is the negative lookahead, alternative 1 is what comes
......@@ -2338,10 +2337,8 @@ int NegativeLookaheadChoiceNode::EatsAtLeast(int still_to_find,
}
void NegativeLookaheadChoiceNode::GetQuickCheckDetails(
QuickCheckDetails* details,
RegExpCompiler* compiler,
int filled_in,
void NegativeLookaroundChoiceNode::GetQuickCheckDetails(
QuickCheckDetails* details, RegExpCompiler* compiler, int filled_in,
bool not_at_start) {
// Alternative 0 is the negative lookahead, alternative 1 is what comes
// afterwards.
......@@ -2511,6 +2508,9 @@ void TextNode::GetQuickCheckDetails(QuickCheckDetails* details,
RegExpCompiler* compiler,
int characters_filled_in,
bool not_at_start) {
// Do not collect any quick check details if the text node reads backward,
// since it reads in the opposite direction than we use for quick checks.
if (read_backward()) return;
Isolate* isolate = compiler->macro_assembler()->isolate();
DCHECK(characters_filled_in < details->characters());
int characters = details->characters();
......@@ -2672,10 +2672,13 @@ void QuickCheckDetails::Clear() {
void QuickCheckDetails::Advance(int by, bool one_byte) {
if (by >= characters_) {
if (by >= characters_ || by < 0) {
DCHECK_IMPLIES(by < 0, characters_ == 0);
Clear();
return;
}
DCHECK_LE(characters_ - by, 4);
DCHECK_LE(characters_, 4);
for (int i = 0; i < characters_ - by; i++) {
positions_[i] = positions_[by + i];
}
......@@ -2891,7 +2894,7 @@ RegExpNode* ChoiceNode::FilterOneByte(int depth, bool ignore_case) {
}
RegExpNode* NegativeLookaheadChoiceNode::FilterOneByte(int depth,
RegExpNode* NegativeLookaroundChoiceNode::FilterOneByte(int depth,
bool ignore_case) {
if (info()->replacement_calculated) return replacement();
if (depth < 0) return this;
......@@ -5373,10 +5376,8 @@ RegExpNode* RegExpLookaround::ToNode(RegExpCompiler* compiler,
body()->ToNode(compiler, new (zone) NegativeSubmatchSuccess(
stack_pointer_register, position_register,
register_count, register_start, zone)));
ChoiceNode* choice_node =
new(zone) NegativeLookaheadChoiceNode(body_alt,
GuardedAlternative(on_success),
zone);
ChoiceNode* choice_node = new (zone) NegativeLookaroundChoiceNode(
body_alt, GuardedAlternative(on_success), zone);
result = ActionNode::BeginSubmatch(stack_pointer_register,
position_register, choice_node);
}
......
......@@ -1114,9 +1114,9 @@ class ChoiceNode: public RegExpNode {
};
class NegativeLookaheadChoiceNode: public ChoiceNode {
class NegativeLookaroundChoiceNode : public ChoiceNode {
public:
explicit NegativeLookaheadChoiceNode(GuardedAlternative this_must_fail,
explicit NegativeLookaroundChoiceNode(GuardedAlternative this_must_fail,
GuardedAlternative then_do_this,
Zone* zone)
: ChoiceNode(2, zone) {
......
// Copyright 2013 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-regexp-lookbehind
assertTrue(/(?<=12345123451234512345)/.test("12345123451234512345"));
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