diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split')
46 files changed, 1616 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-flags-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-flags-err.js new file mode 100644 index 0000000000..b779f838eb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-flags-err.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Behavior when error thrown while coercing `flags` property +info: | + [...] + 7. Let flags be ToString(Get(rx, "flags")). + 8. ReturnIfAbrupt(flags). +features: [Symbol.split] +---*/ + +var uncoercibleFlags = { + flags: { + toString: function() { + throw new Test262Error(); + } + } +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(uncoercibleFlags); +}); + +uncoercibleFlags = { + flags: Symbol.split +}; + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(uncoercibleFlags); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-flags.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-flags.js new file mode 100644 index 0000000000..d0c4f610c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-flags.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: String coercion of `flags` property +info: | + [...] + 7. Let flags be ToString(Get(rx, "flags")). + [...] + 13. Let splitter be Construct(C, «rx, newFlags»). + [...] +features: [Symbol.split, Symbol.species] +---*/ + +var obj = { + constructor: function() {}, + flags: { + toString: function() { + return 'toString valuey'; + } + } +}; +var flagsArg; + +obj.constructor = function() {}; +obj.constructor[Symbol.species] = function(_, flags) { + flagsArg = flags; + return /./y; +}; + +RegExp.prototype[Symbol.split].call(obj); + +assert.sameValue(flagsArg, 'toString valuey'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-limit-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-limit-err.js new file mode 100644 index 0000000000..96a916768e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-limit-err.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Behavior when error thrown while coercing `limit` argument +info: | + [...] + 17. If limit is undefined, let lim be 253–1; else let lim be + ToLength(limit). + 18. ReturnIfAbrupt(lim). +features: [Symbol.split] +---*/ + +var uncoercibleObj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(TypeError, function() { + /./[Symbol.split]('', Symbol.split); +}); + +assert.throws(Test262Error, function() { + /./[Symbol.split]('', uncoercibleObj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-limit.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-limit.js new file mode 100644 index 0000000000..d355b34599 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-limit.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Length coercion of `limit` argument +info: | + [...] + 17. If limit is undefined, let lim be 2^32-1; else let lim be ? ToUint32(limit). + [...] +features: [Symbol.split] +---*/ + +var result; + +// ToUint32(-23) = 4294967273 +result = /./[Symbol.split]('abc', -23); +assert(Array.isArray(result)); +assert.sameValue(result.length, 4); + +result = /./[Symbol.split]('abc', 1.9); +assert(Array.isArray(result)); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], ''); + +result = /./[Symbol.split]('abc', NaN); +assert(Array.isArray(result)); +assert.sameValue(result.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-string-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-string-err.js new file mode 100644 index 0000000000..bb7c9696d1 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-string-err.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Behavior when error thrown while coercing `string` argument +info: | + [...] + 3. Let S be ToString(string). + 4. ReturnIfAbrupt(S). +features: [Symbol.split] +---*/ + +var uncoercibleObj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + /./[Symbol.split](uncoercibleObj); +}); + +assert.throws(TypeError, function() { + /./[Symbol.split](Symbol.split); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-string.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-string.js new file mode 100644 index 0000000000..d1708d8e1a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/coerce-string.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: String coercion of `string` argument +info: | + [...] + 3. Let S be ToString(string). + [...] +features: [Symbol.split] +---*/ + +var obj = { + toString: function() { + return 'toString value'; + } +}; +var result; + +result = / /[Symbol.split](obj); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 2); +assert.sameValue(result[0], 'toString'); +assert.sameValue(result[1], 'value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/get-flags-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/get-flags-err.js new file mode 100644 index 0000000000..62fc932fb5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/get-flags-err.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Behavior when error thrown while accessing `flags` property +info: | + [...] + 7. Let flags be ToString(Get(rx, "flags")). + 8. ReturnIfAbrupt(flags). +features: [Symbol.split] +---*/ + +var poisonedFlags = { + get flags() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(poisonedFlags); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/last-index-exceeds-str-size.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/last-index-exceeds-str-size.js new file mode 100644 index 0000000000..d229f5b8f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/last-index-exceeds-str-size.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@split +description: The `lastIndex` property is clamped to the string size. +info: | + RegExp.prototype [ @@split ] ( string, limit ) + + ... + 19. Repeat, while q < size + ... + d. Else z is not null, + i. Let e be ? ToLength(Get(splitter, "lastIndex")). + ii. Let e be min(e, size). + ... +features: [Symbol.split] +---*/ + +var regExp = /a/; +var string = "foo"; + +RegExp.prototype.exec = function() { + this.lastIndex = 100; + return {length: 0, index: 0}; +}; + +var result = regExp[Symbol.split](string); + +assert.sameValue(result.length, 2, "result.length"); +assert.sameValue(result[0], "", "result[0]"); +assert.sameValue(result[1], "", "result[1]"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/length.js new file mode 100644 index 0000000000..546f056ca0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/length.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.2.5.11 +description: RegExp.prototype[Symbol.split] `length` property +info: | + The length property of the @@split method is 2. + + ES6 Section 17: + + [...] + + 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.split] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.split].length, 2); + +verifyNotEnumerable(RegExp.prototype[Symbol.split], 'length'); +verifyNotWritable(RegExp.prototype[Symbol.split], 'length'); +verifyConfigurable(RegExp.prototype[Symbol.split], 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/limit-0-bail.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/limit-0-bail.js new file mode 100644 index 0000000000..0037f5d21b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/limit-0-bail.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: No matching attempt is made when `limit` argument is `0` +info: | + [...] + 21. If lim = 0, return A. +features: [Symbol.split, Symbol.species] +---*/ + +var result; +var obj = { + constructor: function() {} +}; +obj.constructor[Symbol.species] = function() { + return { + exec: function() { + throw new Test262Error('No match should be attempted when `limit` is `0`.'); + } + }; +}; + +result = RegExp.prototype[Symbol.split].call(obj, '', 0); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/name.js new file mode 100644 index 0000000000..aac4f253a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.2.5.11 +description: RegExp.prototype[Symbol.split] `name` property +info: | + The value of the name property of this function is "[Symbol.split]". + + ES6 Section 17: + + [...] + + 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.split] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.split].name, '[Symbol.split]'); + +verifyNotEnumerable(RegExp.prototype[Symbol.split], 'name'); +verifyNotWritable(RegExp.prototype[Symbol.split], 'name'); +verifyConfigurable(RegExp.prototype[Symbol.split], 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/not-a-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/not-a-constructor.js new file mode 100644 index 0000000000..4623db96ba --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/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: > + RegExp.prototype[Symbol.split] 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, Symbol, Symbol.split, arrow-function] +---*/ + +assert.sameValue( + isConstructor(RegExp.prototype[Symbol.split]), + false, + 'isConstructor(RegExp.prototype[Symbol.split]) must return false' +); + +assert.throws(TypeError, () => { + let re = new RegExp(''); new re[Symbol.split](); +}, '`let re = new RegExp(\'\'); new re[Symbol.split]()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/prop-desc.js new file mode 100644 index 0000000000..f85d07714a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/prop-desc.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: RegExp.prototype[Symbol.split] property descriptor +info: | + ES6 Section 17 + + 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.split] +---*/ + +verifyNotEnumerable(RegExp.prototype, Symbol.split); +verifyWritable(RegExp.prototype, Symbol.split); +verifyConfigurable(RegExp.prototype, Symbol.split); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-ctor-get-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-ctor-get-err.js new file mode 100644 index 0000000000..f96a1389d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-ctor-get-err.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Behavior when error thrown while accessing `constructor` property +info: | + [...] + 5. Let C be SpeciesConstructor(rx, %RegExp%). + 6. ReturnIfAbrupt(C). + + ES6 Section 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). +features: [Symbol.split] +---*/ + +var poisonedCtor = { + get constructor() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(poisonedCtor); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-ctor-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-ctor-non-obj.js new file mode 100644 index 0000000000..f4e1d26d03 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-ctor-non-obj.js @@ -0,0 +1,52 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: TypeError when `constructor` property is defined but not an object +info: | + [...] + 5. Let C be SpeciesConstructor(rx, %RegExp%). + 6. ReturnIfAbrupt(C). + + ES6 Section 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + 5. If Type(C) is not Object, throw a TypeError exception. +features: [Symbol.split] +---*/ + +var obj = { flags: '' }; + +// Avoid false positives from unrelated TypeErrors +RegExp.prototype[Symbol.split].call(obj); + +obj.constructor = false; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(obj); +}); + +obj.constructor = 'string'; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(obj); +}); + +obj.constructor = Symbol.split; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(obj); +}); + +obj.constructor = 86; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(obj); +}); + +obj.constructor = null; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-ctor-undef.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-ctor-undef.js new file mode 100644 index 0000000000..c77f8aaa12 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-ctor-undef.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: RegExp used when `this` value does not define a constructor +info: | + [...] + 5. Let C be SpeciesConstructor(rx, %RegExp%). + [...] + + ES6 Section 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. +features: [Symbol.split] +---*/ + +var re = /[db]/; +var result; +re.constructor = undefined; + +result = re[Symbol.split]('abcde'); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 3); +assert.sameValue(result[0], 'a'); +assert.sameValue(result[1], 'c'); +assert.sameValue(result[2], 'e'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-err.js new file mode 100644 index 0000000000..a694e44854 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-err.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Behavior when error thrown by custom species constructor +info: | + [...] + 5. Let C be SpeciesConstructor(rx, %RegExp%). + [...] + 13. Let splitter be Construct(C, «rx, newFlags»). + 14. ReturnIfAbrupt(splitter). + + ES6 Section 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + 5. If Type(C) is not Object, throw a TypeError exception. + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. + 9. If IsConstructor(S) is true, return S. +features: [Symbol.split, Symbol.species] +---*/ + +var re = /x/; +re.constructor = function() {}; +re.constructor[Symbol.species] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + re[Symbol.split](); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-species-get-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-species-get-err.js new file mode 100644 index 0000000000..8a231885b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-species-get-err.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + Behavior when error thrown while accessing `Symbol.species` property of + constructor +info: | + [...] + 5. Let C be SpeciesConstructor(rx, %RegExp%). + 6. ReturnIfAbrupt(C). + + ES6 Section 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + 5. If Type(C) is not Object, throw a TypeError exception. + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). +features: [Symbol.split, Symbol.species] +---*/ + +var poisonedSpecies = function() {}; +Object.defineProperty(poisonedSpecies, Symbol.species, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call({ constructor: poisonedSpecies }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-species-non-ctor.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-species-non-ctor.js new file mode 100644 index 0000000000..7203f84fd2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-species-non-ctor.js @@ -0,0 +1,59 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + TypeError thrown when `Symbol.species` property value is not a constructor +info: | + [...] + 5. Let C be SpeciesConstructor(rx, %RegExp%). + 6. ReturnIfAbrupt(C). + + ES6 Section 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + 5. If Type(C) is not Object, throw a TypeError exception. + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. + 9. If IsConstructor(S) is true, return S. + 10. Throw a TypeError exception. +features: [Symbol.split, Symbol.species] +---*/ + +var re = /./; +re.constructor = function() {}; + +// Avoid false positives from unrelated TypeErrors +re[Symbol.split](); + +re.constructor[Symbol.species] = {}; +assert.throws(TypeError, function() { + re[Symbol.split](); +}); + +re.constructor[Symbol.species] = 0; +assert.throws(TypeError, function() { + re[Symbol.split](); +}); + +re.constructor[Symbol.species] = ''; +assert.throws(TypeError, function() { + re[Symbol.split](); +}); + +re.constructor[Symbol.species] = Symbol.split; +assert.throws(TypeError, function() { + re[Symbol.split](); +}); + +re.constructor[Symbol.species] = Date.now; +assert.throws(TypeError, function() { + re[Symbol.split](); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-species-undef.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-species-undef.js new file mode 100644 index 0000000000..21614b66f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-species-undef.js @@ -0,0 +1,50 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + RegExp used when the `Symbol.species` property of the `this` value's + constructor is `undefined` or `null` +info: | + [...] + 5. Let C be SpeciesConstructor(rx, %RegExp%). + [...] + + ES6 Section 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + 5. If Type(C) is not Object, throw a TypeError exception. + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. +features: [Symbol.split, Symbol.species] +---*/ + +var noSpecies = function() {}; +var re = /[db]/; +var result; +re.constructor = noSpecies; + +noSpecies[Symbol.species] = undefined; +result = re[Symbol.split]('abcde'); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 3); +assert.sameValue(result[0], 'a'); +assert.sameValue(result[1], 'c'); +assert.sameValue(result[2], 'e'); + +noSpecies[Symbol.species] = null; +result = re[Symbol.split]('abcde'); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 3); +assert.sameValue(result[0], 'a'); +assert.sameValue(result[1], 'c'); +assert.sameValue(result[2], 'e'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-y.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-y.js new file mode 100644 index 0000000000..59b44ea327 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor-y.js @@ -0,0 +1,47 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: The `y` flag is always used in constructing the "splitter" object +info: | + [...] + 5. Let C be SpeciesConstructor(rx, %RegExp%). + [...] + 11. If flags contains "y", let newFlags be flags. + 12. Else, let newFlags be the string that is the concatenation of flags and + "y". + 13. Let splitter be Construct(C, «rx, newFlags»). + [...] +features: [Symbol.split, Symbol.species] +---*/ + +var flagsArg; +var re = {}; +re.constructor = function() {}; +re.constructor[Symbol.species] = function(_, flags) { + flagsArg = flags; + return /./y; +}; + +re.flags = ''; +RegExp.prototype[Symbol.split].call(re, ''); +assert.sameValue(flagsArg, 'y'); + +re.flags = 'abcd'; +RegExp.prototype[Symbol.split].call(re, ''); +assert.sameValue(flagsArg, 'abcdy'); + +re.flags = 'Y'; +RegExp.prototype[Symbol.split].call(re, ''); +assert.sameValue(flagsArg, 'Yy'); + +re.flags = 'y'; +RegExp.prototype[Symbol.split].call(re, ''); +assert.sameValue(flagsArg, 'y'); + +re.flags = 'abycd'; +RegExp.prototype[Symbol.split].call(re, ''); +assert.sameValue(flagsArg, 'abycd'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor.js new file mode 100644 index 0000000000..b8f058dc0e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/species-ctor.js @@ -0,0 +1,50 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Invocation of custom species constructor +info: | + [...] + 5. Let C be SpeciesConstructor(rx, %RegExp%). + [...] + 13. Let splitter be Construct(C, «rx, newFlags»). + [...] + + ES6 Section 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + + 1. Assert: Type(O) is Object. + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + 5. If Type(C) is not Object, throw a TypeError exception. + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. + 9. If IsConstructor(S) is true, return S. +features: [Symbol.split, Symbol.species] +---*/ + +var thisVal, args, result; +var re = /x/iy; +re.constructor = function() {}; +re.constructor[Symbol.species] = function() { + thisVal = this; + args = arguments; + return /[db]/y; +}; + +result = RegExp.prototype[Symbol.split].call(re, 'abcde'); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 3); +assert.sameValue(result[0], 'a'); +assert.sameValue(result[1], 'c'); +assert.sameValue(result[2], 'e'); + +assert(thisVal instanceof re.constructor[Symbol.species]); +assert.sameValue(args.length, 2); +assert.sameValue(args[0], re); +assert.sameValue(args[1], 'iy'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/splitter-proto-from-ctor-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/splitter-proto-from-ctor-realm.js new file mode 100644 index 0000000000..577b554855 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/splitter-proto-from-ctor-realm.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-regexp.prototype-@@split +description: Default [[Prototype]] value derived from realm of the constructor +info: | + 10. Let splitter be ? Construct(C, « rx, newFlags »). + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Symbol.species, Symbol.split] +---*/ + +var other = $262.createRealm().global; +other.shared = null; +var C = new other.Function('shared = this; return /./;'); +C.prototype = null; + +var r = /./; +r.constructor = function() {}; +r.constructor[Symbol.species] = C; + +r[Symbol.split](); + +assert.sameValue(Object.getPrototypeOf(other.shared), other.Object.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-adv-thru-empty-match.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-adv-thru-empty-match.js new file mode 100644 index 0000000000..3918899112 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-adv-thru-empty-match.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + lastIndex is explicitly advanced following an empty match +es6id: 21.2.5.11 +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + b. ReturnIfAbrupt(setStatus). + c. Let z be RegExpExec(splitter, S). + d. ReturnIfAbrupt(z). + e. If z is null, let q be AdvanceStringIndex(S, q, unicodeMatching). + f. Else z is not null, + i. Let e be ToLength(Get(splitter, "lastIndex")). + ii. ReturnIfAbrupt(e). + iii. If e = p, let q be AdvanceStringIndex(S, q, unicodeMatching). +features: [Symbol.split] +---*/ + +var result = /(?:)/[Symbol.split]('abc'); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 3); +assert.sameValue(result[0], 'a'); +assert.sameValue(result[1], 'b'); +assert.sameValue(result[2], 'c'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-coerce-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-coerce-lastindex-err.js new file mode 100644 index 0000000000..7cf7bde55a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-coerce-lastindex-err.js @@ -0,0 +1,51 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + Behavior when error thrown while coercing `lastIndex` property of splitter + after a match +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + i. Let e be ToLength(Get(splitter, "lastIndex")). + ii. ReturnIfAbrupt(e). +features: [Symbol.split, Symbol.species] +---*/ + +var badLastIndex; +var obj = { + constructor: function() {} +}; +var fakeRe = { + set lastIndex(_) {}, + get lastIndex() { + return badLastIndex; + }, + exec: function() { + return []; + } +}; +obj.constructor[Symbol.species] = function() { + return fakeRe; +}; + +badLastIndex = Symbol.split; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(obj, 'abcd'); +}); + +badLastIndex = { + valueOf: function() { throw new Test262Error(); } +}; +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(obj, 'abcd'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-coerce-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-coerce-lastindex.js new file mode 100644 index 0000000000..a8a910fa95 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-coerce-lastindex.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Length coercion of `lastIndex` property of splitter after a match +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + i. Let e be ToLength(Get(splitter, "lastIndex")). + [...] +features: [Symbol.split, Symbol.species] +---*/ + +var result; +var obj = { + constructor: function() {} +}; +var fakeRe = { + set lastIndex(_) {}, + get lastIndex() { + return { + valueOf: function() { + return 2.9; + } + }; + }, + exec: function() { + return []; + } +}; +obj.constructor[Symbol.species] = function() { + return fakeRe; +}; + +result = RegExp.prototype[Symbol.split].call(obj, 'abcd'); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 2); +assert.sameValue(result[0], ''); +assert.sameValue(result[1], 'cd'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-empty-match-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-empty-match-err.js new file mode 100644 index 0000000000..d1452fbf37 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-empty-match-err.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Behavior when error thrown while executing match for empty string +info: | + [...] + 22. If size = 0, then + a. Let z be RegExpExec(splitter, S). + b. ReturnIfAbrupt(z). +features: [Symbol.split, Symbol.species] +---*/ + +var obj = { + constructor: function() {} +}; +obj.constructor[Symbol.species] = function() { + return { + exec: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(obj, ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-empty-match.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-empty-match.js new file mode 100644 index 0000000000..7411ded2cb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-empty-match.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Successful match of empty string +info: | + [...] + 22. If size = 0, then + a. Let z be RegExpExec(splitter, S). + b. ReturnIfAbrupt(z). + c. If z is not null, return A. +features: [Symbol.split] +---*/ + +var result = /(?:)/[Symbol.split](''); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-empty-no-match.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-empty-no-match.js new file mode 100644 index 0000000000..b4cd097e29 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-empty-no-match.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Unsuccessful match of empty string +info: | + [...] + 22. If size = 0, then + a. Let z be RegExpExec(splitter, S). + b. ReturnIfAbrupt(z). + c. If z is not null, return A. + d. Assert: The following call will never result in an abrupt + completion. + e. Perform CreateDataProperty(A, "0", S). + f. Return A. +features: [Symbol.split] +---*/ + +var result = /./[Symbol.split](''); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-get-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-get-lastindex-err.js new file mode 100644 index 0000000000..64f8cc21d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-get-lastindex-err.js @@ -0,0 +1,46 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + Behavior when error thrown while accessing `lastIndex` property of splitter + after a match +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + i. Let e be ToLength(Get(splitter, "lastIndex")). + ii. ReturnIfAbrupt(e). +features: [Symbol.split, Symbol.species] +---*/ + +var obj = { + constructor: function() {} +}; +var callCount = 0; +var fakeRe = { + set lastIndex(_) {}, + get lastIndex() { + throw new Test262Error(); + }, + exec: function() { + callCount += 1; + return []; + } +}; +obj.constructor[Symbol.species] = function() { + return fakeRe; +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(obj, 'abcd'); +}); + +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-limit-capturing.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-limit-capturing.js new file mode 100644 index 0000000000..c08608a185 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-limit-capturing.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: The `limit` argument is applied to capturing groups +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + [...] + iv. Else e ≠ p, + [...] + 11. Repeat, while i ≤ numberOfCaptures. + [...] + f. If lengthA = lim, return A. +features: [Symbol.split] +---*/ + +var result = /c(d)(e)/[Symbol.split]('abcdefg', 2); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 2); +assert.sameValue(result[0], 'ab'); +assert.sameValue(result[1], 'd'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-limit.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-limit.js new file mode 100644 index 0000000000..0d13dcb1bb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-limit.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Results limited to number specified as second argument +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + [...] + iv. Else e ≠ p, + [...] + 3. Perform CreateDataProperty(A, ToString(lengthA), T). + 4. Let lengthA be lengthA +1. + 5. If lengthA = lim, return A. +features: [Symbol.split] +---*/ + +var result = /x/[Symbol.split]('axbxcxdxe', 3); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 3); +assert.sameValue(result[0], 'a'); +assert.sameValue(result[1], 'b'); +assert.sameValue(result[2], 'c'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-match-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-match-err.js new file mode 100644 index 0000000000..0f158b23ec --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-match-err.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + Behavior when error thrown while executing match for non-empty string +info: | + [...] + 24. Repeat, while q < size + [...] + c. Let z be RegExpExec(splitter, S). + d. ReturnIfAbrupt(z). +features: [Symbol.split, Symbol.species] +---*/ + +var obj = { + constructor: function() {} +}; +obj.constructor[Symbol.species] = function() { + return { + exec: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(obj, 'a'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-coerce-length-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-coerce-length-err.js new file mode 100644 index 0000000000..884fd5e22c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-coerce-length-err.js @@ -0,0 +1,52 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + Behavior when error thrown while coercing `length` property of match result +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + iv. Else e ≠ p, + [...] + 7. Let numberOfCaptures be ToLength(Get(z, "length")). + 8. ReturnIfAbrupt(numberOfCaptures). +features: [Symbol.split, Symbol.species] +---*/ + +var obj = { + constructor: function() {} +}; +var uncoercibleLength; +var fakeRe = { + exec: function() { + return { + length: uncoercibleLength + }; + } +}; +obj.constructor[Symbol.species] = function() { + return fakeRe; +}; + +uncoercibleLength = Symbol.split; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(obj, 'abcd'); +}); + +uncoercibleLength = { + valueOf: function() { + throw new Test262Error(); + } +}; +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(obj, 'abcd'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-coerce-length.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-coerce-length.js new file mode 100644 index 0000000000..9ffa5fe519 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-coerce-length.js @@ -0,0 +1,54 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + Length coercion of `length` property of match result +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + iv. Else e ≠ p, + [...] + 7. Let numberOfCaptures be ToLength(Get(z, "length")). + [...] +features: [Symbol.split, Symbol.species] +---*/ + +var result; +var obj = { + constructor: function() {} +}; +var fakeRe = { + exec: function() { + fakeRe.lastIndex = 1; + return { + length: { + valueOf: function() { + return 2.9; + } + }, + 0: 'foo', + 1: 'bar', + 2: 'baz' + }; + } +}; +obj.constructor[Symbol.species] = function() { + return fakeRe; +}; + +result = RegExp.prototype[Symbol.split].call(obj, 'a'); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 3); +assert.sameValue(result[0], ''); +assert.sameValue(result[1], 'bar'); +assert.sameValue(result[2], ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-get-capture-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-get-capture-err.js new file mode 100644 index 0000000000..efea4dacc2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-get-capture-err.js @@ -0,0 +1,51 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + Behavior when error thrown while accessing capturing group match +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + iv. Else e ≠ p, + [...] + 11. Repeat, while i ≤ numberOfCaptures. + [...] + a. Let nextCapture be Get(z, ToString(i)). + b. ReturnIfAbrupt(nextCapture). +features: [Symbol.split, Symbol.species] +---*/ + +var result; +var obj = { + constructor: function() {} +}; +var poisonedCapture = { + length: 3, + 0: 'a', + 1: 'b', + get 2() { + throw new Test262Error(); + } +}; +var fakeRe = { + exec: function() { + fakeRe.lastIndex = 1; + return poisonedCapture; + } +}; +obj.constructor[Symbol.species] = function() { + return fakeRe; +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(obj, 'a'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-get-length-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-get-length-err.js new file mode 100644 index 0000000000..ec7e011813 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-result-get-length-err.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + Behavior when error thrown while accessing `length` property of match + result +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + iv. Else e ≠ p, + [...] + 7. Let numberOfCaptures be ToLength(Get(z, "length")). + 8. ReturnIfAbrupt(numberOfCaptures). +features: [Symbol.split, Symbol.species] +---*/ + +var obj = { + constructor: function() {} +}; +var poisonedLength = { + get length() { + throw new Test262Error(); + } +}; +var fakeRe = { + exec: function() { + return poisonedLength; + } +}; +obj.constructor[Symbol.species] = function() { + return fakeRe; +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(obj, 'abcd'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-set-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-set-lastindex-err.js new file mode 100644 index 0000000000..e151328249 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-set-lastindex-err.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: > + Behavior when error thrown while setting `lastIndex` property of splitter +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + b. ReturnIfAbrupt(setStatus). +features: [Symbol.split, Symbol.species] +---*/ + +var callCount = 0; +var obj = { + constructor: function() {} +}; +obj.constructor[Symbol.species] = function() { + return { + set lastIndex(_) { + throw new Test262Error(); + }, + exec: function() { + callCount += 1; + } + }; +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.split].call(obj, 'a'); +}); + +assert.sameValue(callCount, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-set-lastindex-match.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-set-lastindex-match.js new file mode 100644 index 0000000000..93a8cc0113 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-set-lastindex-match.js @@ -0,0 +1,51 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Setting `lastIndex` property of splitter after a match +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + c. Let z be RegExpExec(splitter, S). + [...] + f. Else z is not null, + i. Let e be ToLength(Get(splitter, "lastIndex")). + [...] + iv. Else e ≠ p, + [...] + 6. Let p be e. + [...] + 12. Let q be p. +features: [Symbol.split, Symbol.species] +---*/ + +var obj = { + constructor: function() {} +}; +var lastIndex = 0; +var indices = ''; +var fakeRe = { + set lastIndex(val) { + lastIndex = val; + indices += val + ','; + }, + get lastIndex() { + return lastIndex; + }, + exec: function() { + lastIndex += 1; + return ['a']; + } +}; +obj.constructor[Symbol.species] = function() { + return fakeRe; +}; + +RegExp.prototype[Symbol.split].call(obj, 'abcd'); + +assert.sameValue(indices, '0,1,2,3,'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-set-lastindex-no-match.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-set-lastindex-no-match.js new file mode 100644 index 0000000000..a40a87132f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-set-lastindex-no-match.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Setting `lastIndex` property of splitter after a failed match +info: | + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + [...] + e. If z is null, let q be AdvanceStringIndex(S, q, unicodeMatching). + [...] +features: [Symbol.split, Symbol.species] +---*/ + +var obj = { + constructor: function() {} +}; +var indices = ''; +var fakeRe = { + set lastIndex(val) { + indices += val + ','; + }, + exec: function() { + return null; + } +}; +obj.constructor[Symbol.species] = function() { + return fakeRe; +}; + +RegExp.prototype[Symbol.split].call(obj, 'abcd'); + +assert.sameValue(indices, '0,1,2,3,'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-trailing-chars.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-trailing-chars.js new file mode 100644 index 0000000000..6d1f6d3830 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/str-trailing-chars.js @@ -0,0 +1,24 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.11 +description: Characters after the final match are appended to the result +info: | + [...] + 25. Let T be a String value equal to the substring of S consisting of the + elements at indices p (inclusive) through size (exclusive). + 26. Assert: The following call will never result in an abrupt completion. + 27. Perform CreateDataProperty(A, ToString(lengthA), T ). + 28. Return A. +features: [Symbol.split] +---*/ + +var result = /d/[Symbol.split]('abcdefg'); + +assert(Array.isArray(result)); +assert.sameValue(result.length, 2); +assert.sameValue(result[0], 'abc'); +assert.sameValue(result[1], 'efg'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/this-val-non-obj.js new file mode 100644 index 0000000000..8afd822474 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/this-val-non-obj.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: The `this` value must be an object +es6id: 21.2.5.11 +info: | + 1. Let rx be the this value. + 2. If Type(rx) is not Object, throw a TypeError exception. +features: [Symbol.split] +---*/ + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(undefined); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(null); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(true); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call('string'); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(Symbol.split); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.split].call(86); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/u-lastindex-adv-thru-failure.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/u-lastindex-adv-thru-failure.js new file mode 100644 index 0000000000..e73f1b9c0d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/u-lastindex-adv-thru-failure.js @@ -0,0 +1,30 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + lastIndex is advanced according to width of astral symbols following match failure +es6id: 21.2.5.11 +info: | + 21.2.5.11 RegExp.prototype [ @@split ] ( string, limit ) + + [...] + 7. Let flags be ToString(Get(rx, "flags")). + 8. ReturnIfAbrupt(flags). + 9. If flags contains "u", let unicodeMatching be true. + 10. Else, let unicodeMatching be false. + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + b. ReturnIfAbrupt(setStatus). + c. Let z be RegExpExec(splitter, S). + d. ReturnIfAbrupt(z). + e. If z is null, let q be AdvanceStringIndex(S, q, unicodeMatching). +features: [Symbol.split] +---*/ + +var result = /\udf06/u[Symbol.split]('\ud834\udf06'); + +assert.sameValue(result.length, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/u-lastindex-adv-thru-match.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/u-lastindex-adv-thru-match.js new file mode 100644 index 0000000000..5bb444eaaf --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.split/u-lastindex-adv-thru-match.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + lastIndex is advanced according to width of astral symbols following match success +es6id: 21.2.5.11 +info: | + 21.2.5.11 RegExp.prototype [ @@split ] ( string, limit ) + + [...] + 7. Let flags be ToString(Get(rx, "flags")). + 8. ReturnIfAbrupt(flags). + 9. If flags contains "u", let unicodeMatching be true. + 10. Else, let unicodeMatching be false. + [...] + 24. Repeat, while q < size + a. Let setStatus be Set(splitter, "lastIndex", q, true). + b. ReturnIfAbrupt(setStatus). + c. Let z be RegExpExec(splitter, S). + d. ReturnIfAbrupt(z). + e. If z is null, let q be AdvanceStringIndex(S, q, unicodeMatching). + f. Else z is not null, + i. Let e be ToLength(Get(splitter, "lastIndex")). + ii. ReturnIfAbrupt(e). + iii. If e = p, let q be AdvanceStringIndex(S, q, unicodeMatching). +features: [Symbol.split] +---*/ + +var result = /./u[Symbol.split]('\ud834\udf06'); + +assert.sameValue(result.length, 2); +assert.sameValue(result[0], ''); +assert.sameValue(result[1], ''); + +reportCompare(0, 0); |