From a567e4c8195c31166ef01af478be018207c12d4b Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 14 Jan 2021 23:06:42 -0800 Subject: [PATCH] Updates to regexp-match-indices tests based on d-flag --- test/built-ins/RegExp/duplicate-flags.js | 5 +- .../match-indices/indices-array-element.js | 2 +- .../match-indices/indices-array-matched.js | 8 ++-- .../indices-array-non-unicode-match.js | 42 +++++++++-------- .../match-indices/indices-array-properties.js | 6 +-- .../indices-array-unicode-match.js | 45 +++++++++--------- .../indices-array-unicode-property-names.js | 20 ++++---- .../match-indices/indices-array-unmatched.js | 2 +- .../RegExp/match-indices/indices-array.js | 4 +- .../indices-groups-object-undefined.js | 10 ++-- .../indices-groups-object-unmatched.js | 8 ++-- .../match-indices/indices-groups-object.js | 12 ++--- .../indices-groups-properties.js | 12 ++--- .../RegExp/match-indices/indices-property.js | 9 ++-- .../match-indices/no-indices-array copy.js | 19 ++++++++ .../prototype/flags/coercion-hasIndices.js | 45 ++++++++++++++++++ .../RegExp/prototype/flags/get-order.js | 20 ++++---- .../RegExp/prototype/flags/rethrow.js | 23 ++++++--- .../RegExp/prototype/flags/return-order.js | 28 ++++++----- .../RegExp/prototype/flags/this-val-regexp.js | 3 +- .../prototype/hasIndices/cross-realm.js | 29 ++++++++++++ .../RegExp/prototype/hasIndices/length.js | 34 ++++++++++++++ .../RegExp/prototype/hasIndices/name.js | 27 +++++++++++ .../RegExp/prototype/hasIndices/prop-desc.js | 29 ++++++++++++ .../hasIndices/this-val-invalid-obj.js | 30 ++++++++++++ .../prototype/hasIndices/this-val-non-obj.js | 40 ++++++++++++++++ .../hasIndices/this-val-regexp-prototype.js | 19 ++++++++ .../prototype/hasIndices/this-val-regexp.js | 47 +++++++++++++++++++ 28 files changed, 463 insertions(+), 115 deletions(-) create mode 100644 test/built-ins/RegExp/match-indices/no-indices-array copy.js create mode 100644 test/built-ins/RegExp/prototype/flags/coercion-hasIndices.js create mode 100644 test/built-ins/RegExp/prototype/hasIndices/cross-realm.js create mode 100644 test/built-ins/RegExp/prototype/hasIndices/length.js create mode 100644 test/built-ins/RegExp/prototype/hasIndices/name.js create mode 100644 test/built-ins/RegExp/prototype/hasIndices/prop-desc.js create mode 100644 test/built-ins/RegExp/prototype/hasIndices/this-val-invalid-obj.js create mode 100644 test/built-ins/RegExp/prototype/hasIndices/this-val-non-obj.js create mode 100644 test/built-ins/RegExp/prototype/hasIndices/this-val-regexp-prototype.js create mode 100644 test/built-ins/RegExp/prototype/hasIndices/this-val-regexp.js diff --git a/test/built-ins/RegExp/duplicate-flags.js b/test/built-ins/RegExp/duplicate-flags.js index 0339f83f26..bd646123d3 100644 --- a/test/built-ins/RegExp/duplicate-flags.js +++ b/test/built-ins/RegExp/duplicate-flags.js @@ -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"); diff --git a/test/built-ins/RegExp/match-indices/indices-array-element.js b/test/built-ins/RegExp/match-indices/indices-array-element.js index e303e9ca16..2a7550609d 100644 --- a/test/built-ins/RegExp/match-indices/indices-array-element.js +++ b/test/built-ins/RegExp/match-indices/indices-array-element.js @@ -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 diff --git a/test/built-ins/RegExp/match-indices/indices-array-matched.js b/test/built-ins/RegExp/match-indices/indices-array-matched.js index 4361bcd569..1b0b70cea0 100644 --- a/test/built-ins/RegExp/match-indices/indices-array-matched.js +++ b/test/built-ins/RegExp/match-indices/indices-array-matched.js @@ -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 diff --git a/test/built-ins/RegExp/match-indices/indices-array-non-unicode-match.js b/test/built-ins/RegExp/match-indices/indices-array-non-unicode-match.js index 82baeab2ed..da762077c6 100644 --- a/test/built-ins/RegExp/match-indices/indices-array-non-unicode-match.js +++ b/test/built-ins/RegExp/match-indices/indices-array-non-unicode-match.js @@ -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 = /(?.)(?.)(?.)\k\k\k/.exec("abccba").indices.groups; +let groups = /(?.)(?.)(?.)\k\k\k/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(/(?.)/).indices.groups.a, 'Indices for non-unicode match against "𝐁" in groups.a (without /u flag)'); -assert.compareArray([0, 1], "\u{1d401}".match(/(?.)/).indices.groups.a, 'Indices for non-unicode match against "\\u{1d401}" in groups.a (without /u flag)'); -assert.compareArray([0, 1], "\uD835\uDC01".match(/(?.)/).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(/(?.)/d).indices.groups.a, 'Indices for non-unicode match against "𝐁" in groups.a (without /u flag)'); +assert.compareArray([0, 1], "\u{1d401}".match(/(?.)/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(/(?.)/d).indices.groups.a, 'Indices for non-unicode match against "\\ud835\\udc01" in groups.a (without /u flag)'); diff --git a/test/built-ins/RegExp/match-indices/indices-array-properties.js b/test/built-ins/RegExp/match-indices/indices-array-properties.js index 5c1e78b01c..7f1c07cb6c 100644 --- a/test/built-ins/RegExp/match-indices/indices-array-properties.js +++ b/test/built-ins/RegExp/match-indices/indices-array-properties.js @@ -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', { diff --git a/test/built-ins/RegExp/match-indices/indices-array-unicode-match.js b/test/built-ins/RegExp/match-indices/indices-array-unicode-match.js index a6ff6df3e9..078cf4d5a2 100644 --- a/test/built-ins/RegExp/match-indices/indices-array-unicode-match.js +++ b/test/built-ins/RegExp/match-indices/indices-array-unicode-match.js @@ -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 = /(?.)(?.)(?.)\k\k\k/u.exec("abccba").indices.groups; +let groups = /(?.)(?.)(?.)\k\k\k/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(/(?.)/u).indices.groups.a, 'Indices for unicode match against 𝐁 in groups.a (with /u flag)'); -assert.compareArray([0, 2], "\u{1d401}".match(/(?.)/u).indices.groups.a, 'Indices for unicode match against \\u{1d401} in groups.a (with /u flag)'); -assert.compareArray([0, 2], "\uD835\uDC01".match(/(?.)/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(/(?.)/du).indices.groups.a, 'Indices for unicode match against 𝐁 in groups.a (with /du flag)'); +assert.compareArray([0, 2], "\u{1d401}".match(/(?.)/du).indices.groups.a, 'Indices for unicode match against \\u{1d401} in groups.a (with /du flag)'); +assert.compareArray([0, 2], "\uD835\uDC01".match(/(?.)/du).indices.groups.a, 'Indices for unicode match against \\ud835\\udc01 in groups.a (with /du flag)'); diff --git a/test/built-ins/RegExp/match-indices/indices-array-unicode-property-names.js b/test/built-ins/RegExp/match-indices/indices-array-unicode-property-names.js index 04f3afb315..2daa3f490c 100644 --- a/test/built-ins/RegExp/match-indices/indices-array-unicode-property-names.js +++ b/test/built-ins/RegExp/match-indices/indices-array-unicode-property-names.js @@ -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.ΰ² _ΰ² ); diff --git a/test/built-ins/RegExp/match-indices/indices-array-unmatched.js b/test/built-ins/RegExp/match-indices/indices-array-unmatched.js index 4c8888fe21..2905a8c853 100644 --- a/test/built-ins/RegExp/match-indices/indices-array-unmatched.js +++ b/test/built-ins/RegExp/match-indices/indices-array-unmatched.js @@ -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 diff --git a/test/built-ins/RegExp/match-indices/indices-array.js b/test/built-ins/RegExp/match-indices/indices-array.js index 7288dd19b5..3d0a436b04 100644 --- a/test/built-ins/RegExp/match-indices/indices-array.js +++ b/test/built-ins/RegExp/match-indices/indices-array.js @@ -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 diff --git a/test/built-ins/RegExp/match-indices/indices-groups-object-undefined.js b/test/built-ins/RegExp/match-indices/indices-groups-object-undefined.js index 816edcd23b..6f3329185a 100644 --- a/test/built-ins/RegExp/match-indices/indices-groups-object-undefined.js +++ b/test/built-ins/RegExp/match-indices/indices-groups-object-undefined.js @@ -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, diff --git a/test/built-ins/RegExp/match-indices/indices-groups-object-unmatched.js b/test/built-ins/RegExp/match-indices/indices-groups-object-unmatched.js index d34ef4020b..cf8ff5bb8e 100644 --- a/test/built-ins/RegExp/match-indices/indices-groups-object-unmatched.js +++ b/test/built-ins/RegExp/match-indices/indices-groups-object-unmatched.js @@ -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).|(?x)/; +const re = /(?a).|(?x)/d; const result = re.exec("ab").indices; assert.compareArray([0, 1], result.groups.a); assert.sameValue(undefined, result.groups.x); diff --git a/test/built-ins/RegExp/match-indices/indices-groups-object.js b/test/built-ins/RegExp/match-indices/indices-groups-object.js index e40412daf7..d5071024bd 100644 --- a/test/built-ins/RegExp/match-indices/indices-groups-object.js +++ b/test/built-ins/RegExp/match-indices/indices-groups-object.js @@ -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 = /(?.)/.exec("a").indices; +let indices = /(?.)/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)); diff --git a/test/built-ins/RegExp/match-indices/indices-groups-properties.js b/test/built-ins/RegExp/match-indices/indices-groups-properties.js index f942195d9c..668fbb5199 100644 --- a/test/built-ins/RegExp/match-indices/indices-groups-properties.js +++ b/test/built-ins/RegExp/match-indices/indices-groups-properties.js @@ -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(/(?.)|(?.)/u.exec("abcd").indices.groups); +let groupNames = Object.getOwnPropertyNames(/(?.)|(?.)/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 = /(?.)/.exec('a').indices; +let indices = /(?.)/d.exec('a').indices; let groups = indices.groups; // assert.sameValue(counter, 0); diff --git a/test/built-ins/RegExp/match-indices/indices-property.js b/test/built-ins/RegExp/match-indices/indices-property.js index 492fc18adf..fcbd8afe4a 100644 --- a/test/built-ins/RegExp/match-indices/indices-property.js +++ b/test/built-ins/RegExp/match-indices/indices-property.js @@ -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. diff --git a/test/built-ins/RegExp/match-indices/no-indices-array copy.js b/test/built-ins/RegExp/match-indices/no-indices-array copy.js new file mode 100644 index 0000000000..a9664a3916 --- /dev/null +++ b/test/built-ins/RegExp/match-indices/no-indices-array copy.js @@ -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")); diff --git a/test/built-ins/RegExp/prototype/flags/coercion-hasIndices.js b/test/built-ins/RegExp/prototype/flags/coercion-hasIndices.js new file mode 100644 index 0000000000..578a2aff83 --- /dev/null +++ b/test/built-ins/RegExp/prototype/flags/coercion-hasIndices.js @@ -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: {}"); diff --git a/test/built-ins/RegExp/prototype/flags/get-order.js b/test/built-ins/RegExp/prototype/flags/get-order.js index 79c72f558a..7742c347c0 100644 --- a/test/built-ins/RegExp/prototype/flags/get-order.js +++ b/test/built-ins/RegExp/prototype/flags/get-order.js @@ -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'); diff --git a/test/built-ins/RegExp/prototype/flags/rethrow.js b/test/built-ins/RegExp/prototype/flags/rethrow.js index 2ca1e9d1e8..8086a7484f 100644 --- a/test/built-ins/RegExp/prototype/flags/rethrow.js +++ b/test/built-ins/RegExp/prototype/flags/rethrow.js @@ -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() { diff --git a/test/built-ins/RegExp/prototype/flags/return-order.js b/test/built-ins/RegExp/prototype/flags/return-order.js index c24394cb8a..b0d10c2694 100644 --- a/test/built-ins/RegExp/prototype/flags/return-order.js +++ b/test/built-ins/RegExp/prototype/flags/return-order.js @@ -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"); diff --git a/test/built-ins/RegExp/prototype/flags/this-val-regexp.js b/test/built-ins/RegExp/prototype/flags/this-val-regexp.js index 17747abb72..4f7741726f 100644 --- a/test/built-ins/RegExp/prototype/flags/this-val-regexp.js +++ b/test/built-ins/RegExp/prototype/flags/this-val-regexp.js @@ -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'); diff --git a/test/built-ins/RegExp/prototype/hasIndices/cross-realm.js b/test/built-ins/RegExp/prototype/hasIndices/cross-realm.js new file mode 100644 index 0000000000..2e0771f351 --- /dev/null +++ b/test/built-ins/RegExp/prototype/hasIndices/cross-realm.js @@ -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'); diff --git a/test/built-ins/RegExp/prototype/hasIndices/length.js b/test/built-ins/RegExp/prototype/hasIndices/length.js new file mode 100644 index 0000000000..8fe5f7f1de --- /dev/null +++ b/test/built-ins/RegExp/prototype/hasIndices/length.js @@ -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, +}); diff --git a/test/built-ins/RegExp/prototype/hasIndices/name.js b/test/built-ins/RegExp/prototype/hasIndices/name.js new file mode 100644 index 0000000000..3a3e4f161e --- /dev/null +++ b/test/built-ins/RegExp/prototype/hasIndices/name.js @@ -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, +}); diff --git a/test/built-ins/RegExp/prototype/hasIndices/prop-desc.js b/test/built-ins/RegExp/prototype/hasIndices/prop-desc.js new file mode 100644 index 0000000000..ec049f099e --- /dev/null +++ b/test/built-ins/RegExp/prototype/hasIndices/prop-desc.js @@ -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, +}); diff --git a/test/built-ins/RegExp/prototype/hasIndices/this-val-invalid-obj.js b/test/built-ins/RegExp/prototype/hasIndices/this-val-invalid-obj.js new file mode 100644 index 0000000000..ac5b596a66 --- /dev/null +++ b/test/built-ins/RegExp/prototype/hasIndices/this-val-invalid-obj.js @@ -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'); diff --git a/test/built-ins/RegExp/prototype/hasIndices/this-val-non-obj.js b/test/built-ins/RegExp/prototype/hasIndices/this-val-non-obj.js new file mode 100644 index 0000000000..325c9ca4aa --- /dev/null +++ b/test/built-ins/RegExp/prototype/hasIndices/this-val-non-obj.js @@ -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"); diff --git a/test/built-ins/RegExp/prototype/hasIndices/this-val-regexp-prototype.js b/test/built-ins/RegExp/prototype/hasIndices/this-val-regexp-prototype.js new file mode 100644 index 0000000000..65bce1d502 --- /dev/null +++ b/test/built-ins/RegExp/prototype/hasIndices/this-val-regexp-prototype.js @@ -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); diff --git a/test/built-ins/RegExp/prototype/hasIndices/this-val-regexp.js b/test/built-ins/RegExp/prototype/hasIndices/this-val-regexp.js new file mode 100644 index 0000000000..d30cd991e6 --- /dev/null +++ b/test/built-ins/RegExp/prototype/hasIndices/this-val-regexp.js @@ -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 R’s [[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");