Updates to regexp-match-indices tests based on d-flag

This commit is contained in:
Ron Buckton 2021-01-14 23:06:42 -08:00 committed by Rick Waldron
parent f6034ebe9f
commit a567e4c819
28 changed files with 463 additions and 115 deletions

View File

@ -7,7 +7,7 @@ info: |
5. If F contains any code unit other than "g", "i", "m", "s", "u", or "y" or if it contains the same code unit more than once, throw a SyntaxError exception.
esid: sec-regexpinitialize
description: Check that duplicate RegExp flags are disallowed
features: [regexp-dotall]
features: [regexp-dotall, regexp-match-indices]
---*/
new RegExp("", "mig"); // single g will not throw SyntaxError
@ -27,3 +27,6 @@ assert.throws(SyntaxError, () => new RegExp("", "uu"), "duplicate u");
new RegExp("", "y"); // single y will not throw SyntaxError
assert.throws(SyntaxError, () => new RegExp("", "yy"), "duplicate y");
new RegExp("", "d"); // single d will not throw SyntaxError
assert.throws(SyntaxError, () => new RegExp("", "dd"), "duplicate d");

View File

@ -11,7 +11,7 @@ info: |
---*/
let input = "abcd";
let match = /b(c)/.exec(input);
let match = /b(c)/d.exec(input);
let indices = match.indices;
// `indices[0]` is an array

View File

@ -7,12 +7,12 @@ includes: [compareArray.js]
esid: sec-makeindicesarray
features: [regexp-match-indices]
info: |
MakeIndicesArray ( S, indices, groupNames )
MakeIndicesArray ( S, indices, groupNames, hasIndices )
4. Let _n_ be the number of elements in _indices_.
...
6. Set _A_ to ! ArrayCreate(_n_).
8. Set _A_ to ! ArrayCreate(_n_).
...
11. For each integer _i_ such that _i_ >= 0 and _i_ < _n_, do
13. For each integer _i_ such that _i_ >= 0 and _i_ < _n_, do
a. Let _matchIndices_ be _indices_[_i_].
b. If _matchIndices_ is not *undefined*, then
i. Let _matchIndicesArray_ be ! GetMatchIndicesArray(_S_, _matchIndices_).
@ -23,7 +23,7 @@ info: |
---*/
let input = "abcd";
let match = /b(c)/.exec(input);
let match = /b(c)/d.exec(input);
let indices = match.indices;
// `indices` has the same length as match

View File

