fa88b378a4
This reverts commit f2a74165bf
.
Reason for revert: Clusterfuzz
Bug: chromium:1026479
Original change's description:
> [regexp] Re-execute regexp when '.indices' is accessed.
>
> Instead of storing a pointer to the last_match_info, which may
> change, this cl modifies JSRegExpResult to store a pointer to
> the original JSRegExp which generated it, as well as additional
> data needed to re-execute the match.
>
> Basically a straight copy and tidy off jgruber@'s prototype:
> https://chromium-review.googlesource.com/c/v8/v8/+/1876810
>
> Bug: v8:9548
> Change-Id: I11b7deae681b8287e41e8d0e342291ff484751fb
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1910129
> Commit-Queue: Joshua Litt <joshualitt@chromium.org>
> Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#65053}
TBR=jgruber@chromium.org,joshualitt@chromium.org
Change-Id: I6294e3d7ac0b3e2bd9404697823b8d3cc2545c16
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:9548
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1925651
Reviewed-by: Joshua Litt <joshualitt@chromium.org>
Commit-Queue: Joshua Litt <joshualitt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65057}
114 lines
2.2 KiB
JavaScript
114 lines
2.2 KiB
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: --harmony-regexp-match-indices --expose-gc
|
|
|
|
// Sanity test.
|
|
{
|
|
const re = /a+(?<Z>z)?/;
|
|
const m = re.exec("xaaaz");
|
|
|
|
assertEquals(m.indices, [[1, 5], [4, 5]]);
|
|
assertEquals(m.indices.groups, {'Z': [4, 5]})
|
|
}
|
|
|
|
// Capture groups that are not matched return `undefined`.
|
|
{
|
|
const re = /a+(?<Z>z)?/;
|
|
const m = re.exec("xaaay");
|
|
|
|
assertEquals(m.indices, [[1, 4], undefined]);
|
|
assertEquals(m.indices.groups, {'Z': undefined});
|
|
}
|
|
|
|
// Two capture groups.
|
|
{
|
|
const re = /a+(?<A>zz)?(?<B>ii)?/;
|
|
const m = re.exec("xaaazzii");
|
|
|
|
assertEquals(m.indices, [[1, 8], [4, 6], [6, 8]]);
|
|
assertEquals(m.indices.groups, {'A': [4, 6], 'B': [6, 8]});
|
|
}
|
|
|
|
// No capture groups.
|
|
{
|
|
const re = /a+/;
|
|
const m = re.exec("xaaazzii");
|
|
|
|
assertEquals(m.indices [[1, 4]]);
|
|
assertEquals(m.indices.groups, undefined);
|
|
}
|
|
|
|
// No match.
|
|
{
|
|
const re = /a+/;
|
|
const m = re.exec("xzzii");
|
|
|
|
assertEquals(null, m);
|
|
}
|
|
|
|
// Unnamed capture groups.
|
|
{
|
|
const re = /a+(z)?/;
|
|
const m = re.exec("xaaaz")
|
|
|
|
assertEquals(m.indices, [[1, 5], [4, 5]]);
|
|
assertEquals(m.indices.groups, undefined)
|
|
}
|
|
|
|
// Named and unnamed capture groups.
|
|
{
|
|
const re = /a+(z)?(?<Y>y)?/;
|
|
const m = re.exec("xaaazyy")
|
|
|
|
assertEquals(m.indices, [[1, 6], [4, 5], [5, 6]]);
|
|
assertEquals(m.indices.groups, {'Y': [5, 6]})
|
|
}
|
|
|
|
|
|
// Verify property overwrite.
|
|
{
|
|
const re = /a+(?<Z>z)?/;
|
|
const m = re.exec("xaaaz");
|
|
|
|
m.indices = null;
|
|
assertEquals(null, m.indices);
|
|
}
|
|
|
|
// Mess with array prototype, we should still do the right thing.
|
|
{
|
|
Object.defineProperty(Array.prototype, "groups", {
|
|
get: () => {
|
|
assertUnreachable();
|
|
return null;
|
|
},
|
|
set: (x) => {
|
|
assertUnreachable();
|
|
}
|
|
});
|
|
|
|
Object.defineProperty(Array.prototype, "0", {
|
|
get: () => {
|
|
assertUnreachable();
|
|
return null;
|
|
},
|
|
set: (x) => {
|
|
assertUnreachable();
|
|
}
|
|
});
|
|
|
|
const re = /a+(?<Z>z)?/;
|
|
const m = re.exec("xaaaz");
|
|
|
|
assertEquals(m.indices.groups, {'Z': [4, 5]})
|
|
}
|
|
|
|
// Test deleting unrelated fields does not break.
|
|
{
|
|
const m = /undefined/.exec();
|
|
delete m['index'];
|
|
gc();
|
|
assertEquals(m.indices, [[0, 9]]);
|
|
}
|