0089006fc5
.. similar to how it is applied in the interpreter. We reserve a stack slot for the backtrack count, increment it on each backtrack, and fail if the limit is hit. Bug: v8:9695 Change-Id: I835888c612d6c8bfa2f34e73ab8c8241dcabc6ed Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1864938 Reviewed-by: Peter Marshall <petermarshall@chromium.org> Commit-Queue: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#64426}
32 lines
1009 B
JavaScript
32 lines
1009 B
JavaScript
// Copyright 2019 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: --allow-natives-syntax
|
|
|
|
const kNoBacktrackLimit = 0; // To match JSRegExp::kNoBacktrackLimit.
|
|
const re0 = %NewRegExpWithBacktrackLimit("(\\d+)+x", "", kNoBacktrackLimit);
|
|
const re1 = %NewRegExpWithBacktrackLimit("(\\d+)+x", "", 50);
|
|
|
|
// Backtracks remain below the limit on this subject string.
|
|
{
|
|
let s = "3333ax3333x";
|
|
assertArrayEquals(["3333x", "3333"], re0.exec(s));
|
|
assertEquals(["3333x", "3333"], re1.exec(s));
|
|
}
|
|
|
|
// A longer subject exceeds the limit.
|
|
{
|
|
let s = "333333333ax3333x";
|
|
assertArrayEquals(["3333x", "3333"], re0.exec(s));
|
|
assertEquals(null, re1.exec(s));
|
|
}
|
|
|
|
// ATOM regexp construction with a limit; in this case the limit should just be
|
|
// ignored, ATOMs never backtrack.
|
|
{
|
|
const re = %NewRegExpWithBacktrackLimit("ax", "", 50);
|
|
let s = "3333ax3333x";
|
|
assertArrayEquals(["ax"], re.exec(s));
|
|
}
|