@ -11,11 +11,13 @@ info: |
...
4. Let _lastIndex_ be ? ToLength(? Get(_R_, `"lastIndex")).
...
25. Let _indices_ be a new empty List.
26. Let _match_ be the Match { [[StartIndex]]: _lastIndex_, [[EndIndex]]: _e_ }.
27. Add _match_ as the last element of _indices_.
8. If _flags_ contains `"d"`, let _hasIndices_ be *true*, else let _hasIndices_ be *false*.
...
33. For each integer _i_ such that _i_ > 0 and _i_ <= _n_, in ascending order, do
26. Let _match_ be the Match { [[StartIndex]]: _lastIndex_, [[EndIndex]]: _e_ }.
27. Let _indices_ be a new empty List.
29. Add _match_ as the last element of _indices_.
...
35. For each integer _i_ such that _i_ > 0 and _i_ <= _n_, in ascending order, do
...
f. Else,
i. Let _captureStart_ be _captureI_'s _startIndex_.
@ -24,18 +26,20 @@ info: |
iv. Let _capture_ be the Match { [[StartIndex]]: _captureStart_, [[EndIndex]]: _captureEnd_ }.
v. Append _capture_ to _indices_.
...
34. Let _indicesArray_ be MakeIndicesArray( _S_, _indices_, _groupNames_).
36. If _hasIndices_ is *true*, then
a. Let _indicesArray_ be MakeIndicesArray( _S_, _indices_, _groupNames_).
b. Perform ! CreateDataProperty(_A_, `"indices"`, _indicesArray_).
---*/
assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/).indices);
assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./).indices);
assert.deepEqual([[0, 3], [1, 2], [2, 3]], "bab".match(/.(a)(.)/).indices);
assert.deepEqual([[0, 3], [1, 3]], "bab".match(/.(\w\w)/).indices);
assert.deepEqual([[0, 3], [0, 3]], "bab".match(/(\w\w\w)/).indices);
assert.deepEqual([[0, 3], [0, 2], [2, 3]], "bab".match(/(\w\w)(\w)/).indices);
assert.deepEqual([[0, 2], [0, 2], undefined], "bab".match(/(\w\w)(\W)?/).indices);
assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/d).indices);
assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./d).indices);
assert.deepEqual([[0, 3], [1, 2], [2, 3]], "bab".match(/.(a)(.)/d).indices);
assert.deepEqual([[0, 3], [1, 3]], "bab".match(/.(\w\w)/d).indices);
assert.deepEqual([[0, 3], [0, 3]], "bab".match(/(\w\w\w)/d).indices);
assert.deepEqual([[0, 3], [0, 2], [2, 3]], "bab".match(/(\w\w)(\w)/d).indices);
assert.deepEqual([[0, 2], [0, 2], undefined], "bab".match(/(\w\w)(\W)?/d).indices);
let groups = /(?<a>.)(?<b>.)(?<c>.)\k<c>\k<b>\k<a>/.exec("abccba").indices.groups;
let groups = /(?<a>.)(?<b>.)(?<c>.)\k<c>\k<b>\k<a>/d.exec("abccba").indices.groups;
assert.compareArray([0, 1], groups.a);
assert.compareArray([1, 2], groups.b);
assert.compareArray([2, 3], groups.c);
@ -67,9 +71,9 @@ assert.sameValue("𝐁".match(/./)[0].length, 1, 'The length of a single code un
assert.sameValue("\u{1d401}".match(/./)[0].length, 1, 'The length of a single code unit match against "\\u{1d401}" is 1 (without /u flag)');
assert.sameValue("\uD835\uDC01".match(/./)[0].length, 1, 'The length of a single code unit match against "\\ud835\\udc01" is 1 (without /u flag)');
assert.compareArray([0, 1], "𝐁".match(/./).indices[0], 'Indices for non-unicode match against "𝐁" (without /u flag)');
assert.compareArray([0, 1], "\u{1d401}".match(/./).indices[0], 'Indices for non-unicode match against "\\u{1d401}" (without /u flag)');
assert.compareArray([0, 1], "\uD835\uDC01".match(/./).indices[0], 'Indices for non-unicode match against "\\ud835\\udc01" (without /u flag)');
assert.compareArray([0, 1], "𝐁".match(/(?<a>.)/).indices.groups.a, 'Indices for non-unicode match against "𝐁" in groups.a (without /u flag)');
assert.compareArray([0, 1], "\u{1d401}".match(/(?<a>.)/).indices.groups.a, 'Indices for non-unicode match against "\\u{1d401}" in groups.a (without /u flag)');
assert.compareArray([0, 1], "\uD835\uDC01".match(/(?<a>.)/).indices.groups.a, 'Indices for non-unicode match against "\\ud835\\udc01" in groups.a (without /u flag)');
assert.compareArray([0, 1], "𝐁".match(/./d).indices[0], 'Indices for non-unicode match against "𝐁" (without /u flag)');
assert.compareArray([0, 1], "\u{1d401}".match(/./d).indices[0], 'Indices for non-unicode match against "\\u{1d401}" (without /u flag)');
assert.compareArray([0, 1], "\uD835\uDC01".match(/./d).indices[0], 'Indices for non-unicode match against "\\ud835\\udc01" (without /u flag)');
assert.compareArray([0, 1], "𝐁".match(/(?<a>.)/d).indices.groups.a, 'Indices for non-unicode match against "𝐁" in groups.a (without /u flag)');
assert.compareArray([0, 1], "\u{1d401}".match(/(?<a>.)/d).indices.groups.a, 'Indices for non-unicode match against "\\u{1d401}" in groups.a (without /u flag)');
assert.compareArray([0, 1], "\uD835\uDC01".match(/(?<a>.)/d).indices.groups.a, 'Indices for non-unicode match against "\\ud835\\udc01" in groups.a (without /u flag)');

View File

@ -7,13 +7,13 @@ includes: [propertyHelper.js]
esid: sec-makeindicesarray
features: [regexp-match-indices]
info: |
MakeIndicesArray ( S, indices, groupNames )
11. For each integer _i_ such that _i_ >= 0 and _i_ < _n_, do
MakeIndicesArray ( S, indices, groupNames, hasGroups )
13. For each integer _i_ such that _i_ >= 0 and _i_ < _n_, do
d. Perform ! CreateDataProperty(_A_, ! ToString(_n_), _matchIndicesArray_).
---*/
let input = "abcd";
let match = /b(c)/.exec(input);
let match = /b(c)/d.exec(input);
let indices = match.indices;
verifyProperty(indices, '0', {

View File

@ -13,11 +13,12 @@ info: |
...
16. If _fullUnicode_ is *true*, set _e_ to ! GetStringIndex(_S_, _Input_, _e_).
...
25. Let _indices_ be a new empty List.
26. Let _match_ be the Match { [[StartIndex]]: _lastIndex_, [[EndIndex]]: _e_ }.
27. Add _match_ as the last element of _indices_.
27. Let _indices_ be a new empty List.
...
33. For each integer _i_ such that _i_ > 0 and _i_ <= _n_, in ascending order, do
29. Add _match_ as the last element of _indices_.
...
35. For each integer _i_ such that _i_ > 0 and _i_ <= _n_, in ascending order, do
...
f. Else,
i. Let _captureStart_ be _captureI_'s _startIndex_.
@ -28,7 +29,9 @@ info: |
iv. Let _capture_ be the Match { [[StartIndex]]: _captureStart_, [[EndIndex]]: _captureEnd_ }.
v. Append _capture_ to _indices_.
...
34. Let _indicesArray_ be MakeIndicesArray( _S_, _indices_, _groupNames_).
36. If _hasIndices_ is *true*, then
a. Let _indicesArray_ be MakeIndicesArray(_S_, _indices_, _groupNames_, _hasGroups_).
b. Perform ! CreateDataProperty(_A_, `"indices"`, _indicesArray_).
GetStringIndex ( S, Input, e )
...
@ -36,15 +39,15 @@ info: |
5. Return _eUTF_.
---*/
assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/u).indices);
assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./u).indices);
assert.deepEqual([[0, 3], [1, 2], [2, 3]], "bab".match(/.(a)(.)/u).indices);
assert.deepEqual([[0, 3], [1, 3]], "bab".match(/.(\w\w)/u).indices);
assert.deepEqual([[0, 3], [0, 3]], "bab".match(/(\w\w\w)/u).indices);
assert.deepEqual([[0, 3], [0, 2], [2, 3]], "bab".match(/(\w\w)(\w)/u).indices);
assert.deepEqual([[0, 2], [0, 2], undefined], "bab".match(/(\w\w)(\W)?/u).indices);
assert.deepEqual([[1, 2], [1, 2]], "bab".match(/(a)/du).indices);
assert.deepEqual([[0, 3], [1, 2]], "bab".match(/.(a)./du).indices);
assert.deepEqual([[0, 3], [1, 2], [2, 3]], "bab".match(/.(a)(.)/du).indices);
assert.deepEqual([[0, 3], [1, 3]], "bab".match(/.(\w\w)/du).indices);
assert.deepEqual([[0, 3], [0, 3]], "bab".match(/(\w\w\w)/du).indices);
assert.deepEqual([[0, 3], [0, 2], [2, 3]], "bab".match(/(\w\w)(\w)/du).indices);
assert.deepEqual([[0, 2], [0, 2], undefined], "bab".match(/(\w\w)(\W)?/du).indices);
let groups = /(?<a>.)(?<b>.)(?<c>.)\k<c>\k<b>\k<a>/u.exec("abccba").indices.groups;
let groups = /(?<a>.)(?<b>.)(?<c>.)\k<c>\k<b>\k<a>/du.exec("abccba").indices.groups;
assert.compareArray([0, 1], groups.a);
assert.compareArray([1, 2], groups.b);
assert.compareArray([2, 3], groups.c);
@ -72,13 +75,13 @@ verifyProperty(groups, "c", {
assert.sameValue("𝐁".length, 2, 'The length of "𝐁" is 2');
assert.sameValue("\u{1d401}".length, 2, 'The length of "\\u{1d401}" is 2');
assert.sameValue("\uD835\uDC01".length, 2, 'The length of "\\uD835\\uDC01" is 2');
assert.sameValue(2, "𝐁".match(/./u)[0].length, 'The length of a single code point match against "𝐁" is 2 (with /u flag)');
assert.sameValue(2, "\u{1d401}".match(/./u)[0].length, 'The length of a single code point match against "\\u{1d401}" is 2 (with /u flag)');
assert.sameValue(2, "\uD835\uDC01".match(/./u)[0].length, 'The length of a single code point match against "\\ud835\\udc01" is 2 (with /u flag)');
assert.sameValue(2, "𝐁".match(/./u)[0].length, 'The length of a single code point match against "𝐁" is 2 (with /du flag)');
assert.sameValue(2, "\u{1d401}".match(/./u)[0].length, 'The length of a single code point match against "\\u{1d401}" is 2 (with /du flag)');
assert.sameValue(2, "\uD835\uDC01".match(/./u)[0].length, 'The length of a single code point match against "\\ud835\\udc01" is 2 (with /du flag)');
assert.compareArray([0, 2], "𝐁".match(/./u).indices[0], 'Indices for unicode match against "𝐁" (with /u flag)');
assert.compareArray([0, 2], "\u{1d401}".match(/./u).indices[0], 'Indices for unicode match against \\u{1d401} (with /u flag)');
assert.compareArray([0, 2], "\uD835\uDC01".match(/./u).indices[0], 'Indices for unicode match against \\ud835\\udc01 (with /u flag)');
assert.compareArray([0, 2], "𝐁".match(/(?<a>.)/u).indices.groups.a, 'Indices for unicode match against 𝐁 in groups.a (with /u flag)');
assert.compareArray([0, 2], "\u{1d401}".match(/(?<a>.)/u).indices.groups.a, 'Indices for unicode match against \\u{1d401} in groups.a (with /u flag)');
assert.compareArray([0, 2], "\uD835\uDC01".match(/(?<a>.)/u).indices.groups.a, 'Indices for unicode match against \\ud835\\udc01 in groups.a (with /u flag)');
assert.compareArray([0, 2], "𝐁".match(/./du).indices[0], 'Indices for unicode match against "𝐁" (with /du flag)');
assert.compareArray([0, 2], "\u{1d401}".match(/./du).indices[0], 'Indices for unicode match against \\u{1d401} (with /du flag)');
assert.compareArray([0, 2], "\uD835\uDC01".match(/./du).indices[0], 'Indices for unicode match against \\ud835\\udc01 (with /du flag)');
assert.compareArray([0, 2], "𝐁".match(/(?<a>.)/du).indices.groups.a, 'Indices for unicode match against 𝐁 in groups.a (with /du flag)');
assert.compareArray([0, 2], "\u{1d401}".match(/(?<a>.)/du).indices.groups.a, 'Indices for unicode match against \\u{1d401} in groups.a (with /du flag)');
assert.compareArray([0, 2], "\uD835\uDC01".match(/(?<a>.)/du).indices.groups.a, 'Indices for unicode match against \\ud835\\udc01 in groups.a (with /du flag)');

View File

@ -8,13 +8,13 @@ esid: sec-makeindicesarray
features: [regexp-match-indices]
---*/
assert.compareArray([1, 2], /(?<π>a)/u.exec("bab").indices.groups.π);
assert.compareArray([1, 2], /(?<\u{03C0}>a)/u.exec("bab").indices.groups.π);
assert.compareArray([1, 2], /(?<π>a)/u.exec("bab").indices.groups.\u03C0);
assert.compareArray([1, 2], /(?<\u{03C0}>a)/u.exec("bab").indices.groups.\u03C0);
assert.compareArray([1, 2], /(?<$>a)/u.exec("bab").indices.groups.$);
assert.compareArray([1, 2], /(?<_>a)/u.exec("bab").indices.groups._);
assert.compareArray([1, 2], /(?<$𐒤>a)/u.exec("bab").indices.groups.$𐒤);
assert.compareArray([1, 2], /(?<_\u200C>a)/u.exec("bab").indices.groups._\u200C);
assert.compareArray([1, 2], /(?<_\u200D>a)/u.exec("bab").indices.groups._\u200D);
assert.compareArray([1, 2], /(?<ಠ_ಠ>a)/u.exec("bab").indices.groups._ಠ);
assert.compareArray([1, 2], /(?<π>a)/du.exec("bab").indices.groups.π);
assert.compareArray([1, 2], /(?<\u{03C0}>a)/du.exec("bab").indices.groups.π);
assert.compareArray([1, 2], /(?<π>a)/du.exec("bab").indices.groups.\u03C0);
assert.compareArray([1, 2], /(?<\u{03C0}>a)/du.exec("bab").indices.groups.\u03C0);
assert.compareArray([1, 2], /(?<$>a)/du.exec("bab").indices.groups.$);
assert.compareArray([1, 2], /(?<_>a)/du.exec("bab").indices.groups._);
assert.compareArray([1, 2], /(?<$𐒤>a)/du.exec("bab").indices.groups.$𐒤);
assert.compareArray([1, 2], /(?<_\u200C>a)/du.exec("bab").indices.groups._\u200C);
assert.compareArray([1, 2], /(?<_\u200D>a)/du.exec("bab").indices.groups._\u200D);
assert.compareArray([1, 2], /(?<_>a)/du.exec("bab").indices.groups._);

View File

@ -22,7 +22,7 @@ info: |
---*/
let input = "abd";
let match = /b(c)?/.exec(input);
let match = /b(c)?/d.exec(input);
let indices = match.indices;
// `indices` has the same length as match

View File

@ -6,11 +6,11 @@ description: The "indices" property is an Array.
esid: sec-makeindicesarray
features: [regexp-match-indices]
info: |
MakeIndicesArray ( S, indices, groupNames )
MakeIndicesArray ( S, indices, groupNames, hasGroups )
6. Set _A_ to ! ArrayCreate(_n_).
---*/
let match = /a/.exec("a");
let match = /a/d.exec("a");
let indices = match.indices;
// `indices` is an array

View File

@ -7,16 +7,16 @@ includes: [propertyHelper.js]
esid: sec-makeindicesarray
features: [regexp-named-groups, regexp-match-indices]
info: |
MakeIndicesArray ( S, indices, groupNames )
8. If _groupNames_ is not *undefined*, then
MakeIndicesArray ( S, indices, groupNames, hasGroups )
10. If _hasGroups_ is *true*, then
a. Let _groups_ be ! ObjectCreate(*null*).
9. Else,
11. Else,
a. Let _groups_ be *undefined*.
10. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_).
12. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_).
---*/
const re = /./;
const re = /./d;
const indices = re.exec("a").indices;
verifyProperty(indices, 'groups', {
writable: true,

View File

@ -7,14 +7,14 @@ includes: [compareArray.js]
esid: sec-makeindicesarray
features: [regexp-named-groups, regexp-match-indices]
info: |
MakeIndicesArray ( S, indices, groupNames )
MakeIndicesArray ( S, indices, groupNames, hasGroups )
11. For each integer _i_ such that _i_ >= 0 and _i_ < _n_, do
e. If _groupNames_ is not *undfined* and _groupNames_[_i_] is not *undefined*, then
i. Perform ! CreateDataProperty(_groups_, _groupNames_[_i_], _matchIndicesArray_).
e. If _i_ > 0 and _groupNames_[_i_ - 1] is not *undefined*, then
i. Perform ! CreateDataProperty(_groups_, _groupNames_[_i_ - 1], _matchIndicesArray_).
---*/
const re = /(?<a>a).|(?<x>x)/;
const re = /(?<a>a).|(?<x>x)/d;
const result = re.exec("ab").indices;
assert.compareArray([0, 1], result.groups.a);
assert.sameValue(undefined, result.groups.x);

View File

@ -7,12 +7,12 @@ includes: [propertyHelper.js, compareArray.js]
esid: sec-makeindicesarray
features: [regexp-named-groups, regexp-match-indices]
info: |
MakeIndicesArray ( S, indices, groupNames )
8. If _groupNames_ is not *undefined*, then
MakeIndicesArray ( S, indices, groupNames, hasIndices )
10. If _hasIndices_ is *true*, then
a. Let _groups_ be ! ObjectCreate(*null*).
9. Else,
11. Else,
a. Let _groups_ be *undefined*.
10. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_).
12. Perform ! CreateDataProperty(_A_, `"groups"`, _groups_).
---*/
// `groups` is created with Define, not Set.
@ -21,7 +21,7 @@ Object.defineProperty(Array.prototype, "groups", {
set() { counter++; }
});
let indices = /(?<x>.)/.exec("a").indices;
let indices = /(?<x>.)/d.exec("a").indices;
assert.sameValue(counter, 0);
// `groups` is writable, enumerable and configurable
@ -34,6 +34,6 @@ verifyProperty(indices, 'groups', {
// The `__proto__` property on the groups object is not special,
// and does not affect the [[Prototype]] of the resulting groups object.
let {groups} = /(?<__proto__>.)/.exec("a").indices;
let {groups} = /(?<__proto__>.)/d.exec("a").indices;
assert.compareArray([0, 1], groups.__proto__);
assert.sameValue(null, Object.getPrototypeOf(groups));

View File

@ -7,22 +7,22 @@ includes: [compareArray.js, propertyHelper.js]
esid: sec-makeindicesarray
features: [regexp-named-groups, regexp-match-indices]
info: |
MakeIndicesArray ( S, indices, groupNames )
11. For each integer _i_ such that _i_ >= 0 and _i_ < _n_, do
e. If _groupNames_ is not *undfined* and _groupNames_[_i_] is not *undefined*, then
i. Perform ! CreateDataProperty(_groups_, _groupNames_[_i_], _matchIndicesArray_).
MakeIndicesArray ( S, indices, groupNames, hasIndices )
13. For each integer _i_ such that _i_ >= 0 and _i_ < _n_, do
e. If _i_ > 0 and _groupNames_[_i_ - 1] is not *undefined*, then
i. Perform ! CreateDataProperty(_groups_, _groupNames_[_i_ - 1], _matchIndicesArray_).
---*/
// Properties created on result.groups in textual order.
let groupNames = Object.getOwnPropertyNames(/(?<fst>.)|(?<snd>.)/u.exec("abcd").indices.groups);
let groupNames = Object.getOwnPropertyNames(/(?<fst>.)|(?<snd>.)/du.exec("abcd").indices.groups);
assert.compareArray(groupNames, ["fst", "snd"]);
// // Properties are created with Define, not Set
// let counter = 0;
// Object.defineProperty(Object.prototype, 'x', {set() { counter++; }});
let indices = /(?<x>.)/.exec('a').indices;
let indices = /(?<x>.)/d.exec('a').indices;
let groups = indices.groups;
// assert.sameValue(counter, 0);

View File

@ -8,8 +8,11 @@ esid: sec-regexpbuiltinexec
features: [regexp-match-indices]
info: |
Runtime Semantics: RegExpBuiltinExec ( R, S )
34. Let _indicesArray_ be MakeIndicesArray(_S_, _indices_, _groupNames_).
35. Perform ! DefinePropertyOrThrow(_A_, `"indices"`, PropertyDescriptor { [[Value]]: _indicesArray_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }).
8. If _flags_ contains `"d"`, let _hasIndices_ be *true*, else let _hasIndices_ be *false*.
...
36. If _hasIndices_ is *true*, then
a. Let _indicesArray_ be MakeIndicesArray(_S_, _indices_, _groupNames_, _hasGroups_).
b. Perform ! CreateDataProperty(_A_, `"indices"`, _indicesArray_).
---*/
// `indices` is created with Define, not Set.
@ -18,7 +21,7 @@ Object.defineProperty(Array.prototype, "indices", {
set() { counter++; }
});
let match = /a/.exec("a");
let match = /a/d.exec("a");
assert.sameValue(counter, 0);
// `indices` is a non-writable, non-enumerable, and configurable data-property.

View File

@ -0,0 +1,19 @@
// Copyright 2019 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: The "indices" property is an Array.
esid: sec-regexpbuiltinexec
features: [regexp-match-indices]
info: |
RegExpBuiltinExec ( R, S )
8. If _flags_ contains `"d"`, let _hasIndices_ be *true*, else let _hasIndices_ be *false*.
36. If _hasIndices_ is *true*, then
b. Perform ! CreateDataProperty(_A_, `"indices"`, _indicesArray_).
---*/
let match = /a/.exec("a");
// `indices` is not defined by default
assert(!match.hasOwnProperty("indices"));

View File

@ -0,0 +1,45 @@
// Copyright (C) 2021 Ron Buckton and Aleksey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.flags
description: Boolean coercion of the hasIndices property
info: |
get RegExp.prototype.flags
...
10. Let hasIndices be ToBoolean(? Get(R, "hasIndices")).
...
features: [Symbol, regexp-match-indices]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get;
var r = {};
r.hasIndices = undefined;
assert.sameValue(get.call(r), "", "hasIndices: undefined");
r.hasIndices = null;
assert.sameValue(get.call(r), "", "hasIndices: null");
r.hasIndices = NaN;
assert.sameValue(get.call(r), "", "hasIndices: NaN");
r.hasIndices = "";
assert.sameValue(get.call(r), "", "hasIndices: the empty string");
r.hasIndices = "string";
assert.sameValue(get.call(r), "s", "hasIndices: string");
r.hasIndices = 86;
assert.sameValue(get.call(r), "s", "hasIndices: 86");
r.hasIndices = Symbol();
assert.sameValue(get.call(r), "s", "hasIndices: Symbol()");
r.hasIndices = [];
assert.sameValue(get.call(r), "s", "hasIndices: []");
r.hasIndices = {};
assert.sameValue(get.call(r), "s", "hasIndices: {}");

View File

@ -8,17 +8,21 @@ info: |
get RegExp.prototype.flags
[...]
4. Let global be ToBoolean(? Get(R, "global")).
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
8. Let multiline be ToBoolean(? Get(R, "multiline")).
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
12. Let unicode be ToBoolean(? Get(R, "unicode")).
14. Let sticky be ToBoolean(? Get(R, "sticky")).
features: [regexp-dotall]
4. let hasIndices be ToBoolean(? Get(R, "hasIndices"))
6. Let global be ToBoolean(? Get(R, "global")).
8. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
10. Let multiline be ToBoolean(? Get(R, "multiline")).
12. Let dotAll be ToBoolean(? Get(R, "dotAll")).
14. Let unicode be ToBoolean(? Get(R, "unicode")).
18. Let sticky be ToBoolean(? Get(R, "sticky")).
features: [regexp-dotall, regexp-match-indices]
---*/
var calls = '';
var re = {
get hasIndices() {
calls += 'd';
},
get global() {
calls += 'g';
},
@ -42,4 +46,4 @@ var re = {
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
get.call(re);
assert.sameValue(calls, 'gimsuy');
assert.sameValue(calls, 'dgimsuy');

View File

@ -8,17 +8,26 @@ info: |
get RegExp.prototype.flags
[...]
4. Let global be ToBoolean(? Get(R, "global")).
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
8. Let multiline be ToBoolean(? Get(R, "multiline")).
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
12. Let unicode be ToBoolean(? Get(R, "unicode")).
14. Let sticky be ToBoolean(? Get(R, "sticky")).
features: [regexp-dotall]
4. let hasIndices be ToBoolean(? Get(R, "hasIndices"))
6. Let global be ToBoolean(? Get(R, "global")).
8. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
10. Let multiline be ToBoolean(? Get(R, "multiline")).
12. Let dotAll be ToBoolean(? Get(R, "dotAll")).
14. Let unicode be ToBoolean(? Get(R, "unicode")).
18. Let sticky be ToBoolean(? Get(R, "sticky")).
features: [regexp-dotall, regexp-match-indices]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get;
assert.throws(Test262Error, function() {
get.call({
get hasIndices() {
throw new Test262Error();
},
});
}, 'Let hasIndices be ToBoolean(? Get(R, "hasIndices"))');
assert.throws(Test262Error, function() {
get.call({
get global() {

View File

@ -8,18 +8,20 @@ description: >
info: |
4. Let global be ToBoolean(? Get(R, "global")).
5. If global is true, append "g" as the last code unit of result.
6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
7. If ignoreCase is true, append "i" as the last code unit of result.
8. Let multiline be ToBoolean(? Get(R, "multiline")).
9. If multiline is true, append "m" as the last code unit of result.
10. Let dotAll be ToBoolean(? Get(R, "dotAll")).
11. If dotAll is true, append "s" as the last code unit of result.
12. Let unicode be ToBoolean(? Get(R, "unicode")).
13. If unicode is true, append "u" as the last code unit of result.
14. Let sticky be ToBoolean(? Get(R, "sticky")).
15. If sticky is true, append "y" as the last code unit of result.
features: [regexp-dotall]
6. Let global be ToBoolean(? Get(R, "global")).
7. If global is true, append "g" as the last code unit of result.
8. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")).
9. If ignoreCase is true, append "i" as the last code unit of result.
10. Let multiline be ToBoolean(? Get(R, "multiline")).
11. If multiline is true, append "m" as the last code unit of result.
12. Let dotAll be ToBoolean(? Get(R, "dotAll")).
13. If dotAll is true, append "s" as the last code unit of result.
14. Let unicode be ToBoolean(? Get(R, "unicode")).
15. If unicode is true, append "u" as the last code unit of result.
16. Let sticky be ToBoolean(? Get(R, "sticky")).
17. If sticky is true, append "y" as the last code unit of result.
features: [regexp-dotall, regexp-match-indices]
---*/
assert.sameValue(new RegExp("", "gimsuy").flags, "gimsuy", "gimsuy => gimsuy");
assert.sameValue(new RegExp("", "yusmig").flags, "gimsuy", "yusmig => gimsuy");
assert.sameValue(new RegExp("", "dgimsuy").flags, "dgimsuy", "dgimsuy => dgimsuy");
assert.sameValue(new RegExp("", "yusmigd").flags, "dgimsuy", "yusmigd => dgimsuy");

View File

@ -20,7 +20,7 @@ info: |
14. Let sticky be ToBoolean(? Get(R, "sticky")).
15. If sticky is true, append "y" as the last code unit of result.
16. Return result.
features: [regexp-dotall]
features: [regexp-dotall, regexp-match-indices]
---*/
assert.sameValue(/./.flags, '', 'no flags');
@ -30,3 +30,4 @@ assert.sameValue(/./m.flags, 'm', 'multiline');
assert.sameValue(/./s.flags, 's', 'dotAll');
assert.sameValue(/./u.flags, 'u', 'unicode');
assert.sameValue(/./y.flags, 'y', 'sticky');
assert.sameValue(/./d.flags, 'd', 'hasIndices');

View File

@ -0,0 +1,29 @@
// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.hasindices
description: Invoked on a cross-realm object
info: |
get RegExp.prototype.hasIndices
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
b. Otherwise, throw a TypeError exception.
features: [regexp-match-indices, cross-realm]
---*/
var dotAll = Object.getOwnPropertyDescriptor(RegExp.prototype, 'hasIndices').get;
var other = $262.createRealm().global;
var otherRegExpProto = other.RegExp.prototype;
var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'hasIndices').get;
assert.throws(TypeError, function() {
hasIndices.call(otherRegExpProto);
}, 'cross-realm RegExp.prototype');
assert.throws(other.TypeError, function() {
otherRegExpGetter.call(RegExp.prototype);
}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype');

View File

@ -0,0 +1,34 @@
// Copyright (C) 2021 Ron Buckton and André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.hasindices
description: >
get RegExp.prototype.hasIndices.length is 0.
info: |
get RegExp.prototype.hasIndices
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
features: [regexp-match-indices]
---*/
var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices");
assert.sameValue(desc.get.length, 0);
verifyProperty(desc.get, "length", {
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -0,0 +1,27 @@
// Copyright (C) 20201 Ron buckton and the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.hasindices
description: >
RegExp.prototype.hasIndices name
info: |
17 ECMAScript Standard Built-in Objects
Functions that are specified as get or set accessor functions of built-in
properties have "get " or "set " prepended to the property name string.
includes: [propertyHelper.js]
features: [regexp-match-indices]
---*/
var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices");
assert.sameValue(
desc.get.name,
"get hasIndices"
);
verifyProperty(desc.get, "name", {
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2017 Ron Buckton and the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.hasIndices
description: >
`pending` property descriptor
info: |
RegExp.prototype.hasIndices is an accessor property whose set accessor
function is undefined.
17 ECMAScript Standard Built-in Objects
Every accessor property described in clauses 18 through 26 and in Annex B.2 has the attributes
{ [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. If only a get
accessor function is described, the set accessor function is the default value, undefined. If
only a set accessor is described the get accessor is the default value, undefined.
includes: [propertyHelper.js]
features: [regexp-match-indices]
---*/
var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices");
assert.sameValue(desc.set, undefined);
assert.sameValue(typeof desc.get, "function");
verifyProperty(RegExp.prototype, "hasIndices", {
enumerable: false,
configurable: true,
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.hasindices
description: Invoked on an object without an [[OriginalFlags]] internal slot
info: |
get RegExp.prototype.hasIndices
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
b. Otherwise, throw a TypeError exception.
features: [regexp-match-indices]
---*/
var hasIndices = Object.getOwnPropertyDescriptor(RegExp.prototype, 'hasIndices').get;
assert.throws(TypeError, function() {
hasIndices.call({});
}, 'ordinary object');
assert.throws(TypeError, function() {
hasIndices.call([]);
}, 'array exotic object');
assert.throws(TypeError, function() {
hasIndices.call(arguments);
}, 'arguments object');

View File

@ -0,0 +1,40 @@
// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.hasindices
description: >
`hasIndices` accessor invoked on a non-object value
info: |
get RegExp.prototype.hasIndices
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
features: [Symbol, regexp-match-indices]
---*/
var hasIndices = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices").get;
assert.throws(TypeError, function() {
hasIndices.call(undefined);
}, "undefined");
assert.throws(TypeError, function() {
hasIndices.call(null);
}, "null");
assert.throws(TypeError, function() {
hasIndices.call(true);
}, "true");
assert.throws(TypeError, function() {
hasIndices.call("string");
}, "string");
assert.throws(TypeError, function() {
hasIndices.call(Symbol("s"));
}, "symbol");
assert.throws(TypeError, function() {
hasIndices.call(4);
}, "number");

View File

@ -0,0 +1,19 @@
// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.hasIndices
description: >
Return value of `undefined` when the "this" value is the RegExp prototype
object
info: |
1. Let R be the this value.
2. If Type(R) is not Object, throw a TypeError exception.
3. If R does not have an [[OriginalFlags]] internal slot, then
a. If SameValue(R, %RegExpPrototype%) is true, return undefined.
features: [regexp-match-indices]
---*/
var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices").get;
assert.sameValue(get.call(RegExp.prototype), undefined);

View File

@ -0,0 +1,47 @@
// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-regexp.prototype.hasindices
description: >
`hasIndices` accessor function invoked on a RegExp instance
info: |
21.2.5.12 get RegExp.prototype.hasIndices
4. Let flags be the value of Rs [[OriginalFlags]] internal slot.
5. If flags contains the code unit "s", return true.
6. Return false.
features: [regexp-match-indices]
---*/
assert.sameValue(/./.hasIndices, false, "/./.hasIndices");
assert.sameValue(/./i.hasIndices, false, "/./i.hasIndices");
assert.sameValue(/./g.hasIndices, false, "/./g.hasIndices");
assert.sameValue(/./y.hasIndices, false, "/./y.hasIndices");
assert.sameValue(/./m.hasIndices, false, "/./m.hasIndices");
assert.sameValue(/./s.hasIndices, false, "/./s.hasIndices");
assert.sameValue(/./u.hasIndices, false, "/./u.hasIndices");
assert.sameValue(/./d.hasIndices, true, "/./d.hasIndices");
assert.sameValue(/./di.hasIndices, true, "/./di.hasIndices");
assert.sameValue(/./dg.hasIndices, true, "/./dg.hasIndices");
assert.sameValue(/./dy.hasIndices, true, "/./dy.hasIndices");
assert.sameValue(/./dm.hasIndices, true, "/./dm.hasIndices");
assert.sameValue(/./ds.hasIndices, true, "/./ds.hasIndices");
assert.sameValue(/./du.hasIndices, true, "/./du.hasIndices");
assert.sameValue(new RegExp(".", "").hasIndices, false, "new RegExp('.', '').hasIndices");
assert.sameValue(new RegExp(".", "i").hasIndices, false, "new RegExp('.', 'i').hasIndices");
assert.sameValue(new RegExp(".", "g").hasIndices, false, "new RegExp('.', 'g').hasIndices");
assert.sameValue(new RegExp(".", "y").hasIndices, false, "new RegExp('.', 'y').hasIndices");
assert.sameValue(new RegExp(".", "m").hasIndices, false, "new RegExp('.', 'm').hasIndices");
assert.sameValue(new RegExp(".", "s").hasIndices, false, "new RegExp('.', 's').hasIndices");
assert.sameValue(new RegExp(".", "u").hasIndices, false, "new RegExp('.', 'u').hasIndices");
assert.sameValue(new RegExp(".", "d").hasIndices, true, "new RegExp('.', 'd').hasIndices");
assert.sameValue(new RegExp(".", "di").hasIndices, true, "new RegExp('.', 'di').hasIndices");
assert.sameValue(new RegExp(".", "dg").hasIndices, true, "new RegExp('.', 'dg').hasIndices");
assert.sameValue(new RegExp(".", "dy").hasIndices, true, "new RegExp('.', 'dy').hasIndices");
assert.sameValue(new RegExp(".", "dm").hasIndices, true, "new RegExp('.', 'dm').hasIndices");
assert.sameValue(new RegExp(".", "ds").hasIndices, true, "new RegExp('.', 'ds').hasIndices");
assert.sameValue(new RegExp(".", "du").hasIndices, true, "new RegExp('.', 'du').hasIndices");