diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/RegExpStringIteratorPrototype')
21 files changed, 739 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/Symbol.toStringTag.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/Symbol.toStringTag.js new file mode 100644 index 0000000000..8a758e65d5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/Symbol.toStringTag.js @@ -0,0 +1,25 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: | + `Symbol.toStringTag` property descriptor +info: | + The initial value of the @@toStringTag property is the string value "String + Iterator". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +features: [Symbol.matchAll, Symbol.toStringTag] +includes: [propertyHelper.js] +---*/ + +var RegExpStringIteratorProto = Object.getPrototypeOf(/./[Symbol.matchAll]('')); + +assert.sameValue(RegExpStringIteratorProto[Symbol.toStringTag], 'RegExp String Iterator'); + +verifyNotEnumerable(RegExpStringIteratorProto, Symbol.toStringTag); +verifyNotWritable(RegExpStringIteratorProto, Symbol.toStringTag); +verifyConfigurable(RegExpStringIteratorProto, Symbol.toStringTag); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/ancestry.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/ancestry.js new file mode 100644 index 0000000000..7278de7f3d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/ancestry.js @@ -0,0 +1,18 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: | + The [[Prototype]] internal slot ofthe %RegExpStringIteratorPrototype% is the + %IteratorPrototype% intrinsic object (25.1.2). +features: [Symbol.iterator, Symbol.matchAll] +---*/ + +var RegExpStringIteratorProto = Object.getPrototypeOf(/./[Symbol.matchAll]('a')); +var ArrayIteratorProto = Object.getPrototypeOf( + Object.getPrototypeOf([][Symbol.iterator]()) +); + +assert.sameValue(Object.getPrototypeOf(RegExpStringIteratorProto), ArrayIteratorProto); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/browser.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/browser.js diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/browser.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/browser.js diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-call-throws.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-call-throws.js new file mode 100644 index 0000000000..4358d95c29 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-call-throws.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: Re-throws errors when calling exec +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 9. Let match be ? RegExpExec(R, S). + + Runtime Semantics: RegExpExec ( R, S ) + 1. Assert: Type(R) is Object. + 2. Assert: Type(S) is String. + 3. Let exec be ? Get(R, "exec"). + 4. If IsCallable(exec) is true, then + a. Let result be ? Call(exec, R, « S »). +features: [Symbol.matchAll] +---*/ + +var iter = /./[Symbol.matchAll](''); + +RegExp.prototype.exec = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + iter.next(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-get-throws.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-get-throws.js new file mode 100644 index 0000000000..b70afc1f65 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-get-throws.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: Re-throws errors thrown while accessing RegExp's exec property +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 9. Let match be ? RegExpExec(R, S). + + Runtime Semantics: RegExpExec ( R, S ) + 1. Assert: Type(R) is Object. + 2. Assert: Type(S) is String. + 3. Let exec be ? Get(R, "exec"). +features: [Symbol.matchAll] +---*/ + +var iter = /./[Symbol.matchAll](''); + +Object.defineProperty(RegExp.prototype, 'exec', { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + iter.next(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-match-get-0-throws.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-match-get-0-throws.js new file mode 100644 index 0000000000..1db7bb3da9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-match-get-0-throws.js @@ -0,0 +1,32 @@ +// 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 the first match +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 9. Let match be ? RegExpExec(R, S). + 10. If match is null, then + [...] + 11. Else, + a. If global is true, + i. Let matchStr be ? ToString(? Get(match, "0")). +features: [Symbol.matchAll] +---*/ + +var iter = /./g[Symbol.matchAll](''); + +RegExp.prototype.exec = function() { + return { + get '0'() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + iter.next(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-match-get-0-tostring-throws.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-match-get-0-tostring-throws.js new file mode 100644 index 0000000000..246d158f35 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-match-get-0-tostring-throws.js @@ -0,0 +1,33 @@ +// 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 from coercing first match to a string +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 9. Let match be ? RegExpExec(R, S). + 10. If match is null, then + [...] + 11. Else, + a. If global is true, + i. Let matchStr be ? ToString(? Get(match, "0")). +features: [Symbol.matchAll] +---*/ + +var iter = /./g[Symbol.matchAll](''); + +RegExp.prototype.exec = function() { + return [{ + toString: function() { + throw new Test262Error(); + } + }]; +}; + +assert.throws(Test262Error, function() { + iter.next(); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-match-get-0-tostring.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-match-get-0-tostring.js new file mode 100644 index 0000000000..3a494cb95f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-match-get-0-tostring.js @@ -0,0 +1,50 @@ +// 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 first match is coerced to a empty string +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 9. Let match be ? RegExpExec(R, S). + 10. If match is null, then + [...] + 11. Else, + a. If global is true, + i. Let matchStr be ? ToString(? Get(match, "0")). + ii. If matchStr is the empty string, + 1. Let thisIndex be ? ToLength(? Get(R, "lastIndex"). + 2. Let nextIndex be ! AdvanceStringIndex(S, thisIndex, fullUnicode). + 3. Perform ? Set(R, "lastIndex", nextIndex, true). + iii. Return ! CreateIterResultObject(match, false). +features: [Symbol.matchAll] +---*/ + +var iter = /./g[Symbol.matchAll](''); + +var execResult = { + get '0'() { + return { + toString() { return ''; } + }; + } +}; + +var internalRegExp; +RegExp.prototype.exec = function () { + internalRegExp = this; + return execResult; +}; + +var result = iter.next(); +assert.sameValue(internalRegExp.lastIndex, 1); +assert.sameValue(result.value, execResult); +assert(!result.done); + + +result = iter.next(); +assert.sameValue(internalRegExp.lastIndex, 2); +assert.sameValue(result.value, execResult); +assert(!result.done); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-not-callable.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-not-callable.js new file mode 100644 index 0000000000..2f41827aa4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec-not-callable.js @@ -0,0 +1,42 @@ +// 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 with a custom RegExp exec +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 9. Let match be ? RegExpExec(R, S). + + Runtime Semantics: RegExpExec ( R, S ) + 1. Assert: Type(R) is Object. + 2. Assert: Type(S) is String. + 3. Let exec be ? Get(R, "exec"). + 4. If IsCallable(exec) is true, then + [...] + 5. If R does not have a [[RegExpMatcher]] internal slot, throw a + TypeError exception. + 6. Return ? RegExpBuiltinExec(R, S). +features: [Symbol.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +function TestWithRegExpExec(exec) { + RegExp.prototype.exec = exec; + + var regexp = /\w/g; + var str = 'a*b'; + + assert.compareIterator(regexp[Symbol.matchAll](str), [ + matchValidator(['a'], 0, str), + matchValidator(['b'], 2, str) + ]); +} + +TestWithRegExpExec(undefined); +TestWithRegExpExec(null); +TestWithRegExpExec(5); +TestWithRegExpExec(true); +TestWithRegExpExec(Symbol()); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec.js new file mode 100644 index 0000000000..b7970c1db2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/custom-regexpexec.js @@ -0,0 +1,57 @@ +// 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 with a custom RegExp exec +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 9. Let match be ? RegExpExec(R, S). + + Runtime Semantics: RegExpExec ( R, S ) + 1. Assert: Type(R) is Object. + 2. Assert: Type(S) is String. + 3. Let exec be ? Get(R, "exec"). + 4. If IsCallable(exec) is true, then + a. Let result be ? Call(exec, R, « S »). + b. If Type(result) is neither Object or Null, throw a TypeError exception. + c. Return result. +features: [Symbol.matchAll] +---*/ + +var regexp = /./g; +var str = 'abc'; +var iter = regexp[Symbol.matchAll](str); + +var callArgs, callCount; +function callNextWithExecReturnValue(returnValue) { + callArgs = undefined; + callCount = 0; + + RegExp.prototype.exec = function() { + callArgs = arguments; + callCount++; + return returnValue; + } + + return iter.next(); +} + +var firstExecReturnValue = ['ab']; +var result = callNextWithExecReturnValue(firstExecReturnValue); +assert.sameValue(result.value, firstExecReturnValue); +assert(!result.done); + +assert.sameValue(callArgs.length, 1); +assert.sameValue(callArgs[0], str); +assert.sameValue(callCount, 1); + +result = callNextWithExecReturnValue(null); +assert.sameValue(result.value, undefined); +assert(result.done); + +assert.sameValue(callArgs.length, 1); +assert.sameValue(callArgs[0], str); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/length.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/length.js new file mode 100644 index 0000000000..da310cd3f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/length.js @@ -0,0 +1,35 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: | + %RegExpStringIteratorPrototype%.next `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: [Symbol.matchAll] +---*/ + +var RegExpStringIteratorProto = Object.getPrototypeOf(/./[Symbol.matchAll]('')); + +assert.sameValue(RegExpStringIteratorProto.next.length, 0); + +verifyNotEnumerable(RegExpStringIteratorProto.next, 'length'); +verifyNotWritable(RegExpStringIteratorProto.next, 'length'); +verifyConfigurable(RegExpStringIteratorProto.next, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/name.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/name.js new file mode 100644 index 0000000000..bd178670f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/name.js @@ -0,0 +1,33 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: | + %RegExpStringIteratorPrototype%.next `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: [Symbol.matchAll] +---*/ + +var RegExpStringIteratorProto = Object.getPrototypeOf(/./[Symbol.matchAll]('')); + +assert.sameValue(RegExpStringIteratorProto.next.name, 'next'); + +verifyNotEnumerable(RegExpStringIteratorProto.next, 'name'); +verifyNotWritable(RegExpStringIteratorProto.next, 'name'); +verifyConfigurable(RegExpStringIteratorProto.next, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/next-iteration-global.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/next-iteration-global.js new file mode 100644 index 0000000000..480f4abc84 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/next-iteration-global.js @@ -0,0 +1,42 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Iterates over each match +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 4. If O.[[Done]] is true, then + a. Return ! reateIterResultObject(undefined, true). + [...] + 9. Let match be ? RegExpExec(R, S). + 10. If match is null, then + a. Set O.[[Done]] to true. + b. Return ! CreateIterResultObject(undefined, true). + 11. Else, + a. If global is true, + i. Let matchStr be ? ToString(? Get(match, "0")). + ii. If matchStr is the empty string, + 1. Let thisIndex be ? ToLength(? Get(R, "lastIndex"). + 2. Let nextIndex be ! AdvanceStringIndex(S, thisIndex, fullUnicode). + 3. Perform ? Set(R, "lastIndex", nextIndex, true). + iii. Return ! CreateIterResultObject(match, false). +features: [Symbol.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var regexp = /\w/g; +var str = 'a*b'; +var iter = regexp[Symbol.matchAll](str); + +assert.compareIterator(iter, [ + matchValidator(['a'], 0, str), + matchValidator(['b'], 2, str) +]); + +// Verifies %RegExpStringIteratorPrototype%.next() step 4 +var result = iter.next(); +assert.sameValue(result.value, undefined); +assert(result.done); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/next-iteration.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/next-iteration.js new file mode 100644 index 0000000000..e8018291e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/next-iteration.js @@ -0,0 +1,39 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Iterates over the first match +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 4. If O.[[Done]] is true, then + a. Return ! reateIterResultObject(undefined, true). + [...] + 9. Let match be ? RegExpExec(R, S). + 10. If match is null, then + a. Set O.[[Done]] to true. + b. Return ! CreateIterResultObject(undefined, true). + 11. Else, + a. If global is true, + [...] + b. Else, + i. Set O.[[Done]] to true. + ii. Return ! CreateIterResultObject(match, false). +features: [Symbol.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var regexp = /\w/; +var str = '*a*b'; +var iter = regexp[Symbol.matchAll](str); + +assert.compareIterator(iter, [ + matchValidator(['a'], 1, str) +]); + +// Verifies %RegExpStringIteratorPrototype%.next() step 4 +var result = iter.next(); +assert.sameValue(result.value, undefined); +assert(result.done); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/next-missing-internal-slots.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/next-missing-internal-slots.js new file mode 100644 index 0000000000..a3c9deba9e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/next-missing-internal-slots.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: Throws TypeError when `this` does not have all internal slots +info: | + %RegExpStringIteratorPrototype%.next ( ) + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have all of the internal slots of a RegExp String Iterator + Object Instance (see PropertiesOfRegExpStringIteratorInstances), throw a + TypeError. +features: [Symbol.matchAll] +---*/ + +var iterator = /./[Symbol.matchAll](''); +var object = Object.create(iterator); + +assert.throws(TypeError, function() { + object.next(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/prop-desc.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/prop-desc.js new file mode 100644 index 0000000000..30a506ebbb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/prop-desc.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: | + %RegExpStringIteratorPrototype%.next 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: [Symbol.matchAll] +---*/ + +var RegExpStringIteratorProto = Object.getPrototypeOf(/./[Symbol.matchAll]('')); + +assert.sameValue(typeof RegExpStringIteratorProto.next, 'function'); + +verifyNotEnumerable(RegExpStringIteratorProto, 'next'); +verifyWritable(RegExpStringIteratorProto, 'next'); +verifyConfigurable(RegExpStringIteratorProto, 'next'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/regexp-tolength-lastindex-throws.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/regexp-tolength-lastindex-throws.js new file mode 100644 index 0000000000..54985688ab --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/regexp-tolength-lastindex-throws.js @@ -0,0 +1,35 @@ +// 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 coercing RegExp's lastIndex to a length +info: | + %RegExpStringIteratorPrototype%.next ( ) + [...] + 9. Let match be ? RegExpExec(R, S). + 10. If match is null, then + [...] + 11. Else, + a. If global is true, + i. Let matchStr be ? ToString(? Get(match, "0")). + ii. If matchStr is the empty string, + 1. Let thisIndex be ? ToLength(? Get(R, "lastIndex"). +features: [Symbol.matchAll] +---*/ + +var iter = /./g[Symbol.matchAll](''); + +RegExp.prototype.exec = function() { + this.lastIndex = { + valueOf() { + throw new Test262Error(); + } + }; + return ['']; +}; + +assert.throws(Test262Error, function() { + iter.next(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/shell.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/shell.js new file mode 100644 index 0000000000..0ba29600b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/shell.js @@ -0,0 +1,152 @@ +// 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 formatted = printCodePoint(symbol.codePointAt(0)); + assert( + regExp.test(symbol), + `\`${ expression }\` should match ${ formatted } (\`${ 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 } (${ printStringCodePoints(string) })` + ); + } + } + + if (!nonMatchStrings) return; + + const allNonMatchStrings = nonMatchStrings.join(''); + if (regExp.test(allNonMatchStrings)) { + for (const string of nonMatchStrings) { + assert( + !regExp.test(string), + `\`${ expression }\` should not match ${ string } (${ 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/RegExpStringIteratorPrototype/next/this-is-not-object-throws.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/this-is-not-object-throws.js new file mode 100644 index 0000000000..3d587339c9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/next/this-is-not-object-throws.js @@ -0,0 +1,36 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: Throws TypeError when `this` is not an Object +info: | + %RegExpStringIteratorPrototype%.next ( ) + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. +features: [Symbol.matchAll] +---*/ + +var RegExpStringIteratorProto = Object.getPrototypeOf(/./[Symbol.matchAll]('')); + +var thisValue; +var callNext = function() { + RegExpStringIteratorProto.next.call(thisValue); +}; + +thisValue = null; +assert.throws(TypeError, callNext, 'this value is null'); + +thisValue = true; +assert.throws(TypeError, callNext, 'this value is Boolean'); + +thisValue = ''; +assert.throws(TypeError, callNext, 'this value is String'); + +thisValue = Symbol(); +assert.throws(TypeError, callNext, 'this value is Symbol'); + +thisValue = 1; +assert.throws(TypeError, callNext, 'this value is Number'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/shell.js b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExpStringIteratorPrototype/shell.js |