diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/matchAll')
22 files changed, 782 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/browser.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/flags-nonglobal-throws.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/flags-nonglobal-throws.js new file mode 100644 index 0000000000..c134e85870 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/flags-nonglobal-throws.js @@ -0,0 +1,44 @@ +// Copyright (C) 2019 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Re-throws errors when calling @@matchAll +info: | + String.prototype.matchAll ( regexp ) + [...] + 2. If _regexp_ is neither *undefined* nor *null*, then + 1. Let _isRegExp_ be ? IsRegExp(_regexp_). + 1. If _isRegExp_ is true, then + 1. Let _flags_ be ? Get(_regexp_, *"flags"*). + 1. Perform ? RequireObjectCoercible(_flags_). + 1. If ? ToString(_flags_) does not contain *"g"*, throw a *TypeError* exception. +features: [Symbol.matchAll] +---*/ + + +assert.throws(TypeError, function () { + ''.matchAll(/a/); +}); +assert.throws(TypeError, function () { + ''.matchAll(/a/i); +}); +assert.throws(TypeError, function () { + ''.matchAll(/a/m); +}); +assert.throws(TypeError, function () { + ''.matchAll(/a/u); +}); +assert.throws(TypeError, function () { + ''.matchAll(/a/y); +}); + +var regex = /a/; +Object.defineProperty(regex, 'flags', { + value: 'muyi' +}); + +assert.throws(TypeError, function () { + ''.matchAll(regex); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/flags-undefined-throws.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/flags-undefined-throws.js new file mode 100644 index 0000000000..9c6928c719 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/flags-undefined-throws.js @@ -0,0 +1,35 @@ +// Copyright (C) 2019 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Re-throws errors when calling @@matchAll +info: | + String.prototype.matchAll ( regexp ) + [...] + 2. If _regexp_ is neither *undefined* nor *null*, then + 1. Let _isRegExp_ be ? IsRegExp(_regexp_). + 1. If _isRegExp_ is true, then + 1. Let _flags_ be ? Get(_regexp_, *"flags"*). + 1. Perform ? RequireObjectCoercible(_flags_). + 1. If ? ToString(_flags_) does not contain *"g"*, throw a *TypeError* exception. +features: [Symbol.matchAll] +---*/ + +var regex = /a/g; +Object.defineProperty(regex, 'flags', { value: undefined }); + +assert.throws(TypeError, function () { + ''.matchAll(regex); +}); + +Object.defineProperty(RegExp.prototype, 'flags', { + get: function () { + return undefined; + } +}); + +assert.throws(TypeError, function () { + ''.matchAll(/a/g); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/length.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/length.js new file mode 100644 index 0000000000..49fc24912e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: String.prototype.matchAll `length` property +info: | + 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. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are 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: [String.prototype.matchAll] +---*/ + +assert.sameValue(String.prototype.matchAll.length, 1); + +verifyNotEnumerable(String.prototype.matchAll, 'length'); +verifyNotWritable(String.prototype.matchAll, 'length'); +verifyConfigurable(String.prototype.matchAll, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/name.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/name.js new file mode 100644 index 0000000000..efab01207f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/name.js @@ -0,0 +1,30 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: String.prototype.matchAll `name` property +info: | + 17 ECMAScript Standard Built-in Objects: + + [...] + + Every built-in function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + [...] + + Unless otherwise specified, the name property of a built-in function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [String.prototype.matchAll] +---*/ + +assert.sameValue(String.prototype.matchAll.name, 'matchAll'); + +verifyNotEnumerable(String.prototype.matchAll, 'name'); +verifyNotWritable(String.prototype.matchAll, 'name'); +verifyConfigurable(String.prototype.matchAll, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/not-a-constructor.js new file mode 100644 index 0000000000..e4a6ba973c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.matchAll does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, String.prototype.matchAll, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.matchAll), + false, + 'isConstructor(String.prototype.matchAll) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.matchAll(); +}, '`new String.prototype.matchAll()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/prop-desc.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/prop-desc.js new file mode 100644 index 0000000000..4354fc6ae6 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/prop-desc.js @@ -0,0 +1,24 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: String.prototype.matchAll property descriptor +info: | + 17 ECMAScript Standard Built-in Objects: + + [...] + + Every other data property described in clauses 18 through 26 and in Annex + B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [String.prototype.matchAll] +---*/ + +assert.sameValue(typeof String.prototype.matchAll, 'function'); + +verifyNotEnumerable(String.prototype, 'matchAll'); +verifyWritable(String.prototype, 'matchAll'); +verifyConfigurable(String.prototype, 'matchAll'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-get-matchAll-throws.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-get-matchAll-throws.js new file mode 100644 index 0000000000..ebab7328b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-get-matchAll-throws.js @@ -0,0 +1,27 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Re-throws errors when calling @@matchAll +info: | + String.prototype.matchAll ( regexp ) + [...] + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). + b. If matcher is not undefined, then + i. Return ? Call(matcher, regexp, « O »). +features: [Symbol.matchAll, String.prototype.matchAll] +---*/ + +var regexp = /./g; +Object.defineProperty(regexp, Symbol.matchAll, { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + ''.matchAll(regexp); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-is-null.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-is-null.js new file mode 100644 index 0000000000..0244014e4c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-is-null.js @@ -0,0 +1,24 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Behavior when regexp is null +info: | + String.prototype.matchAll ( regexp ) + 1. Let O be ? RequireObjectCoercible(this value). + 2. If regexp is neither undefined nor null, then + [...] + 3. Let S be ? ToString(O). + 4. Let rx be ? RegExpCreate(R, "g"). + 5. Return ? Invoke(rx, @@matchAll, « S »). +features: [String.prototype.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var str = '-null-'; + +assert.compareIterator(str.matchAll(null), [ + matchValidator(['null'], 1, str) +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-is-undefined-or-null-invokes-matchAll.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-is-undefined-or-null-invokes-matchAll.js new file mode 100644 index 0000000000..17a08e3282 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-is-undefined-or-null-invokes-matchAll.js @@ -0,0 +1,31 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Behavior when regexp is null or undefined +info: | + String.prototype.matchAll ( regexp ) + 1. Let O be ? RequireObjectCoercible(this value). + 2. If regexp is neither undefined nor null, then + [...] + 3. Let S be ? ToString(O). + 4. Let rx be ? RegExpCreate(R, "g"). + 5. Return ? Invoke(rx, @@matchAll, « S »). +features: [String.prototype.matchAll] +---*/ + +var callCount = 0; +var obj = {}; +RegExp.prototype[Symbol.matchAll] = function() { + callCount++; + return obj; +}; + +assert.sameValue('a'.matchAll(null), obj); +assert.sameValue(callCount, 1); + +assert.sameValue(''.matchAll(undefined), obj); +assert.sameValue(callCount, 2); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-is-undefined.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-is-undefined.js new file mode 100644 index 0000000000..255c0d5a09 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-is-undefined.js @@ -0,0 +1,30 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Behavior when regexp is null +info: | + String.prototype.matchAll ( regexp ) + 1. Let O be ? RequireObjectCoercible(this value). + 2. If regexp is neither undefined nor null, then + [...] + 3. Return ? MatchAllIterator(regexp, O). + + MatchAllIterator( regexp, O ) + [...] + 2. If ? IsRegExp(regexp) is true, then + [...] + 3. Else, + a. Let R be RegExpCreate(regexp, "g"). +features: [String.prototype.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var str = 'a'; + +assert.compareIterator(str.matchAll(undefined), [ + matchValidator([''], 0, str), + matchValidator([''], 1, str) +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-invocation.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-invocation.js new file mode 100644 index 0000000000..0246337834 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-invocation.js @@ -0,0 +1,37 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Invocation of @@matchAll property of user-supplied RegExp objects +info: | + String.prototype.matchAll ( regexp ) + [...] + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). + b. If matcher is not undefined, then + i. Return ? Call(matcher, regexp, « O »). +features: [Symbol.matchAll, String.prototype.matchAll] +---*/ + +var obj = {}; +var returnVal = {}; +var callCount = 0; +var thisVal, args; + +obj[Symbol.matchAll] = function () { + callCount++; + thisVal = this; + args = arguments; + return returnVal; +}; + +var str = ''; + +assert.sameValue(str.matchAll(obj), returnVal); +assert.sameValue(callCount, 1, 'Invokes the method exactly once'); +assert.sameValue(thisVal, obj); +assert.notSameValue(args, undefined); +assert.sameValue(args.length, 1); +assert.sameValue(args[0], str); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-is-undefined-or-null.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-is-undefined-or-null.js new file mode 100644 index 0000000000..ae29ed7feb --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-is-undefined-or-null.js @@ -0,0 +1,40 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Behavior when regexp[@@matchAll] is undefined or null +info: | + String.prototype.matchAll ( regexp ) + 1. Let O be ? RequireObjectCoercible(this value). + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). + b. If matcher is not undefined, then + [...] + 3. Let S be ? ToString(O). + 4. Let rx be ? RegExpCreate(R, "g"). + 5. Return ? Invoke(rx, @@matchAll, « S »). +features: [Symbol.matchAll, String.prototype.matchAll] +---*/ + +var regexp = /./g; +var callCount = 0; +var arg; +var obj = {}; +var str = 'abc'; +RegExp.prototype[Symbol.matchAll] = function(string) { + arg = string; + callCount++; + return obj; +}; + +regexp[Symbol.matchAll] = undefined; +assert.sameValue(str.matchAll(regexp), obj); +assert.sameValue(arg, str); +assert.sameValue(callCount, 1); + +regexp[Symbol.matchAll] = null; +assert.sameValue(str.matchAll(regexp), obj); +assert.sameValue(arg, str); +assert.sameValue(callCount, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-not-callable.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-not-callable.js new file mode 100644 index 0000000000..647b38fb66 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-not-callable.js @@ -0,0 +1,38 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Behavior when regexp[@@matchAll] is not callable +info: | + String.prototype.matchAll ( regexp ) + [...] + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). +features: [Symbol.matchAll, String.prototype.matchAll] +---*/ + +assert.sameValue(typeof String.prototype.matchAll, "function"); + +var regexp = /./; + +regexp[Symbol.matchAll] = true; +assert.throws(TypeError, function() { + ''.matchAll(regexp); +}); + +regexp[Symbol.matchAll] = 5; +assert.throws(TypeError, function() { + ''.matchAll(regexp); +}); + +regexp[Symbol.matchAll] = ''; +assert.throws(TypeError, function() { + ''.matchAll(regexp); +}); + +regexp[Symbol.matchAll] = Symbol(); +assert.throws(TypeError, function() { + ''.matchAll(regexp); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-throws.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-throws.js new file mode 100644 index 0000000000..343aaddfbb --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-matchAll-throws.js @@ -0,0 +1,23 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Re-throws errors when calling @@matchAll +info: | + String.prototype.matchAll ( regexp ) + [...] + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). +features: [Symbol.matchAll, String.prototype.matchAll] +---*/ + +var regexp = /./g; +regexp[Symbol.matchAll] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + ''.matchAll(regexp); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-get-matchAll-throws.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-get-matchAll-throws.js new file mode 100644 index 0000000000..dbad3f4b1d --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-get-matchAll-throws.js @@ -0,0 +1,24 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Re-throws errors thrown while accessing RegExp's @@matchAll property +info: | + String.prototype.matchAll ( regexp ) + [...] + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). +features: [Symbol.matchAll] +---*/ + +Object.defineProperty(RegExp.prototype, Symbol.matchAll, { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + ''.matchAll(/./g); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-has-no-matchAll.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-has-no-matchAll.js new file mode 100644 index 0000000000..bd1d5fd466 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-has-no-matchAll.js @@ -0,0 +1,29 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Behavior when @@matchAll is removed from RegExp's prototype +info: | + String.prototype.matchAll ( regexp ) + 1. Let O be ? RequireObjectCoercible(this value). + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). + b. If matcher is not undefined, then + [...] + [...] + 4. Let rx be ? RegExpCreate(R, "g"). + 5. Return ? Invoke(rx, @@matchAll, « S »). + +features: [Symbol.matchAll, String.prototype.matchAll] +---*/ + +assert.sameValue(typeof String.prototype.matchAll, "function"); + +delete RegExp.prototype[Symbol.matchAll]; +var str = '/a/g*/b/g'; + +assert.throws(TypeError, function() { + str.matchAll(/\w/g); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-invocation.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-invocation.js new file mode 100644 index 0000000000..0da71822e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-invocation.js @@ -0,0 +1,38 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Behavior when invoking of @@matchAll +info: | + String.prototype.matchAll ( regexp ) + [...] + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). + b. If matcher is not undefined, then + i. Return ? Call(matcher, regexp, « O »). +features: [Symbol.matchAll] +---*/ + +var obj = {}; +var returnVal = {}; +var callCount = 0; +var thisVal, args; + +RegExp.prototype[Symbol.matchAll] = function() { + callCount++; + thisVal = this; + args = arguments; + return returnVal; +}; + +var regexp = /./g; +var str = ''; + +assert.sameValue(str.matchAll(regexp), returnVal); +assert.sameValue(callCount, 1, 'Invokes the method exactly once'); +assert.sameValue(thisVal, regexp); +assert.notSameValue(args, undefined); +assert.sameValue(args.length, 1); +assert.sameValue(args[0], str); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-throws.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-throws.js new file mode 100644 index 0000000000..febeeb440c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-throws.js @@ -0,0 +1,24 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Re-throws errors when calling @@matchAll +info: | + String.prototype.matchAll ( regexp ) + [...] + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). + b. If matcher is not undefined, then + i. Return ? Call(matcher, regexp, « O »). +features: [Symbol.matchAll] +---*/ + +RegExp.prototype[Symbol.matchAll] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + ''.matchAll(/./g); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/shell.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/shell.js new file mode 100644 index 0000000000..b2377bc5bc --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/shell.js @@ -0,0 +1,150 @@ +// GENERATED, DO NOT EDIT +// file: compareIterator.js +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Compare the values of an iterator with an array of expected values +defines: [assert.compareIterator] +---*/ + +// Example: +// +// function* numbers() { +// yield 1; +// yield 2; +// yield 3; +// } +// +// assert.compareIterator(numbers(), [ +// v => assert.sameValue(v, 1), +// v => assert.sameValue(v, 2), +// v => assert.sameValue(v, 3), +// ]); +// +assert.compareIterator = function(iter, validators, message) { + message = message || ''; + + var i, result; + for (i = 0; i < validators.length; i++) { + result = iter.next(); + assert(!result.done, 'Expected ' + i + ' values(s). Instead iterator only produced ' + (i - 1) + ' value(s). ' + message); + validators[i](result.value); + } + + result = iter.next(); + assert(result.done, 'Expected only ' + i + ' values(s). Instead iterator produced more. ' + message); + assert.sameValue(result.value, undefined, 'Expected value of `undefined` when iterator completes. ' + message); +} + +// file: regExpUtils.js +// Copyright (C) 2017 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of RegExp objects. +defines: [buildString, testPropertyEscapes, testPropertyOfStrings, testExtendedCharacterClass, matchValidator] +---*/ + +function buildString(args) { + // Use member expressions rather than destructuring `args` for improved + // compatibility with engines that only implement assignment patterns + // partially or not at all. + const loneCodePoints = args.loneCodePoints; + const ranges = args.ranges; + const CHUNK_SIZE = 10000; + let result = Reflect.apply(String.fromCodePoint, null, loneCodePoints); + for (let i = 0; i < ranges.length; i++) { + const range = ranges[i]; + const start = range[0]; + const end = range[1]; + const codePoints = []; + for (let length = 0, codePoint = start; codePoint <= end; codePoint++) { + codePoints[length++] = codePoint; + if (length === CHUNK_SIZE) { + result += Reflect.apply(String.fromCodePoint, null, codePoints); + codePoints.length = length = 0; + } + } + result += Reflect.apply(String.fromCodePoint, null, codePoints); + } + return result; +} + +function printCodePoint(codePoint) { + const hex = codePoint + .toString(16) + .toUpperCase() + .padStart(6, "0"); + return `U+${hex}`; +} + +function printStringCodePoints(string) { + const buf = []; + for (const symbol of string) { + const formatted = printCodePoint(symbol.codePointAt(0)); + buf.push(formatted); + } + return buf.join(' '); +} + +function testPropertyEscapes(regExp, string, expression) { + if (!regExp.test(string)) { + for (const symbol of string) { + const hex = printCodePoint(symbol.codePointAt(0)); + assert( + regExp.test(symbol), + `\`${ expression }\` should match U+${ hex } (\`${ symbol }\`)` + ); + } + } +} + +function testPropertyOfStrings(args) { + // Use member expressions rather than destructuring `args` for improved + // compatibility with engines that only implement assignment patterns + // partially or not at all. + const regExp = args.regExp; + const expression = args.expression; + const matchStrings = args.matchStrings; + const nonMatchStrings = args.nonMatchStrings; + const allStrings = matchStrings.join(''); + if (!regExp.test(allStrings)) { + for (const string of matchStrings) { + assert( + regExp.test(string), + `\`${ expression }\` should match ${ string } (U+${ printStringCodePoints(string) })` + ); + } + } + + const allNonMatchStrings = nonMatchStrings.join(''); + if (regExp.test(allNonMatchStrings)) { + for (const string of nonMatchStrings) { + assert( + !regExp.test(string), + `\`${ expression }\` should not match ${ string } (U+${ printStringCodePoints(string) })` + ); + } + } +} + +// The exact same logic can be used to test extended character classes +// as enabled through the RegExp `v` flag. This is useful to test not +// just standalone properties of strings, but also string literals, and +// set operations. +const testExtendedCharacterClass = testPropertyOfStrings; + +// Returns a function that validates a RegExp match result. +// +// Example: +// +// var validate = matchValidator(['b'], 1, 'abc'); +// validate(/b/.exec('abc')); +// +function matchValidator(expectedEntries, expectedIndex, expectedInput) { + return function(match) { + assert.compareArray(match, expectedEntries, 'Match entries'); + assert.sameValue(match.index, expectedIndex, 'Match index'); + assert.sameValue(match.input, expectedInput, 'Match input'); + } +} diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/this-val-non-obj-coercible.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/this-val-non-obj-coercible.js new file mode 100644 index 0000000000..6e214fc416 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/this-val-non-obj-coercible.js @@ -0,0 +1,24 @@ +// Copyright (C) 2018 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: The `this` value cannot be coerced into an object +info: | + String.prototype.matchAll ( regexp ) + 1. Let O be RequireObjectCoercible(this value). +features: [String.prototype.matchAll] +---*/ + +var matchAll = String.prototype.matchAll; + +assert.sameValue(typeof matchAll, 'function'); + +assert.throws(TypeError, function() { + matchAll.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + matchAll.call(null); +}, 'null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/matchAll/toString-this-val.js b/js/src/tests/test262/built-ins/String/prototype/matchAll/toString-this-val.js new file mode 100644 index 0000000000..6652e29f06 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/matchAll/toString-this-val.js @@ -0,0 +1,43 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: | + Verify ToString is called when regexp[@@matchAll] is undefined or null +info: | + String.prototype.matchAll ( regexp ) + 1. Let O be ? RequireObjectCoercible(this value). + 2. If regexp is neither undefined nor null, then + a. Let matcher be ? GetMethod(regexp, @@matchAll). + b. If matcher is not undefined, then + [...] + 3. Let S be ? ToString(O). + 4. Let rx be ? RegExpCreate(R, "g"). + 5. Return ? Invoke(rx, @@matchAll, « S »). +features: [Symbol.matchAll, String.prototype.matchAll] +---*/ + +var regexp = /./; +var callCount = 0; +var arg; +var obj = {}; +var toStringResult = 'abc'; +var receiver = { + [Symbol.toPrimitive]: function() { + callCount++; + return toStringResult; + } +}; +RegExp.prototype[Symbol.matchAll] = function(string) { + arg = string; +}; + +String.prototype.matchAll.call(receiver, null); +assert.sameValue(callCount, 1); +assert.sameValue(arg, toStringResult); + +String.prototype.matchAll.call(receiver, undefined); +assert.sameValue(callCount, 2); +assert.sameValue(arg, toStringResult); + +reportCompare(0, 0); |