diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/RegExp/prototype')
524 files changed, 17301 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/15.10.6.js b/js/src/tests/test262/built-ins/RegExp/prototype/15.10.6.js new file mode 100644 index 0000000000..80dbe9887a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/15.10.6.js @@ -0,0 +1,13 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 15.10.6 +description: RegExp.prototype is itself a not RegExp +---*/ + + var s = Object.prototype.toString.call(RegExp.prototype); + +assert.sameValue(s, '[object Object]', 's'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A1.js b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A1.js new file mode 100644 index 0000000000..04d04f3210 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A1.js @@ -0,0 +1,11 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp has property prototype +es5id: 15.10.5.1_A1 +description: Checking RegExp.prototype property +---*/ +assert.sameValue(RegExp.hasOwnProperty('prototype'), true, 'RegExp.hasOwnProperty(\'prototype\') must return true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A2.js b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A2.js new file mode 100644 index 0000000000..3ae4b9d1bd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A2.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype property has the attribute DontEnum +es5id: 15.10.5.1_A2 +description: Checking if enumerating the RegExp.prototype property fails +---*/ +assert.sameValue(RegExp.hasOwnProperty('prototype'), true, 'RegExp.hasOwnProperty(\'prototype\') must return true'); + +assert.sameValue( + RegExp.propertyIsEnumerable('prototype'), + false, + 'RegExp.propertyIsEnumerable(\'prototype\') must return false' +); + +var count=0; +for (var p in RegExp){ + if (p==="prototype") { + count++; + } +} + +assert.sameValue(count, 0, 'The value of count is expected to be 0'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A3.js b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A3.js new file mode 100644 index 0000000000..d88e80882e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A3.js @@ -0,0 +1,30 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype property has the attribute DontDelete +es5id: 15.10.5.1_A3 +description: Checking if deleting the RegExp.prototype property fails +includes: [propertyHelper.js] +---*/ +assert.sameValue(RegExp.hasOwnProperty('prototype'), true); + +verifyNotConfigurable(RegExp, "prototype"); + +try { + assert.sameValue(delete RegExp.prototype, false); +} catch (e) { + if (e instanceof Test262Error) { + throw e; + } + assert(e instanceof TypeError); +} + +if (RegExp.hasOwnProperty('prototype') !== true) { + throw new Test262Error('#2: delete RegExp.prototype; RegExp.hasOwnProperty(\'prototype\') === true'); +} + +// TODO: Convert to verifyProperty() format. +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A4.js b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A4.js new file mode 100644 index 0000000000..f55d12ffb5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.5.1_A4.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype property has the attribute ReadOnly +es5id: 15.10.5.1_A4 +description: Checking if varying the RegExp.prototype property fails +includes: [propertyHelper.js] +---*/ +assert.sameValue(RegExp.hasOwnProperty('prototype'), true, 'RegExp.hasOwnProperty(\'prototype\') must return true'); + +var __obj = RegExp.prototype; + +verifyNotWritable(RegExp, "prototype", null, function(){return "shifted";}); + +assert.sameValue(RegExp.prototype, __obj, 'The value of RegExp.prototype is expected to equal the value of __obj'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6.1_A1_T1.js b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6.1_A1_T1.js new file mode 100644 index 0000000000..00da30eab9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6.1_A1_T1.js @@ -0,0 +1,17 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The initial value of RegExp.prototype.constructor is the built-in RegExp + constructor +es5id: 15.10.6.1_A1_T1 +description: Compare RegExp.prototype.constructor with RegExp +---*/ +assert.sameValue( + RegExp.prototype.constructor, + RegExp, + 'The value of RegExp.prototype.constructor is expected to equal the value of RegExp' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6.1_A1_T2.js b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6.1_A1_T2.js new file mode 100644 index 0000000000..01dada3d9e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6.1_A1_T2.js @@ -0,0 +1,30 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The initial value of RegExp.prototype.constructor is the built-in RegExp + constructor +es5id: 15.10.6.1_A1_T2 +description: > + Compare instance.constructor !== RegExp, where instance is new + RegExp.prototype.constructor +---*/ + +var __FACTORY = RegExp.prototype.constructor; + +var __instance = new __FACTORY; + +assert.sameValue( + __instance instanceof RegExp, + true, + 'The result of evaluating (__instance instanceof RegExp) is expected to be true' +); + +assert.sameValue( + __instance.constructor, + RegExp, + 'The value of __instance.constructor is expected to equal the value of RegExp' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6_A1_T1.js b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6_A1_T1.js new file mode 100644 index 0000000000..c7c472c997 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6_A1_T1.js @@ -0,0 +1,17 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The value of the internal [[Prototype]] property of the RegExp prototype + object is the Object prototype +es5id: 15.10.6_A1_T1 +description: Checking Object.prototype.isPrototypeOf(RegExp.prototype) +---*/ +assert.sameValue( + Object.prototype.isPrototypeOf(RegExp.prototype), + true, + 'Object.prototype.isPrototypeOf(RegExp.prototype) must return true' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6_A1_T2.js b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6_A1_T2.js new file mode 100644 index 0000000000..9de66ca246 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/S15.10.6_A1_T2.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The value of the internal [[Prototype]] property of the RegExp prototype + object is the Object prototype +es5id: 15.10.6_A1_T2 +description: > + Add new property to Object.prototype and check it of + RegExp.prototype +---*/ + +Object.prototype.indicator = 1; + +assert.sameValue(RegExp.prototype.indicator, 1, 'The value of RegExp.prototype.indicator is expected to be 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-coerce-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-coerce-lastindex.js new file mode 100644 index 0000000000..1de99223f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-coerce-lastindex.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Type coercion of `lastIndex` property value +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 8. Else, let lastIndex be ? ToLength(? Get(R, "lastIndex")). +features: [Symbol.match] +---*/ + +var r = /./y; +var result; + +r.lastIndex = '1.9'; + +result = r[Symbol.match]('abc'); + +assert.notSameValue(result, null); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 'b'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-g-set-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-g-set-lastindex-err.js new file mode 100644 index 0000000000..d4954c4915 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-g-set-lastindex-err.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: > + Behavior when error thrown while setting `lastIndex` after a match failure +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 3. Let length be the number of code units in S. + [...] + 11. Let matchSucceeded be false. + 12. Repeat, while matchSucceeded is false + a. If lastIndex > length, then + i. If global is true or sticky is true, then + 1. Perform ? Set(R, "lastIndex", 0, true). + ii. Return null. +features: [Symbol.match] +---*/ + +var r = /a/g; +Object.defineProperty(r, 'lastIndex', { writable: false }); + +assert.throws(TypeError, function() { + r[Symbol.match]('b'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-g-set-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-g-set-lastindex.js new file mode 100644 index 0000000000..efdcc6c304 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-g-set-lastindex.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Setting `lastIndex` to `0` after a match failure +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 3. Let length be the number of code units in S. + [...] + 11. Let matchSucceeded be false. + 12. Repeat, while matchSucceeded is false + a. If lastIndex > length, then + i. If global is true or sticky is true, then + 1. Perform ? Set(R, "lastIndex", 0, true). + ii. Return null. +features: [Symbol.match] +---*/ + +var r = /a/g; +r.lastIndex = 3; + +r[Symbol.match]('b'); + +assert.sameValue(r.lastIndex, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-return-val.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-return-val.js new file mode 100644 index 0000000000..4271bcb800 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-return-val.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. + +/*--- +description: Return value after a match failure +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 3. Let length be the number of code units in S. + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 14. Let matchSucceeded be false. + 15. Repeat, while matchSucceeded is false + a. If lastIndex > length, then + i. Let setStatus be Set(R, "lastIndex", 0, true). + ii. ReturnIfAbrupt(setStatus). + iii. Return null. +features: [Symbol.match] +---*/ + +var r = /a/; + +assert.sameValue(r[Symbol.match]('b'), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-return-val.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-return-val.js new file mode 100644 index 0000000000..09a52e14bb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-return-val.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. + +/*--- +description: Return value after a "sticky" match failure +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 14. Let matchSucceeded be false. + 15. Repeat, while matchSucceeded is false + [...] + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). + 2. ReturnIfAbrupt(setStatus). + 3. Return null. +features: [Symbol.match] +---*/ + +assert.sameValue(/a/y[Symbol.match]('ba'), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex-err.js new file mode 100644 index 0000000000..5942f5a220 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex-err.js @@ -0,0 +1,44 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Behavior when error thrown while setting `lastIndex` after a "sticky" match + failure +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 14. Let matchSucceeded be false. + 15. Repeat, while matchSucceeded is false + [...] + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). + 2. ReturnIfAbrupt(setStatus). +features: [Symbol.match] +---*/ + +var r = /a/y; + +Object.defineProperty(r, 'lastIndex', { writable: false }); + +assert.throws(TypeError, function() { + r[Symbol.match]('ba'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex.js new file mode 100644 index 0000000000..dae445fba7 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-failure-y-set-lastindex.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Setting `lastIndex` to `0` after a "sticky" match failure +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 14. Let matchSucceeded be false. + 15. Repeat, while matchSucceeded is false + [...] + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). +features: [Symbol.match] +---*/ + +var r = /a/y; +r.lastIndex = 1; + +r[Symbol.match]('aba'); + +assert.sameValue(r.lastIndex, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-infer-unicode.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-infer-unicode.js new file mode 100644 index 0000000000..4b54342f63 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-infer-unicode.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Extended unicode support is determined by internal slot (not `unicode` + property) +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 12. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 13. If flags contains "u", let fullUnicode be true, else let fullUnicode be + false. +features: [Symbol.match] +---*/ + +var r; + +r = /\udf06/; +Object.defineProperty(r, 'unicode', { value: true }); +assert.notSameValue(r[Symbol.match]('\ud834\udf06'), null); + +r = /\udf06/u; +Object.defineProperty(r, 'unicode', { value: false }); +assert.sameValue(r[Symbol.match]('\ud834\udf06'), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex-err.js new file mode 100644 index 0000000000..69a5517173 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex-err.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. + +/*--- +description: > + Behavior when error thrown while setting `lastIndex` after a "global" match + success +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 18. If global is true or sticky is true, + a. Let setStatus be Set(R, "lastIndex", e, true). + b. ReturnIfAbrupt(setStatus). +features: [Symbol.match] +---*/ + +var r = /b/g; +var callCount = 0; + +// Because this test speicifically concerns the behavior when setting +// "lastIndex" following a match, care must be taken to avoid triggering a +// similar error when `lastIndex` is initially set to `0` earlier in the +// algorithm. +// +// Because the `lastIndex` property is non-configurable, this cannot be +// accomplished with a simple "set" accessor function. +// +// Defer disabling modification of `lastIndex` until after the "this" value's +// `exec` property has been accessed, ensuring that the resultant abrupt +// completion originates from the second property modification. +Object.defineProperty(r, 'exec', { + get: function() { + Object.defineProperty(r, 'lastIndex', { writable: false }); + } +}); + +assert.throws(TypeError, function() { + r[Symbol.match]('abc'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex.js new file mode 100644 index 0000000000..dc8548afdf --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-g-set-lastindex.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: Setting `lastIndex` after a "global" match success +esid: sec-regexp.prototype-@@match +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 5. Let flags be the value of R's [[OriginalFlags]] internal slot. + 6. If flags contains "g", let global be true, else let global be false. + [...] + 16. Let e be r's endIndex value. + [...] + 18. If global is true or sticky is true, + a. Let setStatus be Set(R, "lastIndex", e, true). +features: [Symbol.match] +---*/ + +// The conflicting values for the "global" flag are necessary to observe the +// final modification of `lastIndex` in RegExpBuiltinExec +var r = /b/g; +Object.defineProperty(r, 'global', { value: false }); + +r[Symbol.match]('abc'); + +assert.sameValue(r.lastIndex, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-return-val-groups.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-return-val-groups.js new file mode 100644 index 0000000000..86d8aaa53f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-return-val-groups.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. + +/*--- +description: Return value after successful match with capturing groups +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 20. Let A be ArrayCreate(n + 1). + [...] + 24. Perform CreateDataProperty(A, "index", matchIndex). + 25. Perform CreateDataProperty(A, "input", S). + 26. Let matchedSubstr be the matched substring (i.e. the portion of S + between offset lastIndex inclusive and offset e exclusive). + 27. Perform CreateDataProperty(A, "0", matchedSubstr). + 28. For each integer i such that i > 0 and i ≤ n + [...] + d. Else, fullUnicode is false, + i. Assert: captureI is a List of code units. + ii. Let capturedValue be a string consisting of the code units of + captureI. + e. Perform CreateDataProperty(A, ToString(i) , capturedValue). + [...] + 29. Return A. +features: [Symbol.match] +---*/ + +var result = /b(.).(.)./[Symbol.match]('abcdefg'); + +assert(Array.isArray(result)); +assert.sameValue(result.index, 1); +assert.sameValue(result.input, 'abcdefg'); +assert.sameValue(result.length, 3); +assert.sameValue(result[0], 'bcdef'); +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.match/builtin-success-return-val.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-return-val.js new file mode 100644 index 0000000000..cf833f4fab --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-return-val.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Return value after successful match +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 20. Let A be ArrayCreate(n + 1). + [...] + 24. Perform CreateDataProperty(A, "index", matchIndex). + 25. Perform CreateDataProperty(A, "input", S). + 26. Let matchedSubstr be the matched substring (i.e. the portion of S + between offset lastIndex inclusive and offset e exclusive). + 27. Perform CreateDataProperty(A, "0", matchedSubstr). + [...] + 29. Return A. +features: [Symbol.match] +---*/ + +var result = /b./[Symbol.match]('abcd'); + +assert(Array.isArray(result)); +assert.sameValue(result.index, 1); +assert.sameValue(result.input, 'abcd'); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 'bc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-u-return-val-groups.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-u-return-val-groups.js new file mode 100644 index 0000000000..e324b49846 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-u-return-val-groups.js @@ -0,0 +1,53 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Return value after successful match with extended unicode capturing groups +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 20. Let A be ArrayCreate(n + 1). + [...] + 24. Perform CreateDataProperty(A, "index", matchIndex). + 25. Perform CreateDataProperty(A, "input", S). + 26. Let matchedSubstr be the matched substring (i.e. the portion of S + between offset lastIndex inclusive and offset e exclusive). + 27. Perform CreateDataProperty(A, "0", matchedSubstr). + 28. For each integer i such that i > 0 and i ≤ n + [...] + c. Else if fullUnicode is true, + i. Assert: captureI is a List of code points. + ii. Let capturedValue be a string whose code units are the + UTF16Encoding (10.1.1) of the code points of captureI. + [...] + e. Perform CreateDataProperty(A, ToString(i) , capturedValue). + [...] + 29. Return A. +features: [Symbol.match] +---*/ + +var result = /b(.).(.)./u[Symbol.match]('ab\ud834\udf06defg'); + +assert(Array.isArray(result)); +assert.sameValue(result.index, 1); +assert.sameValue(result.input, 'ab\ud834\udf06defg'); +assert.sameValue(result.length, 3); +assert.sameValue(result[0], 'b\ud834\udf06def'); +assert.sameValue(result[1], '\ud834\udf06'); +assert.sameValue(result[2], 'e'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex-err.js new file mode 100644 index 0000000000..d48ba62333 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex-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. + +/*--- +description: > + Behavior when error thrown while setting `lastIndex` after a "sticky" match + success +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 18. If global is true or sticky is true, + a. Let setStatus be Set(R, "lastIndex", e, true). + b. ReturnIfAbrupt(setStatus). +features: [Symbol.match] +---*/ + +var r = /a/y; + +Object.defineProperty(r, 'lastIndex', { writable: false }); + +assert.throws(TypeError, function() { + r[Symbol.match]('a'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex.js new file mode 100644 index 0000000000..a2eff7604e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-success-y-set-lastindex.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Setting `lastIndex` after a "sticky" match success +es6id: 21.2.5.6 +info: | + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 16. Let e be r's endIndex value. + [...] + 18. If global is true or sticky is true, + a. Let setStatus be Set(R, "lastIndex", e, true). +features: [Symbol.match] +---*/ + +var r = /a/y; + +r[Symbol.match]('a'); + +assert.sameValue(r.lastIndex, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-y-coerce-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-y-coerce-lastindex-err.js new file mode 100644 index 0000000000..9ef965f7d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/builtin-y-coerce-lastindex-err.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: Behavior when coercion of `lastIndex` attribute throws an error +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 7. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 7. If global is false and sticky is false, let lastIndex be 0. + 8. Else, let lastIndex be ? ToLength(? Get(R, "lastIndex")). +features: [Symbol.match] +---*/ + +var r = /./y; +r.lastIndex = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + r[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/coerce-arg-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/coerce-arg-err.js new file mode 100644 index 0000000000..6c7ede9f51 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/coerce-arg-err.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Behavior when error thrown during string coercion of first parameter +es6id: 21.2.5.6 +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 3. Let S be ToString(string) + 4. ReturnIfAbrupt(S). +features: [Symbol.match] +---*/ + +var str = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + /./[Symbol.match](str); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/coerce-arg.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/coerce-arg.js new file mode 100644 index 0000000000..5b3ef902b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/coerce-arg.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: String coercion of first parameter +es6id: 21.2.5.6 +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 3. Let S be ToString(string) + [...] +features: [Symbol.match] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + toString: function() { + return 'toString value'; + } +}; + +assert.notSameValue(/toString value/[Symbol.match](obj), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/coerce-global.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/coerce-global.js new file mode 100644 index 0000000000..82750300d6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/coerce-global.js @@ -0,0 +1,87 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Boolean coercion of `global` property +esid: sec-regexp.prototype-@@match +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 4. Let global be ToBoolean(? Get(rx, "global")). + 5. If global is false, then + a. Return ? RegExpExec(rx, S). + 6. Else global is true, + a. Let fullUnicode be ToBoolean(? Get(rx, "unicode")). + [...] +features: [Symbol.match] +---*/ + +var exec = function() { + execCount += 1; + if (execCount === 1) { + return ['']; + } + return null; +}; +var r, result, execCount; + +r = /a/g; +r.exec = exec; +Object.defineProperty(r, 'global', { writable: true }); + +execCount = 0; +r.global = undefined; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 1, 'value: undefined'); + +execCount = 0; +r.global = null; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 1, 'value: null'); + +execCount = 0; +r.global = false; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 1, 'value: false'); + +execCount = 0; +r.global = NaN; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 1, 'value: NaN'); + +execCount = 0; +r.global = 0; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 1, 'value: 0'); + +execCount = 0; +r.global = ''; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 1, 'value: ""'); + +r = /a/; +r.exec = exec; +Object.defineProperty(r, 'global', { writable: true }); + +r.global = true; +execCount = 0; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 2, 'value: true'); + +r.global = 86; +execCount = 0; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 2, 'value: 86'); + +r.global = Symbol.match; +execCount = 0; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 2, 'value: Symbol.match'); + +r.global = {}; +execCount = 0; +r[Symbol.match]('aa'); +assert.sameValue(execCount, 2, 'value: {}'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-err.js new file mode 100644 index 0000000000..9d6ba24730 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-err.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: Behavior when error is thrown by `exec` method +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 5. If IsCallable(exec) is true, then + a. Let result be Call(exec, R, «S»). + b. ReturnIfAbrupt(result). +features: [Symbol.match] +---*/ + +var r = /./; + +r.exec = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + r[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-invocation.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-invocation.js new file mode 100644 index 0000000000..9322ef4d81 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-invocation.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Invocation of `exec` method +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 5. If IsCallable(exec) is true, then + a. Let result be Call(exec, R, «S»). +features: [Symbol.match] +---*/ + +var r = /./; +var callCount = 0; +var arg = { + toString: function() { + return 'string form'; + } +}; +var thisValue, args; + +r.exec = function() { + thisValue = this; + args = arguments; + callCount += 1; + return null; +}; + +r[Symbol.match](arg); + +assert.sameValue(callCount, 1); +assert.sameValue(thisValue, r); +assert.sameValue(args.length, 1); +assert.sameValue(args[0], 'string form'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-return-type-invalid.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-return-type-invalid.js new file mode 100644 index 0000000000..b173aee5d7 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-return-type-invalid.js @@ -0,0 +1,58 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Behavior when `exec` method returns value of invalid type +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 5. If IsCallable(exec) is true, then + a. Let result be Call(exec, R, «S»). + b. ReturnIfAbrupt(result). + c. If Type(result) is neither Object or Null, throw a TypeError + exception. +features: [Symbol.match] +---*/ + +var r = /./; +var retValue; +r.exec = function() { + return retValue; +}; + +// Explicitly assert the method's presence to avoid false positives (i.e. +// TypeErrors thrown by invoking an undefined reference). +assert.sameValue(typeof r[Symbol.match], 'function'); + +retValue = undefined; +assert.throws(TypeError, function() { + r[Symbol.match](''); +}); + +retValue = true; +assert.throws(TypeError, function() { + r[Symbol.match](''); +}); + +retValue = 'string'; +assert.throws(TypeError, function() { + r[Symbol.match](''); +}); + +retValue = Symbol.match; +assert.throws(TypeError, function() { + r[Symbol.match](''); +}); + +retValue = 86; +assert.throws(TypeError, function() { + r[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-return-type-valid.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-return-type-valid.js new file mode 100644 index 0000000000..9a73b01290 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/exec-return-type-valid.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: Behavior when `exec` method returns value of valid type +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 5. If IsCallable(exec) is true, then + a. Let result be Call(exec, R, «S»). + b. ReturnIfAbrupt(result). + c. If Type(result) is neither Object or Null, throw a TypeError + exception. + d. Return result. +features: [Symbol.match] +---*/ + +var r = /./; +var retValue; +r.exec = function() { + return retValue; +}; + +retValue = null; +assert.sameValue(r[Symbol.match](''), retValue); + +retValue = {}; +assert.sameValue(r[Symbol.match](''), retValue); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/flags-tostring-error.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/flags-tostring-error.js new file mode 100644 index 0000000000..57faa2b888 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/flags-tostring-error.js @@ -0,0 +1,45 @@ +// Copyright (C) 2022 Richard Gibson. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Errors thrown by converting `flags` to string are forwarded to the runtime +esid: sec-regexp.prototype-@@match +info: | + 1. Let _rx_ be the *this* value. + 2. If Type(_rx_) is not Object, throw a *TypeError* exception. + 3. Let _S_ be ? ToString(_string_). + 4. Let _flags_ be ? ToString(? Get(_rx_, *"flags"*)). +features: [Symbol.match] +---*/ + +function CustomError() {} +var toStringThrows = { + [Symbol.toPrimitive](hint) { + if (hint === 'string') { + throw new CustomError(); + } + throw new Test262Error('@@toPrimitive should be called with hint "string"'); + }, + get toString() { throw new Test262Error('toString property should not be read'); }, + get valueOf() { throw new Test262Error('valueOf property should not be read'); } +}; + +var re = /./; +Object.defineProperties(re, { + flags: { + get() { return toStringThrows; } + }, + global: { + get() { throw new Test262Error('global property should not be read'); } + }, + unicode: { + get() { throw new Test262Error('unicode property should not be read'); } + } +}); + +assert.throws(CustomError, function() { + re[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-coerce-result-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-coerce-result-err.js new file mode 100644 index 0000000000..72b4033d09 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-coerce-result-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. + +/*--- +description: > + Behavior when error is thrown while coercing `0` property of match result +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + [...] + iv. Else result is not null, + 1. Let matchStr be ToString(Get(result, "0")). + 2. ReturnIfAbrupt(matchStr). +features: [Symbol.match] +---*/ + +var r = /./g; +r.exec = function() { + return { + 0: { + toString: function() { + throw new Test262Error(); + } + } + }; +}; + +assert.throws(Test262Error, function() { + r[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-get-exec-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-get-exec-err.js new file mode 100644 index 0000000000..da260f89ca --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-get-exec-err.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Behavior when there is an error thrown while accessing the `exec` method of + "global" instances +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + ii. ReturnIfAbrupt(result). + + ES6 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 3. Let exec be Get(R, "exec"). + 4. ReturnIfAbrupt(exec). +features: [Symbol.match] +---*/ + +var r = { flags: 'g', global: true }; +Object.defineProperty(r, 'exec', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.match].call(r, ''); +}); + +assert.sameValue(r.lastIndex, 0, 'Error thrown after setting `lastIndex`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-get-result-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-get-result-err.js new file mode 100644 index 0000000000..00e26c5aec --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-get-result-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. + +/*--- +description: > + Behavior when error is thrown while accessing `0` property of match result +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + [...] + iv. Else result is not null, + 1. Let matchStr be ToString(Get(result, "0")). + 2. ReturnIfAbrupt(matchStr). +features: [Symbol.match] +---*/ + +var r = /./g; +var poisonedZero = { + get 0() { + throw new Test262Error(); + } +}; + +r.exec = function() { + return poisonedZero; +}; + +assert.throws(Test262Error, function() { + r[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-init-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-init-lastindex-err.js new file mode 100644 index 0000000000..cd214c8d58 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-init-lastindex-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. + +/*--- +description: Behavior when `lastIndex` cannot be set on "global" instances +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + c. Let setStatus be Set(rx, "lastIndex", 0, true). + d. ReturnIfAbrupt(setStatus). +features: [Symbol.match] +---*/ + +var r = /./g; +Object.defineProperty(r, 'lastIndex', { writable: false }); + +assert.throws(TypeError, function() { + r[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-init-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-init-lastindex.js new file mode 100644 index 0000000000..f407004ff4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-init-lastindex.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Initializing the value of `lastIndex` on "global" instances +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + c. Let setStatus be Set(rx, "lastIndex", 0, true). +features: [Symbol.match] +---*/ + +var r = /./g; + +r.lastIndex = 1; + +assert.notSameValue(r[Symbol.match]('a'), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-empty-advance-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-empty-advance-lastindex.js new file mode 100644 index 0000000000..40787a069e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-empty-advance-lastindex.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. + +/*--- +description: > + lastIndex is explicitly advanced for zero-length matches for "global" + instances +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + [...] + iv. Else result is not null, + [...] + 5. If matchStr is the empty String, then + [...] + c. Let nextIndex be AdvanceStringIndex(S, thisIndex, + fullUnicode). + d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). + e. ReturnIfAbrupt(setStatus). + 6. Increment n. +features: [Symbol.match] +---*/ + +var result = /(?:)/g[Symbol.match]('abc'); + +assert.notSameValue(result, null); +assert.sameValue(result.length, 4); +assert.sameValue(result[0], ''); +assert.sameValue(result[1], ''); +assert.sameValue(result[2], ''); +assert.sameValue(result[3], ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-empty-coerce-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-empty-coerce-lastindex-err.js new file mode 100644 index 0000000000..8b11e37cc9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-empty-coerce-lastindex-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. + +/*--- +description: > + Behavior when error is thrown while type coercing `lastIndex` of zero-width + match +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + [...] + iv. Else result is not null, + 1. Let matchStr be ToString(Get(result, "0")). + [...] + 5. If matchStr is the empty String, then + a. Let thisIndex be ToLength(Get(rx, "lastIndex")). + b. ReturnIfAbrupt(thisIndex). +features: [Symbol.match] +---*/ + +var r = /./g; +var nextMatch; + +r.exec = function() { + var thisMatch = nextMatch; + if (thisMatch === null) { + return null; + } + nextMatch = null; + return { + get 0() { + r.lastIndex = { + valueOf: function() { + throw new Test262Error(); + } + }; + return thisMatch; + } + }; +}; + +nextMatch = ''; +assert.throws(Test262Error, function() { + r[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-empty-set-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-empty-set-lastindex-err.js new file mode 100644 index 0000000000..f767a612c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-empty-set-lastindex-err.js @@ -0,0 +1,49 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Behavior when error is thrown while setting `lastIndex` after a zero-width + match +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + [...] + iv. Else result is not null, + 1. Let matchStr be ToString(Get(result, "0")). + [...] + 5. If matchStr is the empty String, then + [...] + d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). + e. ReturnIfAbrupt(setStatus). +features: [Symbol.match] +---*/ + +var exec = function() { + var thisMatch = nextMatch; + if (thisMatch === null) { + return null; + } + nextMatch = null; + return { + get 0() { + Object.defineProperty(r, 'lastIndex', { writable: false }); + return thisMatch; + } + }; +}; +var r, nextMatch; + +r = /./g; +r.exec = exec; +nextMatch = ''; +assert.throws(TypeError, function() { + r[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-no-coerce-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-no-coerce-lastindex.js new file mode 100644 index 0000000000..3417f6cb3b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-no-coerce-lastindex.js @@ -0,0 +1,49 @@ +// Copyright (C) 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + The `lastIndex` property is not coerced for a non-empty string match +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + [...] + iv. Else result is not null, + 1. Let matchStr be ToString(Get(result, "0")). + [...] + 5. If matchStr is the empty String, then + a. Let thisIndex be ToLength(Get(rx, "lastIndex")). + b. ReturnIfAbrupt(thisIndex). +features: [Symbol.match] +---*/ + +var r = /./g; +var nextMatch; + +r.exec = function() { + var thisMatch = nextMatch; + if (thisMatch === null) { + return null; + } + nextMatch = null; + return { + get 0() { + r.lastIndex = { + valueOf: function() { + throw new Test262Error('This function should not be invoked.'); + } + }; + return thisMatch; + } + }; +}; + +nextMatch = 'a non-empty string'; +r[Symbol.match](''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-no-set-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-no-set-lastindex.js new file mode 100644 index 0000000000..7ca7374884 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-match-no-set-lastindex.js @@ -0,0 +1,45 @@ +// Copyright (C) 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: The `lastIndex` is not set after a non-zero-width match +es6id: 21.2.5.6 +info: | + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + [...] + iv. Else result is not null, + 1. Let matchStr be ToString(Get(result, "0")). + [...] + 5. If matchStr is the empty String, then + [...] + d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). + e. ReturnIfAbrupt(setStatus). +features: [Symbol.match] +---*/ + +var exec = function() { + var thisMatch = nextMatch; + if (thisMatch === null) { + return null; + } + nextMatch = null; + return { + get 0() { + Object.defineProperty(r, 'lastIndex', { writable: false }); + return thisMatch; + } + }; +}; +var r, nextMatch; + +r = /./g; +r.exec = exec; +nextMatch = 'a non-empty string'; +r[Symbol.match](''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-success-return-val.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-success-return-val.js new file mode 100644 index 0000000000..b5b50c7b9e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-success-return-val.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. + +/*--- +description: Return value when matches occur with the `global` flag +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + [...] + 8. Else global is true, + [...] + e. Let A be ArrayCreate(0). + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + ii. ReturnIfAbrupt(result). + iii. If result is null, then + 1. If n=0, return null. + 2. Else, return A. +features: [Symbol.match] +---*/ + +var result = /.(.)./g[Symbol.match]('abcdefghi'); + +assert(Array.isArray(result)); + +assert( + !Object.prototype.hasOwnProperty.call(result, 'index'), + 'Does not define an `index` "own" property' +); +assert.sameValue( + result.index, undefined, 'Does not define an `index` property' +); +assert( + !Object.prototype.hasOwnProperty.call(result, 'input'), + 'Does not define an `input` "own" property' +); +assert.sameValue( + result.input, undefined, 'Does not define an `input` property' +); + +assert.sameValue(result.length, 3); +assert.sameValue(result[0], 'abc'); +assert.sameValue(result[1], 'def'); +assert.sameValue(result[2], 'ghi'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-zero-matches.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-zero-matches.js new file mode 100644 index 0000000000..2c60e877f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/g-zero-matches.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Return value when no matches occur with the `global` flag +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + ii. ReturnIfAbrupt(result). + iii. If result is null, then + 1. If n=0, return null. +features: [Symbol.match] +---*/ + +assert.sameValue(/a/g[Symbol.match]('b'), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-exec-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-exec-err.js new file mode 100644 index 0000000000..aabcd9a3e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-exec-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. + +/*--- +description: Behavior when error is thrown while accessing `exec` property +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 3. Let exec be Get(R, "exec"). + 4. ReturnIfAbrupt(exec). +features: [Symbol.match] +---*/ + +var r = /./; + +Object.defineProperty(r, 'exec', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + r[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-flags-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-flags-err.js new file mode 100644 index 0000000000..e45a8d0789 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-flags-err.js @@ -0,0 +1,34 @@ +// Copyright (C) 2022 Richard Gibson. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Errors thrown by `flags` accessor are forwarded to the runtime +esid: sec-regexp.prototype-@@match +info: | + 1. Let _rx_ be the *this* value. + 2. If Type(_rx_) is not Object, throw a *TypeError* exception. + 3. Let _S_ be ? ToString(_string_). + 4. Let _flags_ be ? ToString(? Get(_rx_, *"flags"*)). +features: [Symbol.match] +---*/ + +function CustomError() {} + +var obj = { + get flags() { + throw new CustomError(); + }, + get global() { + throw new Test262Error('global property should not be read'); + }, + get unicode() { + throw new Test262Error('unicode property should not be read'); + } +}; + +assert.throws(CustomError, function() { + RegExp.prototype[Symbol.match].call(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-global-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-global-err.js new file mode 100644 index 0000000000..22690b007f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-global-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. + +/*--- +description: > + Behavior when error is thrown during retrieval of `global` property +esid: sec-regexp.prototype-@@match +info: | + 1. Let _rx_ be the *this* value. + 2. If Type(_rx_) is not Object, throw a *TypeError* exception. + 3. Let _S_ be ? ToString(_string_). + 4. Let _flags_ be ? ToString(? Get(_rx_, *"flags"*)). + + sec-get-regexp.prototype.flags get RegExp.prototype.flags + 6. Let _global_ be ToBoolean(? Get(_R_, *"global"*)). +features: [Symbol.match] +---*/ + +var re = /./; +Object.defineProperty(re, 'global', { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.match].call(re); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-unicode-error.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-unicode-error.js new file mode 100644 index 0000000000..496d101d4b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/get-unicode-error.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Errors thrown by `unicode` accessor are forwarded to the runtime +esid: sec-regexp.prototype-@@match +info: | + 1. Let _rx_ be the *this* value. + 2. If Type(_rx_) is not Object, throw a *TypeError* exception. + 3. Let _S_ be ? ToString(_string_). + 4. Let _flags_ be ? ToString(? Get(_rx_, *"flags"*)). + + sec-get-regexp.prototype.flags get RegExp.prototype.flags + 14. Let _unicode_ be ToBoolean(? Get(_R_, *"unicode"*)). +features: [Symbol.match] +---*/ + +var nonGlobalRe = /./; +var globalRe = /./g; +var accessor = function() { + throw new Test262Error(); +}; +Object.defineProperty(nonGlobalRe, 'unicode', { + get: accessor +}); +Object.defineProperty(globalRe, 'unicode', { + get: accessor +}); + +assert.throws(Test262Error, function() { + nonGlobalRe[Symbol.match](''); +}); + +assert.throws(Test262Error, function() { + globalRe[Symbol.match](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/length.js new file mode 100644 index 0000000000..ea84d3ce40 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/length.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.6 +description: RegExp.prototype[Symbol.match] `length` property +info: | + ES6 Section 17: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + 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.match] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.match].length, 1); + +verifyNotEnumerable(RegExp.prototype[Symbol.match], 'length'); +verifyNotWritable(RegExp.prototype[Symbol.match], 'length'); +verifyConfigurable(RegExp.prototype[Symbol.match], 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/name.js new file mode 100644 index 0000000000..2c676dba2f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/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.6 +description: RegExp.prototype[Symbol.match] `name` property +info: | + The value of the name property of this function is "[Symbol.match]". + + 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.match] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.match].name, '[Symbol.match]'); + +verifyNotEnumerable(RegExp.prototype[Symbol.match], 'name'); +verifyNotWritable(RegExp.prototype[Symbol.match], 'name'); +verifyConfigurable(RegExp.prototype[Symbol.match], 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/not-a-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/not-a-constructor.js new file mode 100644 index 0000000000..f56be3391f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/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.match] 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.match, arrow-function] +---*/ + +assert.sameValue( + isConstructor(RegExp.prototype[Symbol.match]), + false, + 'isConstructor(RegExp.prototype[Symbol.match]) must return false' +); + +assert.throws(TypeError, () => { + let re = new RegExp(''); new re[Symbol.match](); +}, '`let re = new RegExp(\'\'); new re[Symbol.match]()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/prop-desc.js new file mode 100644 index 0000000000..bfc4b1b68f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/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.6 +description: RegExp.prototype[Symbol.match] 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.match] +---*/ + +verifyNotEnumerable(RegExp.prototype, Symbol.match); +verifyWritable(RegExp.prototype, Symbol.match); +verifyConfigurable(RegExp.prototype, Symbol.match); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/this-val-non-obj.js new file mode 100644 index 0000000000..2c48f0ceeb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/this-val-non-obj.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. + +/*--- +description: The `this` value must be an object +es6id: 21.2.5.6 +info: | + 1. Let rx be the this value. + 2. If Type(rx) is not Object, throw a TypeError exception. +features: [Symbol.match] +---*/ + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.match].call(undefined); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.match].call(null); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.match].call(true); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.match].call('string'); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.match].call(Symbol.match); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.match].call(86); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/this-val-non-regexp.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/this-val-non-regexp.js new file mode 100644 index 0000000000..ec0f62d4ea --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/this-val-non-regexp.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. + +/*--- +description: > + Behavior when invoked on an object without a a [[RegExpMatcher]] internal + slot +es6id: 21.2.5.6 +info: | + [...] + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 5. If IsCallable(exec) is true, then + [...] + d. Return result. + 6. If R does not have a [[RegExpMatcher]] internal slot, throw a TypeError + exception. +features: [Symbol.match] +---*/ + +var objWithExec = { + exec: function() { + return null; + } +}; +var objWithoutExec = {}; + +RegExp.prototype[Symbol.match].call(objWithExec); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.match].call(objWithoutExec); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/u-advance-after-empty.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/u-advance-after-empty.js new file mode 100644 index 0000000000..0b37aa2184 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/u-advance-after-empty.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. + +/*--- +description: lastIndex is advanced according to width of astral symbols +es6id: 21.2.5.6 +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 8. Else global is true, + a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). + [...] + g. Repeat, + [...] + iv. Else result is not null, + [...] + 5. If matchStr is the empty String, then + [...] + c. Let nextIndex be AdvanceStringIndex(S, thisIndex, + fullUnicode). + d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). +features: [Symbol.match] +---*/ + +var match = /^|\udf06/ug[Symbol.match]('\ud834\udf06'); + +assert(match !== null); +assert.sameValue(match.length, 1); +assert.sameValue(match[0], ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-global-return.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-global-return.js new file mode 100644 index 0000000000..2feead0fe2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-global-return.js @@ -0,0 +1,49 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Accumulates consecutive matches when `g` flag is present +es6id: 21.2.5.6 +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + [...] + 8. Else global is true, + [...] + g. Repeat, + i. Let result be RegExpExec(rx, S). + ii. ReturnIfAbrupt(result). + iii. If result is null, then + 1. If n=0, return null. + 2. Else, return A. + [...] + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + [...] + 3. Return null. +features: [Symbol.match] +---*/ + +var result = /a/yg[Symbol.match]('aaba'); + +assert.notSameValue(result, null); +assert.sameValue(result.length, 2); +assert.sameValue(result[0], 'a'); +assert.sameValue(result[1], 'a'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-lastindex-no-write.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-lastindex-no-write.js new file mode 100644 index 0000000000..174a13fccf --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-lastindex-no-write.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Match failure with non-writable `lastIndex` property +es6id: 21.2.5.6 +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). + 2. ReturnIfAbrupt(setStatus). +features: [Symbol.match] +---*/ + +var r = /c/y; +Object.defineProperty(r, 'lastIndex', { + writable: false +}); + +assert.throws(TypeError, function() { + r[Symbol.match]('abc'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-lastindex.js new file mode 100644 index 0000000000..be4f4d0fd0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-lastindex.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Resets the `lastIndex` property to zero after a match failure +es6id: 21.2.5.6 +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). +features: [Symbol.match] +---*/ + +var r = /c/y; +r.lastIndex = 1; + +r[Symbol.match]('abc'); + +assert.sameValue(r.lastIndex, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-return.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-return.js new file mode 100644 index 0000000000..eab1193a87 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-fail-return.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Stops match execution after first match failure +es6id: 21.2.5.6 +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + [...] + 3. Return null. +features: [Symbol.match] +---*/ + +assert.sameValue(/b/y[Symbol.match]('ab'), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-init-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-init-lastindex.js new file mode 100644 index 0000000000..2570ac501a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-init-lastindex.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. + +/*--- +description: Honors initial value of the `lastIndex` property +es6id: 21.2.5.6 +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + 9. ReturnIfAbrupt(sticky). + 10. If global is false and sticky is false, let lastIndex be 0. +features: [Symbol.match] +---*/ + +var r = /./y; +var match; +r.lastIndex = 1; + +match = r[Symbol.match]('abc'); + +assert.notSameValue(match, null); +assert.sameValue(match.length, 1); +assert.sameValue(match[0], 'b'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-set-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-set-lastindex.js new file mode 100644 index 0000000000..a2e70777b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.match/y-set-lastindex.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: Sets the `lastIndex` property to the end index of the first match +es6id: 21.2.5.6 +info: | + 21.2.5.6 RegExp.prototype [ @@match ] ( string ) + + [...] + 5. Let global be ToBoolean(Get(rx, "global")). + 6. ReturnIfAbrupt(global). + 7. If global is false, then + a. Return RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 18. If global is true or sticky is true, + a. Let setStatus be Set(R, "lastIndex", e, true). +features: [Symbol.match] +---*/ + +var r = /abc/y; +r[Symbol.match]('abc'); + +assert.sameValue(r.lastIndex, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-called-once.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-called-once.js new file mode 100644 index 0000000000..4d0888f201 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-called-once.js @@ -0,0 +1,59 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: IsRegExp should only be called once +info: | + RegExp.prototype [ @@matchAll ] ( string ) + 1. Let R be the this value. + [...] + 4. Let C be ? SpeciesConstructor(R, %RegExp%). + 5. Let flags be ? ToString(? Get(R, "flags")). + 6. Let matcher be ? Construct(C, « R, flags »). + + 21.2.3.1 RegExp ( pattern, flags ) + 1. Let patternIsRegExp be ? IsRegExp(pattern). + [...] +features: [Symbol.match, Symbol.matchAll] +---*/ + +var internalCount = 0; +Object.defineProperty(RegExp.prototype, Symbol.match, { + get: function() { + ++internalCount; + return true; + } +}); + +var calls = []; +var o = { + get [Symbol.match]() { + calls.push('get @@match'); + return false; + }, + get flags() { + calls.push('get flags'); + return { + toString() { + calls.push('flags toString'); + return ""; + } + }; + }, +}; + +RegExp.prototype[Symbol.matchAll].call(o, { + toString() { + calls.push('arg toString') + } +}); + +assert.sameValue(0, internalCount); + +assert.sameValue(calls.length, 4); +assert.sameValue(calls[0], 'arg toString'); +assert.sameValue(calls[1], 'get flags'); +assert.sameValue(calls[2], 'flags toString'); +assert.sameValue(calls[3], 'get @@match'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-this-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-this-throws.js new file mode 100644 index 0000000000..528c0cd5ad --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/isregexp-this-throws.js @@ -0,0 +1,28 @@ +// 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 @@match property +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + [...] +features: [Symbol.match, Symbol.matchAll] +---*/ + +var obj = { + get [Symbol.match]() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.matchAll].call(obj, ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/length.js new file mode 100644 index 0000000000..ec522ab2f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.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: RegExp.prototype[Symbol.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: [Symbol.matchAll] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.matchAll].length, 1); + +verifyNotEnumerable(RegExp.prototype[Symbol.matchAll], 'length'); +verifyNotWritable(RegExp.prototype[Symbol.matchAll], 'length'); +verifyConfigurable(RegExp.prototype[Symbol.matchAll], 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/name.js new file mode 100644 index 0000000000..f9a1e9bf87 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.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: RegExp.prototype[Symbol.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: [Symbol.matchAll] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.matchAll].name, '[Symbol.matchAll]'); + +verifyNotEnumerable(RegExp.prototype[Symbol.matchAll], 'name'); +verifyNotWritable(RegExp.prototype[Symbol.matchAll], 'name'); +verifyConfigurable(RegExp.prototype[Symbol.matchAll], 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/not-a-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/not-a-constructor.js new file mode 100644 index 0000000000..03009bf3de --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.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: > + RegExp.prototype[Symbol.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, Symbol, Symbol.match, Symbol.matchAll, arrow-function] +---*/ + +assert.sameValue( + isConstructor(RegExp.prototype[Symbol.matchAll]), + false, + 'isConstructor(RegExp.prototype[Symbol.matchAll]) must return false' +); + +assert.throws(TypeError, () => { + let re = new RegExp(''); new re[Symbol.matchAll](); +}, '`let re = new RegExp(\'\'); new re[Symbol.matchAll]()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/prop-desc.js new file mode 100644 index 0000000000..5fc20a0f9c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.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: RegExp.prototype[Symbol.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: [Symbol.matchAll] +---*/ + +assert.sameValue(typeof RegExp.prototype[Symbol.matchAll], 'function'); + +verifyNotEnumerable(RegExp.prototype, Symbol.matchAll); +verifyWritable(RegExp.prototype, Symbol.matchAll); +verifyConfigurable(RegExp.prototype, Symbol.matchAll); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/regexpcreate-this-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/regexpcreate-this-throws.js new file mode 100644 index 0000000000..edb02b3b8c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/regexpcreate-this-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 while creating an internal RegExp +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + [...] + 3. Else, + a. Let flags be "g". + b. Let matcher be ? RegExpCreate(R, flags). +features: [Symbol.matchAll] +---*/ + +var obj = { + toString() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.matchAll].call(obj, ''); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/shell.js new file mode 100644 index 0000000000..0ba29600b8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/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/RegExp/prototype/Symbol.matchAll/species-constructor-get-constructor-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-constructor-throws.js new file mode 100644 index 0000000000..73baa39d78 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-constructor-throws.js @@ -0,0 +1,34 @@ +// 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 constructor property +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + a. Let C be ? SpeciesConstructor(R, RegExp). + + SpeciesConstructor ( O, defaultConstructor ) + [...] + 2. Let C be ? Get(O, "constructor"). +features: [Symbol.matchAll] +---*/ + +var regexp = /./; +Object.defineProperty(regexp, 'constructor', { + get(){ + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + regexp[Symbol.matchAll](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-species-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-species-throws.js new file mode 100644 index 0000000000..4f3ebb94b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-get-species-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 while accessing of @@species property +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + a. Let C be ? SpeciesConstructor(R, RegExp). + + SpeciesConstructor ( O, defaultConstructor ) + [...] + 2. Let C be ? Get(O, "constructor"). +features: [Symbol.matchAll, Symbol.species] +---*/ + +var regexp = /./; +regexp.constructor = { + get [Symbol.species]() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + regexp[Symbol.matchAll](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-is-not-object-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-is-not-object-throws.js new file mode 100644 index 0000000000..12a96e9dc6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-is-not-object-throws.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: Throws TypeError if `constructor` property is not an object +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + a. Let C be ? SpeciesConstructor(R, RegExp). + + SpeciesConstructor ( O, defaultConstructor ) + [...] + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. +features: [Symbol.matchAll] +---*/ + +var regexp = /./; + +function callMatchAll() { regexp[Symbol.matchAll](''); } + +regexp.constructor = null; +assert.throws(TypeError, callMatchAll, "`constructor` value is null"); + +regexp.constructor = true; +assert.throws(TypeError, callMatchAll, "`constructor` value is Boolean"); + +regexp.constructor = ""; +assert.throws(TypeError, callMatchAll, "`constructor` value is String"); + +regexp.constructor = Symbol(); +assert.throws(TypeError, callMatchAll, "`constructor` value is Symbol"); + +regexp.constructor = 1; +assert.throws(TypeError, callMatchAll, "`constructor` value is Number"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-is-undefined.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-is-undefined.js new file mode 100644 index 0000000000..6b1fe894da --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-is-undefined.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: Throws TypeError if `constructor` property is not an object +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + a. Let C be ? SpeciesConstructor(R, RegExp). + + SpeciesConstructor ( O, defaultConstructor ) + [...] + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. +features: [Symbol.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var regexp = /\w/g; +regexp.constructor = undefined; +var str = 'a*b'; + +assert.compareIterator(regexp[Symbol.matchAll](str), [ + matchValidator(['a'], 0, str), + matchValidator(['b'], 2, str) +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-species-is-not-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-species-is-not-constructor.js new file mode 100644 index 0000000000..6499c3b06a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-species-is-not-constructor.js @@ -0,0 +1,47 @@ +// Copyright (C) 2018 Peter Wong. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: pending +description: TypeError is thrown when species constructor is not a constructor +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 2. Return ? [MatchAllIterator](#matchalliterator)(R, string). + + MatchAllIterator ( R, O ) + [...] + 3. Let C be ? [SpeciesConstructor][species-constructor](R, RegExp). + + SpeciesConstructor ( O, defaultConstructor ) + [...] + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. + 7. If IsConstructor(S) is true, return S. + 8. Throw a TypeError exception. +features: [Symbol.matchAll, Symbol.species] +---*/ + +var regexp = /./; +var speciesConstructor = {}; +regexp.constructor = speciesConstructor; + +var callMatchAll = function() { + regexp[Symbol.matchAll](''); +} + +speciesConstructor[Symbol.species] = true; +assert.throws(TypeError, callMatchAll, "`constructor[Symbol.species]` value is Boolean"); + +speciesConstructor[Symbol.species] = 1; +assert.throws(TypeError, callMatchAll, "`constructor[Symbol.species]` value is Number"); + +speciesConstructor[Symbol.species] = Symbol(); +assert.throws(TypeError, callMatchAll, "`constructor[Symbol.species]` value is Symbol"); + +speciesConstructor[Symbol.species] = true; +assert.throws(TypeError, callMatchAll, "`constructor[Symbol.species]` value is Boolean"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-species-is-null-or-undefined.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-species-is-null-or-undefined.js new file mode 100644 index 0000000000..fbc5affa42 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-species-is-null-or-undefined.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: | + Default constructor is used when species constructor is null or undefined +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 2. Return ? [MatchAllIterator](#matchalliterator)(R, string). + + MatchAllIterator ( R, O ) + [...] + 3. Let C be ? [SpeciesConstructor][species-constructor](R, RegExp). + + SpeciesConstructor ( O, defaultConstructor ) + [...] + 2. Let C be ? Get(O, "constructor"). + 3. If C is undefined, return defaultConstructor. + 4. If Type(C) is not Object, throw a TypeError exception. + 5. Let S be ? Get(C, @@species). + 6. If S is either undefined or null, return defaultConstructor. +features: [Symbol.matchAll, Symbol.species] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +function TestWithConstructor(ctor) { + var regexp = /\w/g; + regexp.constructor = { + [Symbol.species]: ctor + }; + var str = 'a*b'; + + assert.compareIterator(regexp[Symbol.matchAll](str), [ + matchValidator(['a'], 0, str), + matchValidator(['b'], 2, str) + ]); +} + +TestWithConstructor(undefined); +TestWithConstructor(null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-species-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-species-throws.js new file mode 100644 index 0000000000..9ba712e86a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor-species-throws.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: Re-throws errors when calling constructor's @@species +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + a. Let C be ? SpeciesConstructor(R, RegExp). + b. Let flags be ? ToString(? Get(R, "flags")) + c. Let matcher be ? Construct(C, R, flags). +features: [Symbol.matchAll, Symbol.species] +---*/ + +var regexp = /./; +regexp.constructor = { + [Symbol.species]: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + regexp[Symbol.matchAll](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor.js new file mode 100644 index 0000000000..521301b381 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-constructor.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: Custom species constructor is called when creating internal RegExp +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 4. Let C be ? SpeciesConstructor(R, %RegExp%). + 5. Let flags be ? ToString(? Get(R, "flags")). + 6. Let matcher be ? Construct(C, « R, flags »). + [...] + 9. If flags contains "g", let global be true. + 10. Else, let global be false. + [...] +features: [Symbol.matchAll, Symbol.species] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var callCount = 0; +var callArgs; +var regexp = /\d/u; +regexp.constructor = { + [Symbol.species]: function(){ + callCount++; + callArgs = arguments; + return /\w/g; + } +}; +var str = 'a*b'; +var iter = regexp[Symbol.matchAll](str); + +assert.sameValue(callCount, 1); +assert.sameValue(callArgs.length, 2); +assert.sameValue(callArgs[0], regexp); +assert.sameValue(callArgs[1], 'u'); + +assert.compareIterator(iter, [ + matchValidator(['a'], 0, str), +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-regexp-get-global-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-regexp-get-global-throws.js new file mode 100644 index 0000000000..dacf9b4249 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-regexp-get-global-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: | + Doesn't access the "global" property of the constructed RegExp +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 4. Let C be ? SpeciesConstructor(R, %RegExp%). + 5. Let flags be ? ToString(? Get(R, "flags")). + 6. Let matcher be ? Construct(C, « R, flags »). + [...] + 9. If flags contains "g", let global be true. + 10. Else, let global be false. + [...] +features: [Symbol.matchAll, Symbol.species] +---*/ + +var regexp = /./; +regexp.constructor = { + [Symbol.species]: function() { + return Object.defineProperty(/./, 'global', { + get() { + throw new Test262Error(); + } + }); + } +}; + +regexp[Symbol.matchAll](''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-regexp-get-unicode-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-regexp-get-unicode-throws.js new file mode 100644 index 0000000000..f58fe1169b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/species-regexp-get-unicode-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: | + Doesn't access the "unicode" property of the constructed RegExp +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 4. Let C be ? SpeciesConstructor(R, %RegExp%). + 5. Let flags be ? ToString(? Get(R, "flags")). + 6. Let matcher be ? Construct(C, « R, flags »). + [...] + 11. If flags contains "u", let fullUnicode be true. + 12. Else, let fullUnicode be false. + [...] +features: [Symbol.matchAll, Symbol.species] +---*/ + +var regexp = /./; +regexp.constructor = { + [Symbol.species]: function() { + return Object.defineProperty(/./, 'unicode', { + get() { + throw new Test262Error(); + } + }); + } +}; + +regexp[Symbol.matchAll](''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/string-tostring-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/string-tostring-throws.js new file mode 100644 index 0000000000..6592addd96 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/string-tostring-throws.js @@ -0,0 +1,29 @@ +// 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 coercion of string parameter +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + 1. Let S be ? ToString(O). +features: [Symbol.matchAll] +---*/ + +var obj = { + valueOf() { + throw new Test262Error('This method should not be invoked.'); + }, + toString() { + throw new Test262Error('toString invoked'); + } +}; + +assert.throws(Test262Error, function() { + /toString value/[Symbol.matchAll](obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/string-tostring.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/string-tostring.js new file mode 100644 index 0000000000..f7a03a6c56 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/string-tostring.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: String coercion of `string` argument +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + 1. Let S be ? ToString(O). +features: [Symbol.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var str = 'a*b'; +var obj = { + toString() { + return str; + } +}; +var regexp = /\w/g; + +assert.compareIterator(regexp[Symbol.matchAll](obj), [ + matchValidator(['a'], 0, str), + matchValidator(['b'], 2, str) +]); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-get-flags-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-get-flags-throws.js new file mode 100644 index 0000000000..7612c19e3e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-get-flags-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 flags property +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + [...] + b. Let flags be ? ToString(? Get(R, "flags")) +features: [Symbol.matchAll] +---*/ + +var regexp = /./; +Object.defineProperty(regexp, 'flags', { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + regexp[Symbol.matchAll](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-get-flags.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-get-flags.js new file mode 100644 index 0000000000..083f7e4e50 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-get-flags.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: Regexp's flags +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + [...] + b. Let flags be ? ToString(? Get(R, "flags")) +features: [Symbol.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var regexp = /\w/; +Object.defineProperty(regexp, 'flags', { + value: 'g' +}); +var str = 'a*b'; + +assert.compareIterator(regexp[Symbol.matchAll](str), [ + matchValidator(['a'], 0, str), + matchValidator(['b'], 2, str) +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-lastindex-cached.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-lastindex-cached.js new file mode 100644 index 0000000000..0c669c3594 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-lastindex-cached.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: Verify regexp's lastIndex is cached +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + [...] + f. Let lastIndex be ? ToLength(? Get(R, "lastIndex")). + g. Perform ? Set(matcher, "lastIndex", lastIndex, true). +features: [Symbol.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var regexp = /./g; +regexp.lastIndex = { + valueOf() { + return 2; + } +}; +var str = 'abcd'; +var iter = regexp[Symbol.matchAll](str); + +// Verify lastIndex is cached at the time of calling @@matchAll +regexp.lastIndex = 0; + +assert.compareIterator(iter, [ + matchValidator(['c'], 2, str), + matchValidator(['d'], 3, str) +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-not-object-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-not-object-throws.js new file mode 100644 index 0000000000..83cf79f929 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-not-object-throws.js @@ -0,0 +1,33 @@ +// Copyright (C) 2018 Jordan Harband. 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: | + RegExp.prototype [ @@matchAll ] ( string ) + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol.matchAll] +---*/ + +var thisValue; +var callMatchAll = function() { + RegExp.prototype[Symbol.matchAll].call(thisValue, ''); +}; + +thisValue = null; +assert.throws(TypeError, callMatchAll, 'this value is null'); + +thisValue = true; +assert.throws(TypeError, callMatchAll, 'this value is Boolean'); + +thisValue = ''; +assert.throws(TypeError, callMatchAll, 'this value is String'); + +thisValue = Symbol(); +assert.throws(TypeError, callMatchAll, 'this value is Symbol'); + +thisValue = 1; +assert.throws(TypeError, callMatchAll, 'this value is Number'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-tolength-lastindex-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-tolength-lastindex-throws.js new file mode 100644 index 0000000000..a3fd259a40 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-tolength-lastindex-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 while coercing RegExp's lastIndex +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + [...] + f. Let lastIndex be ? ToLength(? Get(R, "lastIndex")). +features: [Symbol.matchAll] +---*/ + +var regexp = /./; +regexp.lastIndex = { + valueOf() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + regexp[Symbol.matchAll](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-tostring-flags-throws.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-tostring-flags-throws.js new file mode 100644 index 0000000000..3dc84b9a0c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-tostring-flags-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 while coercing RegExp's flags to a string +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + [...] + b. Let flags be ? ToString(? Get(R, "flags")) +features: [Symbol.matchAll] +---*/ + +var regexp = /\w/; +Object.defineProperty(regexp, 'flags', { + value: { + valueOf() { + ERROR('valueOf Should not be called'); + }, + toString() { + throw new Test262Error(); + } + } +}); + +assert.throws(Test262Error, function() { + regexp[Symbol.matchAll](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-tostring-flags.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-tostring-flags.js new file mode 100644 index 0000000000..a2b69cfd1b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.matchAll/this-tostring-flags.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: Corercing regexp's flags +info: | + RegExp.prototype [ @@matchAll ] ( string ) + [...] + 3. Return ? MatchAllIterator(R, string). + + MatchAllIterator ( R, O ) + [...] + 2. If ? IsRegExp(R) is true, then + [...] + b. Let flags be ? ToString(? Get(R, "flags")) +features: [Symbol.matchAll] +includes: [compareArray.js, compareIterator.js, regExpUtils.js] +---*/ + +var regexp = /\w/; +Object.defineProperty(regexp, 'flags', { + value: { + toString() { + return 'g'; + } + } +}); +var str = 'a*b'; + +assert.compareIterator(regexp[Symbol.matchAll](str), [ + matchValidator(['a'], 0, str), + matchValidator(['b'], 2, str) +]); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-1-coerce-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-1-coerce-err.js new file mode 100644 index 0000000000..c9146920f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-1-coerce-err.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. + +/*--- +description: Behavior when error thrown while type coercing first argument +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 3. Let S be ToString(string). + 4. ReturnIfAbrupt(S). +features: [Symbol.replace] +---*/ + +var arg = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + /./[Symbol.replace](arg); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-1-coerce.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-1-coerce.js new file mode 100644 index 0000000000..a471e4ef1e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-1-coerce.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Type coercion of first argument +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 3. Let S be ToString(string). + [...] +features: [Symbol.replace] +---*/ + +var arg = { + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + toString: function() { + return 'toString value'; + } +}; + +assert.sameValue(/./[Symbol.replace](arg, 'x'), 'xoString value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-2-coerce-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-2-coerce-err.js new file mode 100644 index 0000000000..3fe9cb57f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-2-coerce-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. + +/*--- +description: Behavior when error thrown while type coercing second argument +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 6. Let functionalReplace be IsCallable(replaceValue). + 7. If functionalReplace is false, then + a. Let replaceValue be ToString(replaceValue). + b. ReturnIfAbrupt(replaceValue). +features: [Symbol.replace] +---*/ + +var arg = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + /./[Symbol.replace]('', arg); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-2-coerce.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-2-coerce.js new file mode 100644 index 0000000000..16c659a095 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/arg-2-coerce.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. + +/*--- +description: Type coercion of second argument +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 6. Let functionalReplace be IsCallable(replaceValue). + 7. If functionalReplace is false, then + a. Let replaceValue be ToString(replaceValue). + [...] +features: [Symbol.replace] +---*/ + +var arg = { + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + toString: function() { + return 'toString value'; + } +}; + +assert.sameValue(/./[Symbol.replace]('string', arg), 'toString valuetring'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-global.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-global.js new file mode 100644 index 0000000000..4b87e84024 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-global.js @@ -0,0 +1,75 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Boolean coercion of `global` property +es6id: 21.2.5.8 +info: | + 21.2.5.6 RegExp.prototype [ @@replace ] ( string ) + + [...] + 8. Let global be ToBoolean(Get(rx, "global")). + [...] +features: [Symbol.replace] +---*/ + +Array.print = print; +var r = /a/g; +Object.defineProperty(r, 'global', { writable: true }); + +r.lastIndex = 0; +r.global = undefined; +assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: undefined'); + +r.lastIndex = 0; +r.global = null; +assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: null'); + +r.lastIndex = 0; +r.global = false; +assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: false'); + +r.lastIndex = 0; +r.global = NaN; +assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: NaN'); + +r.lastIndex = 0; +r.global = 0; +assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: global'); + +r.lastIndex = 0; +r.global = ''; +assert.sameValue(r[Symbol.replace]('aa', 'b'), 'ba', 'value: ""'); + +var execCount = 0; +r = /a/; +Object.defineProperty(r, 'global', { writable: true }); +r.exec = function() { + execCount += 1; + if (execCount === 1) { + return ['a']; + } + return null; +}; + +execCount = 0; +r.global = true; +r[Symbol.replace]('aa', 'b'); +assert.sameValue(execCount, 2, 'value: true'); + +execCount = 0; +r.global = 86; +r[Symbol.replace]('aa', 'b'); +assert.sameValue(execCount, 2, 'value: 86'); + +execCount = 0; +r.global = Symbol.replace; +r[Symbol.replace]('aa', 'b'); +assert.sameValue(execCount, 2, 'value: Symbol.replace'); + +execCount = 0; +r.global = {}; +r[Symbol.replace]('aa', 'b'); +assert.sameValue(execCount, 2, 'value: {}'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-lastindex-err.js new file mode 100644 index 0000000000..767644672b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-lastindex-err.js @@ -0,0 +1,53 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Abrupt completion during coercion of "lastIndex" property of `this` value. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 11. Repeat, while done is false + a. Let result be ? RegExpExec(rx, S). + b. If result is null, set done to true. + c. Else, + i. Append result to the end of results. + ii. If global is false, set done to true. + iii. Else, + 1. Let matchStr be ? ToString(? Get(result, "0")). + 2. If matchStr is the empty String, then + a. Let thisIndex be ? ToLength(? Get(rx, "lastIndex")). +features: [Symbol.replace] +---*/ + +var r = /./g; +var execWasCalled = false; +var coercibleIndex = { + valueOf: function() { + throw new Test262Error(); + }, +}; + +var result = { + length: 1, + 0: '', + index: 0, +}; + +r.exec = function() { + if (execWasCalled) { + return null; + } + + r.lastIndex = coercibleIndex; + execWasCalled = true; + return result; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('', ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-lastindex.js new file mode 100644 index 0000000000..23297ddfbd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-lastindex.js @@ -0,0 +1,54 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Length coercion of "lastIndex" property of `this` value. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 11. Repeat, while done is false + a. Let result be ? RegExpExec(rx, S). + b. If result is null, set done to true. + c. Else, + i. Append result to the end of results. + ii. If global is false, set done to true. + iii. Else, + 1. Let matchStr be ? ToString(? Get(result, "0")). + 2. If matchStr is the empty String, then + a. Let thisIndex be ? ToLength(? Get(rx, "lastIndex")). + b. Let nextIndex be AdvanceStringIndex(S, thisIndex, fullUnicode). + c. Perform ? Set(rx, "lastIndex", nextIndex, true). +features: [Symbol.replace] +---*/ + +var r = /./g; +var execWasCalled = false; +var coercibleIndex = { + valueOf: function() { + return Math.pow(2, 54); + }, +}; + +var result = { + length: 1, + 0: '', + index: 0, +}; + +r.exec = function() { + if (execWasCalled) { + return null; + } + + r.lastIndex = coercibleIndex; + execWasCalled = true; + return result; +}; + +assert.sameValue(r[Symbol.replace]('', ''), ''); +assert.sameValue(r.lastIndex, Math.pow(2, 53)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-unicode.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-unicode.js new file mode 100644 index 0000000000..abe4a3727a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/coerce-unicode.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. + +/*--- +description: Boolean coercion of `unicode` property +es6id: 21.2.5.8 +info: | + 21.2.5.6 RegExp.prototype [ @@replace ] ( string ) + + [...] + 10. If global is true, then + a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). + [...] +features: [Symbol.replace] +---*/ + +var r = /^|\udf06/g; +Object.defineProperty(r, 'unicode', { writable: true }); + +r.unicode = undefined; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834XXX'); + +r.unicode = null; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834XXX'); + +r.unicode = false; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834XXX'); + +r.unicode = NaN; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834XXX'); + +r.unicode = 0; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834XXX'); + +r.unicode = ''; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834XXX'); + +r.unicode = true; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834\udf06'); + +r.unicode = 86; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834\udf06'); + +r.unicode = Symbol.replace; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834\udf06'); + +r.unicode = {}; +assert.sameValue(r[Symbol.replace]('\ud834\udf06', 'XXX'), 'XXX\ud834\udf06'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/exec-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/exec-err.js new file mode 100644 index 0000000000..20be01fa3c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/exec-err.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Behavior when error is thrown by `exec` method +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + b. ReturnIfAbrupt(result). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 3. Let exec be Get(R, "exec"). + 4. ReturnIfAbrupt(exec). + 5. If IsCallable(exec) is true, then + a. Let result be Call(exec, R, «S»). + b. ReturnIfAbrupt(result). +features: [Symbol.replace] +---*/ + +var r = /./; +r.exec = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('', ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/exec-invocation.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/exec-invocation.js new file mode 100644 index 0000000000..54f4b7b59e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/exec-invocation.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. + +/*--- +description: Invocation of `exec` method +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + [...] + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 3. Let exec be Get(R, "exec"). + 4. ReturnIfAbrupt(exec). + 5. If IsCallable(exec) is true, then + a. Let result be Call(exec, R, «S»). +features: [Symbol.replace] +---*/ + +var r = /./; +var callCount = 0; +var arg = { + toString: function() { + return 'string form'; + } +}; +var thisValue, args; + +r.exec = function() { + thisValue = this; + args = arguments; + callCount += 1; + return null; +}; + +r[Symbol.replace](arg, ''); + +assert.sameValue(callCount, 1); +assert.sameValue(thisValue, r); +assert.sameValue(args.length, 1); +assert.sameValue(args[0], 'string form'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/flags-tostring-error.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/flags-tostring-error.js new file mode 100644 index 0000000000..f66a3e4053 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/flags-tostring-error.js @@ -0,0 +1,49 @@ +// Copyright (C) 2022 Richard Gibson. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Errors thrown by converting `flags` to string are forwarded to the runtime +esid: sec-regexp.prototype-@@replace +info: | + 1. Let _rx_ be the *this* value. + 2. If Type(_rx_) is not Object, throw a *TypeError* exception. + 3. Let _S_ be ? ToString(_string_). + 4. Let _lengthS_ be the number of code unit elements in _S_. + 5. Let _functionalReplace_ be IsCallable(_replaceValue_). + 6. If _functionalReplace_ is *false*, then + a. Set _replaceValue_ to ? ToString(_replaceValue_). + i. Let _flags_ be ? ToString(? Get(_rx_, *"flags"*)). +features: [Symbol.replace] +---*/ + +function CustomError() {} +var toStringThrows = { + [Symbol.toPrimitive](hint) { + if (hint === 'string') { + throw new CustomError(); + } + throw new Test262Error('@@toPrimitive should be called with hint "string"'); + }, + get toString() { throw new Test262Error('toString property should not be read'); }, + get valueOf() { throw new Test262Error('valueOf property should not be read'); } +}; + +var re = /./g; +Object.defineProperties(re, { + flags: { + get() { return toStringThrows; } + }, + global: { + get() { throw new Test262Error('global property should not be read'); } + }, + unicode: { + get() { throw new Test262Error('unicode property should not be read'); } + } +}); + +assert.throws(CustomError, function() { + re[Symbol.replace](''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement-err.js new file mode 100644 index 0000000000..76362ce99d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement-err.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: > + Behavior when error is thrown during string coercion of the value returned + by functional replaceValue +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + i. Let replacerArgs be «matched». + ii. Append in list order the elements of captures to the end of the + List replacerArgs. + iii. Append position and S as the last two elements of replacerArgs. + iv. Let replValue be Call(replaceValue, undefined, replacerArgs). + v. Let replacement be ToString(replValue). + [...] + o. ReturnIfAbrupt(replacement). +features: [Symbol.replace] +---*/ + +var replacer = function() { + return { + toString: function() { + throw new Test262Error(); + } + }; +}; + +assert.throws(Test262Error, function() { + /x/[Symbol.replace]('[x]', replacer); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement.js new file mode 100644 index 0000000000..6b09118351 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement.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. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + String coercion of the value returned by functional replaceValue. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + k. If functionalReplace is true, then + [...] + v. Let replValue be ? Call(replaceValue, undefined, replacerArgs). + vi. Let replacement be ? ToString(replValue). +features: [Symbol.replace] +---*/ + +var replacer = function() { + return { + toString: function() { + return 'toString value'; + }, + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + }; +}; + +assert.sameValue(/x/[Symbol.replace]('[x]', replacer), '[toString value]'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-err.js new file mode 100644 index 0000000000..32e0ccd115 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-err.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: > + Behavior when error is thrown by functional replaceValue. +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + i. Let replacerArgs be «matched». + ii. Append in list order the elements of captures to the end of the + List replacerArgs. + iii. Append position and S as the last two elements of replacerArgs. + iv. Let replValue be Call(replaceValue, undefined, replacerArgs). + v. Let replacement be ToString(replValue). + [...] + o. ReturnIfAbrupt(replacement). +features: [Symbol.replace] +---*/ + +var replacer = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + /./[Symbol.replace]('a', replacer); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args-empty-result.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args-empty-result.js new file mode 100644 index 0000000000..712d046f6e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args-empty-result.js @@ -0,0 +1,43 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Arguments of functional replaceValue (`exec` result is empty array). +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + e. Let position be ? ToInteger(? Get(result, "index")). + [...] + k. If functionalReplace is true, then + i. Let replacerArgs be « matched ». + ii. Append in list order the elements of captures to the end of the List replacerArgs. + iii. Append position and S to replacerArgs. + [...] + v. Let replValue be ? Call(replaceValue, undefined, replacerArgs). +features: [Symbol.replace] +---*/ + +var args; +var replacer = function() { + args = arguments; +}; + +var r = /./; +r.exec = function() { + return []; +}; + +r[Symbol.replace]('foo', replacer); + +assert.notSameValue(args, undefined); +assert.sameValue(args.length, 3); +assert.sameValue(args[0], 'undefined'); +assert.sameValue(args[1], 0); +assert.sameValue(args[2], 'foo'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args.js new file mode 100644 index 0000000000..b48f9aff71 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Arguments of functional replaceValue +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + i. Let replacerArgs be «matched». + ii. Append in list order the elements of captures to the end of the + List replacerArgs. + iii. Append position and S as the last two elements of replacerArgs. + iv. Let replValue be Call(replaceValue, undefined, replacerArgs). + [...] +features: [Symbol.replace] +---*/ + +var args; +var replacer = function() { + args = arguments; +}; + +/b(.).(.)/[Symbol.replace]('abcdef', replacer); + +assert.notSameValue(args, undefined); +assert.sameValue(args.length, 5); +assert.sameValue(args[0], 'bcde'); +assert.sameValue(args[1], 'c'); +assert.sameValue(args[2], 'e'); +assert.sameValue(args[3], 1); +assert.sameValue(args[4], 'abcdef'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-this-no-strict.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-this-no-strict.js new file mode 100644 index 0000000000..217a7768a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-this-no-strict.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: > + `this` value of functional replaceValue (outside of strict mode) +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + i. Let replacerArgs be «matched». + ii. Append in list order the elements of captures to the end of the + List replacerArgs. + iii. Append position and S as the last two elements of replacerArgs. + iv. Let replValue be Call(replaceValue, undefined, replacerArgs). + [...] +flags: [noStrict] +features: [Symbol.replace] +---*/ + +var thisVal; +var replacer = function() { + thisVal = this; +}; + +/./[Symbol.replace]('x', replacer); + +assert.sameValue(thisVal, this); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-this-strict-strict.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-this-strict-strict.js new file mode 100644 index 0000000000..906210b6bf --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-this-strict-strict.js @@ -0,0 +1,32 @@ +'use strict'; +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `this` value of functional replaceValue (within strict mode) +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + i. Let replacerArgs be «matched». + ii. Append in list order the elements of captures to the end of the + List replacerArgs. + iii. Append position and S as the last two elements of replacerArgs. + iv. Let replValue be Call(replaceValue, undefined, replacerArgs). + [...] +flags: [onlyStrict] +features: [Symbol.replace] +---*/ + +var thisVal = null; +var replacer = function() { + thisVal = this; +}; + +/./[Symbol.replace]('x', replacer); + +assert.sameValue(thisVal, undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-init-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-init-lastindex-err.js new file mode 100644 index 0000000000..df97b72216 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-init-lastindex-err.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: > + Behavior when error is thrown while initializing `lastIndex` property for + "global" instances +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 10. If global is true, then + [...] + c. Let setStatus be Set(rx, "lastIndex", 0, true). + d. ReturnIfAbrupt(setStatus). +features: [Symbol.replace] +---*/ + +var r = /./g; + +// Avoid false positives from unrelated TypeErrors +r[Symbol.replace]('x', 'x'); + +Object.defineProperty(r, 'lastIndex', { writable: false }); + +assert.throws(TypeError, function() { + r[Symbol.replace]('x', 'x'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-init-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-init-lastindex.js new file mode 100644 index 0000000000..ea824178e8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-init-lastindex.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. + +/*--- +description: Initialization of `lastIndex` property for "global" instances +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 10. If global is true, then + [...] + c. Let setStatus be Set(rx, "lastIndex", 0, true). + [...] +features: [Symbol.replace] +---*/ + +var r = /./g; + +r.lastIndex = 1; + +assert.sameValue(r[Symbol.replace]('aa', 'x'), 'xx'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-pos-decrement.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-pos-decrement.js new file mode 100644 index 0000000000..ed390cd2ed --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-pos-decrement.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Behavior when position is decremented during result accumulation +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + p. If position ≥ nextSourcePosition, then + i. NOTE position should not normally move backwards. If it does, it + is an indication of an ill-behaving RegExp subclass or use of an + access triggered side-effect to change the global flag or other + characteristics of rx. In such cases, the corresponding + substitution is ignored. + ii. Let accumulatedResult be the String formed by concatenating the + code units of the current value of accumulatedResult with the + substring of S consisting of the code units from + nextSourcePosition (inclusive) up to position (exclusive) and + with the code units of replacement. + iii. Let nextSourcePosition be position + matchLength. +features: [Symbol.replace] +---*/ + +var r = /./g; +var callCount = 0; +r.exec = function() { + callCount += 1; + + if (callCount === 1) { + return { index: 3, length: 1, 0: 0 }; + } else if (callCount === 2) { + return { index: 1, length: 1, 0: 0 }; + } + + return null; +}; + +assert.sameValue(r[Symbol.replace]('abcde', 'X'), 'abcXe'); +assert.sameValue(callCount, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-pos-increment.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-pos-increment.js new file mode 100644 index 0000000000..2bc399093a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/g-pos-increment.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Behavior when position is incremented during result accumulation +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + p. If position ≥ nextSourcePosition, then + i. NOTE position should not normally move backwards. If it does, it + is an indication of an ill-behaving RegExp subclass or use of an + access triggered side-effect to change the global flag or other + characteristics of rx. In such cases, the corresponding + substitution is ignored. + ii. Let accumulatedResult be the String formed by concatenating the + code units of the current value of accumulatedResult with the + substring of S consisting of the code units from + nextSourcePosition (inclusive) up to position (exclusive) and + with the code units of replacement. + iii. Let nextSourcePosition be position + matchLength. +features: [Symbol.replace] +---*/ + +var r = /./g; +var callCount = 0; +r.exec = function() { + callCount += 1; + + if (callCount === 1) { + return { index: 1, length: 1, 0: 0 }; + } else if (callCount === 2) { + return { index: 3, length: 1, 0: 0 }; + } + + return null; +}; + +assert.sameValue(r[Symbol.replace]('abcde', 'X'), 'aXcXe'); +assert.sameValue(callCount, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-exec-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-exec-err.js new file mode 100644 index 0000000000..6d431b44fb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-exec-err.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Behavior when there is an error thrown while accessing the `exec` method of + "global" instances +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + + ES6 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 3. Let exec be Get(R, "exec"). + 4. ReturnIfAbrupt(exec). +features: [Symbol.replace] +---*/ + +var r = { flags: 'g', global: true }; +Object.defineProperty(r, 'exec', { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.replace].call(r, '', ''); +}); + +assert.sameValue(r.lastIndex, 0, 'Error thrown after setting `lastIndex`'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-flags-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-flags-err.js new file mode 100644 index 0000000000..9e2312efc0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-flags-err.js @@ -0,0 +1,38 @@ +// Copyright (C) 2022 Richard Gibson. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Errors thrown by `flags` accessor are forwarded to the runtime +esid: sec-regexp.prototype-@@replace +info: | + 1. Let _rx_ be the *this* value. + 2. If Type(_rx_) is not Object, throw a *TypeError* exception. + 3. Let _S_ be ? ToString(_string_). + 4. Let _lengthS_ be the number of code unit elements in _S_. + 5. Let _functionalReplace_ be IsCallable(_replaceValue_). + 6. If _functionalReplace_ is *false*, then + a. Set _replaceValue_ to ? ToString(_replaceValue_). + i. Let _flags_ be ? ToString(? Get(_rx_, *"flags"*)). +features: [Symbol.replace] +---*/ + +function CustomError() {} + +var obj = { + get flags() { + throw new CustomError(); + }, + get global() { + throw new Test262Error('global property should not be read'); + }, + get unicode() { + throw new Test262Error('unicode property should not be read'); + } +}; + +assert.throws(CustomError, function() { + RegExp.prototype[Symbol.replace].call(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-global-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-global-err.js new file mode 100644 index 0000000000..dad8ab4b54 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-global-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. + +/*--- +description: > + Behavior when error is thrown during retrieval of `global` property +esid: sec-regexp.prototype-@@replace +info: | + 1. Let _rx_ be the *this* value. + 2. If Type(_rx_) is not Object, throw a *TypeError* exception. + 3. Let _S_ be ? ToString(_string_). + 4. Let _lengthS_ be the number of code unit elements in _S_. + 5. Let _functionalReplace_ be IsCallable(_replaceValue_). + 6. If _functionalReplace_ is *false*, then + a. Set _replaceValue_ to ? ToString(_replaceValue_). + i. Let _flags_ be ? ToString(? Get(_rx_, *"flags"*)). + + sec-get-regexp.prototype.flags get RegExp.prototype.flags + 6. Let _global_ be ToBoolean(? Get(_R_, *"global"*)). +features: [Symbol.replace] +---*/ + +var re = /./; +Object.defineProperty(re, 'global', { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.replace].call(re); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-unicode-error.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-unicode-error.js new file mode 100644 index 0000000000..a8ef365fac --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/get-unicode-error.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Errors thrown by `unicode` accessor are forwarded to the runtime +esid: sec-regexp.prototype-@@replace +info: | + 1. Let _rx_ be the *this* value. + 2. If Type(_rx_) is not Object, throw a *TypeError* exception. + 3. Let _S_ be ? ToString(_string_). + 4. Let _lengthS_ be the number of code unit elements in _S_. + 5. Let _functionalReplace_ be IsCallable(_replaceValue_). + 6. If _functionalReplace_ is *false*, then + a. Set _replaceValue_ to ? ToString(_replaceValue_). + i. Let _flags_ be ? ToString(? Get(_rx_, *"flags"*)). + + sec-get-regexp.prototype.flags get RegExp.prototype.flags + 14. Let _unicode_ be ToBoolean(? Get(_R_, *"unicode"*)). +features: [Symbol.replace] +---*/ + +var nonGlobalRe = /./; +var globalRe = /./g; +var accessor = function() { + throw new Test262Error(); +}; +Object.defineProperty(nonGlobalRe, 'unicode', { + get: accessor +}); +Object.defineProperty(globalRe, 'unicode', { + get: accessor +}); + +assert.throws(Test262Error, function() { + nonGlobalRe[Symbol.replace]('', ''); +}); + +assert.throws(Test262Error, function() { + globalRe[Symbol.replace]('', ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/length.js new file mode 100644 index 0000000000..fe89e2265b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/length.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.8 +description: RegExp.prototype[Symbol.replace] `length` property +info: | + ES6 Section 17: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + 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.replace] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.replace].length, 2); + +verifyNotEnumerable(RegExp.prototype[Symbol.replace], 'length'); +verifyNotWritable(RegExp.prototype[Symbol.replace], 'length'); +verifyConfigurable(RegExp.prototype[Symbol.replace], 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/match-failure.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/match-failure.js new file mode 100644 index 0000000000..a0d5317e5b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/match-failure.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. + +/*--- +description: Return original string when no matches occur +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 12. Let done be false. + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + b. ReturnIfAbrupt(result). + c. If result is null, set done to true. + [...] + 14. Let accumulatedResult be the empty String value. + 15. Let nextSourcePosition be 0. + [...] + 18. Return the String formed by concatenating the code units of + accumulatedResult with the substring of S consisting of the code units + from nextSourcePosition (inclusive) up through the final code unit of S + (inclusive). +features: [Symbol.replace] +---*/ + +assert.sameValue(/x/[Symbol.replace]('abc', 'X'), 'abc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/name.js new file mode 100644 index 0000000000..5d6dbb13e7 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/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.8 +description: RegExp.prototype[Symbol.replace] `name` property +info: | + The value of the name property of this function is "[Symbol.replace]". + + 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.replace] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.replace].name, '[Symbol.replace]'); + +verifyNotEnumerable(RegExp.prototype[Symbol.replace], 'name'); +verifyNotWritable(RegExp.prototype[Symbol.replace], 'name'); +verifyConfigurable(RegExp.prototype[Symbol.replace], 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/named-groups-fn.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/named-groups-fn.js new file mode 100644 index 0000000000..5ef8030922 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/named-groups-fn.js @@ -0,0 +1,61 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + "groups" value is passed as last argument of replacer unless it is undefined. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + j. Let namedCaptures be ? Get(result, "groups"). + k. If functionalReplace is true, then + [...] + iv. If namedCaptures is not undefined, then + 1. Append namedCaptures as the last element of replacerArgs. + v. Let replValue be ? Call(replaceValue, undefined, replacerArgs). +features: [Symbol.replace, regexp-named-groups] +---*/ + +var matchGroups; +var re = /./; +re.exec = function() { + return { + length: 1, + 0: "a", + index: 0, + groups: matchGroups, + }; +}; + +var replacerCalls = 0; +var replacerLastArg; +var replacer = function() { + replacerCalls++; + replacerLastArg = arguments[arguments.length - 1]; +}; + +matchGroups = null; +re[Symbol.replace]("a", replacer); +assert.sameValue(replacerCalls, 1); +assert.sameValue(replacerLastArg, matchGroups); + +matchGroups = undefined; +re[Symbol.replace]("a", replacer); +assert.sameValue(replacerCalls, 2); +assert.sameValue(replacerLastArg, "a"); + +matchGroups = 10; +re[Symbol.replace]("a", replacer); +assert.sameValue(replacerCalls, 3); +assert.sameValue(replacerLastArg, matchGroups); + +matchGroups = {}; +re[Symbol.replace]("a", replacer); +assert.sameValue(replacerCalls, 4); +assert.sameValue(replacerLastArg, matchGroups); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/named-groups.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/named-groups.js new file mode 100644 index 0000000000..731671bccd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/named-groups.js @@ -0,0 +1,46 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-getsubstitution +description: > + RegExp.prototype[Symbol.replace] works with named capture references as expected. + (string replacement) +info: | + GetSubstitution ( matched, str, position, captures, namedCaptures, replacement ) + + Table: Replacement Text Symbol Substitutions + + Unicode Characters: $< + Replacement text: + 1. If namedCaptures is undefined, the replacement text is the literal string $<. + 2. Else, + a. Assert: Type(namedCaptures) is Object. + b. Scan until the next > U+003E (GREATER-THAN SIGN). + c. If none is found, the replacement text is the String "$<". + d. Else, + i. Let groupName be the enclosed substring. + ii. Let capture be ? Get(namedCaptures, groupName). + iii. If capture is undefined, replace the text through > with the empty String. + iv. Otherwise, replace the text through > with ? ToString(capture). +features: [Symbol.replace, regexp-named-groups] +---*/ + +assert.sameValue(/b/u[Symbol.replace]("abc", "$&$<food"), "ab$<foodc"); +assert.sameValue(/./g[Symbol.replace]("ab", "c$<foo>d"), "c$<foo>dc$<foo>d"); +assert.sameValue(/(b)./[Symbol.replace]("abc", "$<foo>$1"), "a$<foo>b"); + +assert.sameValue(/(?<foo>.)(?<bar>.)/[Symbol.replace]("abc", "$<bar>$<foo>"), "bac"); +assert.sameValue(/(?<foo>.)(?<bar>.)/gu[Symbol.replace]("abc", "$2$<foo>$1"), "baac"); +assert.sameValue(/(?<foo>b)/u[Symbol.replace]("abc", "c$<bar>d"), "acdc"); +assert.sameValue(/(?<foo>.)/g[Symbol.replace]("abc", "$<$1>"), ""); +assert.sameValue(/(?<foo>b)/[Symbol.replace]("abc", "$<>"), "ac"); +assert.sameValue(/(?<foo>.)(?<bar>.)/g[Symbol.replace]("abc", "$2$1"), "bac"); +assert.sameValue(/(?<foo>b)/u[Symbol.replace]("abc", "$<foo"), "a$<fooc"); +assert.sameValue(/(?<foo>.)/gu[Symbol.replace]("abc", "$<bar>"), ""); +assert.sameValue(/(?<foo>b)/[Symbol.replace]("abc", "$$<foo>$&"), "a$<foo>bc"); + +assert.sameValue(/(?<𝒜>b)/u[Symbol.replace]("abc", "d$<𝒜>$`"), "adbac"); +assert.sameValue(/(?<$𐒤>b)/gu[Symbol.replace]("abc", "$'$<$𐒤>d"), "acbdc"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/not-a-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/not-a-constructor.js new file mode 100644 index 0000000000..8fe7bd03bb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/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.replace] 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.replace, arrow-function] +---*/ + +assert.sameValue( + isConstructor(RegExp.prototype[Symbol.replace]), + false, + 'isConstructor(RegExp.prototype[Symbol.replace]) must return false' +); + +assert.throws(TypeError, () => { + let re = new RegExp(''); new re[Symbol.replace](); +}, '`let re = new RegExp(\'\'); new re[Symbol.replace]()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/poisoned-stdlib.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/poisoned-stdlib.js new file mode 100644 index 0000000000..891ddbabb4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/poisoned-stdlib.js @@ -0,0 +1,45 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Both functional and pattern replacement performs as expected with poisoned stdlib. +features: [Symbol.iterator, Symbol.replace, regexp-named-groups] +---*/ + +assert(delete Array.prototype.concat); +assert(delete Array.prototype.push); +assert(delete Array.prototype[Symbol.iterator]); +assert(delete Function.prototype.apply); +assert(delete String.prototype.charAt); +assert(delete String.prototype.charCodeAt); +assert(delete String.prototype.indexOf); +assert(delete String.prototype.slice); +assert(delete String.prototype.substring); + +for (let i = 0; i < 5; ++i) { + Object.defineProperty(Array.prototype, i, { + get: function() { + throw new Test262Error(i + " getter should be unreachable."); + }, + set: function(_value) { + throw new Test262Error(i + " setter should be unreachable."); + }, + }); +} + +var str = "1a2"; + +assert.sameValue(/a/[Symbol.replace](str, "$`b"), "11b2"); +assert.sameValue(/a/[Symbol.replace](str, "b$'"), "1b22"); +assert.sameValue(/a/[Symbol.replace](str, "$3b$33"), "1$3b$332"); +assert.sameValue(/(a)/[Symbol.replace](str, "$1b"), "1ab2"); +assert.sameValue(/(?<a>a)/[Symbol.replace](str, "$<a>b"), "1ab2"); + +var replacer = function() { + return "b"; +}; + +assert.sameValue(/a/[Symbol.replace](str, replacer), "1b2"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/prop-desc.js new file mode 100644 index 0000000000..f2d00e5f77 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/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.8 +description: RegExp.prototype[Symbol.replace] 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.replace] +---*/ + +verifyNotEnumerable(RegExp.prototype, Symbol.replace); +verifyWritable(RegExp.prototype, Symbol.replace); +verifyConfigurable(RegExp.prototype, Symbol.replace); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/replace-with-trailing.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/replace-with-trailing.js new file mode 100644 index 0000000000..18c994a784 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/replace-with-trailing.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. + +/*--- +description: > + Return value when replacement pattern does not match final code point +es6id: 21.2.5.8 +info: | + [...] + 18. Return the String formed by concatenating the code units of + accumulatedResult with the substring of S consisting of the code units + from nextSourcePosition (inclusive) up through the final code unit of S + (inclusive). +features: [Symbol.replace] +---*/ + +assert.sameValue(/abc/[Symbol.replace]('abcd', 'X'), 'Xd'); +assert.sameValue(/bc/[Symbol.replace]('abcd', 'X'), 'aXd'); +assert.sameValue(/c/[Symbol.replace]('abcd', 'X'), 'abXd'); + +assert.sameValue(/ab/[Symbol.replace]('abcd', 'X'), 'Xcd'); +assert.sameValue(/b/[Symbol.replace]('abcd', 'X'), 'aXcd'); + +assert.sameValue(/a/[Symbol.replace]('abcd', 'X'), 'Xbcd'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/replace-without-trailing.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/replace-without-trailing.js new file mode 100644 index 0000000000..e52de7ba56 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/replace-without-trailing.js @@ -0,0 +1,18 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Return value when replacement pattern matches final code point +es6id: 21.2.5.8 +info: | + [...] + 17. If nextSourcePosition ≥ lengthS, return accumulatedResult. +features: [Symbol.replace] +---*/ + +assert.sameValue(/abcd/[Symbol.replace]('abcd', 'X'), 'X'); +assert.sameValue(/bcd/[Symbol.replace]('abcd', 'X'), 'aX'); +assert.sameValue(/cd/[Symbol.replace]('abcd', 'X'), 'abX'); +assert.sameValue(/d/[Symbol.replace]('abcd', 'X'), 'abcX'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture-err.js new file mode 100644 index 0000000000..e03a9a4300 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture-err.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: > + Behavior when error is thrown while type coercing `1` property of result +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + [...] + 16. Repeat, for each result in results, + [...] + l. Repeat while n ≤ nCaptures + i. Let capN be Get(result, ToString(n)). + ii. ReturnIfAbrupt(capN). + iii. If capN is not undefined, then + 1. Let capN be ToString(capN). + 2. ReturnIfAbrupt(capN). +features: [Symbol.replace] +---*/ + +var r = /./; +var uncoercibleValue = { + length: 2, + 1: { + toString: function() { + throw new Test262Error(); + } + } +}; +r.exec = function() { + return uncoercibleValue; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', 'b'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.js new file mode 100644 index 0000000000..8ad783902e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.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. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + String coercion of "3" property of the value returned by RegExpExec. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 11. Repeat, while done is false + a. Let result be ? RegExpExec(rx, S). + [...] + 14. For each result in results, do + [...] + i. Repeat, while n ≤ nCaptures + i. Let capN be ? Get(result, ! ToString(n)). + ii. If capN is not undefined, then + 1. Set capN to ? ToString(capN). + [...] +features: [Symbol.replace] +---*/ + +var r = /./; +var coercibleValue = { + length: 4, + index: 0, + 3: { + toString: function() { + return 'toString value'; + }, + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + }, +}; +r.exec = function() { + return coercibleValue; +}; + +assert.sameValue( + r[Symbol.replace]('', 'foo[$3]bar'), 'foo[toString value]bar' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups-err.js new file mode 100644 index 0000000000..c006397d2c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups-err.js @@ -0,0 +1,40 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Abrupt completion during coercion of "groups" + property of the value returned by RegExpExec. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + j. Let namedCaptures be ? Get(result, "groups"). + k. If functionalReplace is true, then + [...] + l. Else, + i. If namedCaptures is not undefined, then + 1. Set namedCaptures to ? ToObject(namedCaptures). +features: [Symbol.replace, regexp-named-groups] +---*/ + +var r = /./; +var coercibleValue = { + length: 1, + 0: '', + index: 0, + groups: null, +}; + +r.exec = function() { + return coercibleValue; +}; + +assert.throws(TypeError, function() { + r[Symbol.replace]('bar', ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups-prop-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups-prop-err.js new file mode 100644 index 0000000000..bb69475979 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups-prop-err.js @@ -0,0 +1,69 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Abrupt completion during coercion of value of "groups" object. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + j. Let namedCaptures be ? Get(result, "groups"). + k. If functionalReplace is true, then + [...] + l. Else, + [...] + ii. Let replacement be ? GetSubstitution(matched, S, position, captures, namedCaptures, replaceValue). + + Runtime Semantics: GetSubstitution ( matched, str, position, captures, namedCaptures, replacement ) + + [...] + 11. Let result be the String value derived from replacement by copying code unit elements + from replacement to result while performing replacements as specified in Table 54. + These $ replacements are done left-to-right, and, once such a replacement is performed, + the new replacement text is not subject to further replacements. + 12. Return result. + + Table 54: Replacement Text Symbol Substitutions + + $< + + 1. If namedCaptures is undefined, the replacement text is the String "$<". + 2. Else, + a. Assert: Type(namedCaptures) is Object. + b. Scan until the next > U+003E (GREATER-THAN SIGN). + c. If none is found, the replacement text is the String "$<". + d. Else, + i. Let groupName be the enclosed substring. + ii. Let capture be ? Get(namedCaptures, groupName). + iii. If capture is undefined, replace the text through > with the empty String. + iv. Otherwise, replace the text through > with ? ToString(capture). +features: [Symbol.replace, regexp-named-groups] +---*/ + +var r = /./; +var coercibleValue = { + length: 1, + 0: '', + index: 0, + groups: { + foo: { + toString: function() { + throw new Test262Error(); + }, + }, + }, +}; + +r.exec = function() { + return coercibleValue; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', '$<foo>'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups-prop.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups-prop.js new file mode 100644 index 0000000000..4a2f731c76 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups-prop.js @@ -0,0 +1,72 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + String coercion of "groups" object values returned by RegExpExec. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + j. Let namedCaptures be ? Get(result, "groups"). + k. If functionalReplace is true, then + [...] + l. Else, + [...] + ii. Let replacement be ? GetSubstitution(matched, S, position, captures, namedCaptures, replaceValue). + + Runtime Semantics: GetSubstitution ( matched, str, position, captures, namedCaptures, replacement ) + + [...] + 11. Let result be the String value derived from replacement by copying code unit elements + from replacement to result while performing replacements as specified in Table 54. + These $ replacements are done left-to-right, and, once such a replacement is performed, + the new replacement text is not subject to further replacements. + 12. Return result. + + Table 54: Replacement Text Symbol Substitutions + + $< + + 1. If namedCaptures is undefined, the replacement text is the String "$<". + 2. Else, + a. Assert: Type(namedCaptures) is Object. + b. Scan until the next > U+003E (GREATER-THAN SIGN). + c. If none is found, the replacement text is the String "$<". + d. Else, + i. Let groupName be the enclosed substring. + ii. Let capture be ? Get(namedCaptures, groupName). + iii. If capture is undefined, replace the text through > with the empty String. + iv. Otherwise, replace the text through > with ? ToString(capture). +features: [Symbol.replace, regexp-named-groups] +---*/ + +var r = /./; +var coercibleValue = { + length: 1, + 0: 'a', + index: 0, + groups: { + foo: { + toString: function() { + return 'toString value'; + }, + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + }, + bar: null, + }, +}; + +r.exec = function() { + return coercibleValue; +}; + +assert.sameValue(r[Symbol.replace]('ab', '[$<foo>]'), '[toString value]b'); +assert.sameValue(r[Symbol.replace]('ab', '[$<bar>]'), '[null]b'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups.js new file mode 100644 index 0000000000..db36533e3c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-groups.js @@ -0,0 +1,38 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + String coercion of "groups" property of the value returned by RegExpExec. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + j. Let namedCaptures be ? Get(result, "groups"). + k. If functionalReplace is true, then + [...] + l. Else, + i. If namedCaptures is not undefined, then + 1. Set namedCaptures to ? ToObject(namedCaptures). + ii. Let replacement be ? GetSubstitution(matched, S, position, captures, namedCaptures, replaceValue). +features: [Symbol.replace, regexp-named-groups] +---*/ + +var r = /./; +var coercibleValue = { + length: 1, + 0: 'b', + index: 1, + groups: '123', +}; + +r.exec = function() { + return coercibleValue; +}; + +assert.sameValue(r[Symbol.replace]('ab', '[$<length>]'), 'a[3]'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index-err.js new file mode 100644 index 0000000000..9f7f177ee6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index-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. + +/*--- +description: > + Behavior when error is thrown while type coercing `index` property of + result +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + [...] + 16. Repeat, for each result in results, + [...] + g. Let position be ToInteger(Get(result, "index")). + h. ReturnIfAbrupt(position). +features: [Symbol.replace] +---*/ + +var r = /./; +var uncoercibleIndex = { + index: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +r.exec = function() { + return uncoercibleIndex; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', 'b'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index-undefined.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index-undefined.js new file mode 100644 index 0000000000..506b483703 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index-undefined.js @@ -0,0 +1,43 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Integer coercion of "index" property of the value returned by RegExpExec. + (undefined value) +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + e. Let position be ? ToInteger(? Get(result, "index")). + [...] + + ToInteger ( argument ) + + 1. Let number be ? ToNumber(argument). + 2. If number is NaN, return +0. +features: [Symbol.toPrimitive, Symbol.replace] +---*/ + +var index = {}; +var toPrimitiveHint; +index[Symbol.toPrimitive] = function(hint) { + toPrimitiveHint = hint; +}; + +var r = /./; +r.exec = function() { + return { + length: 1, + 0: 'a', + index: index, + }; +}; + +assert.sameValue(r[Symbol.replace]('ab', '$`'), 'b'); +assert.sameValue(toPrimitiveHint, 'number'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index.js new file mode 100644 index 0000000000..58e401564c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index.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. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Integer coercion of "index" property of the value returned by RegExpExec. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + e. Let position be ? ToInteger(? Get(result, "index")). + [...] + k. If functionalReplace is true, then + i. Let replacerArgs be « matched ». + ii. Append in list order the elements of captures to the end of the List replacerArgs. + iii. Append position and S to replacerArgs. + [...] + v. Let replValue be ? Call(replaceValue, undefined, replacerArgs). +features: [Symbol.replace] +---*/ + +var r = /./; +var coercibleIndex = { + length: 1, + 0: '', + index: { + valueOf: function() { + return 2.9; + }, + }, +}; +r.exec = function() { + return coercibleIndex; +}; + +var replacer = function(_matched, position) { + return position; +}; + +assert.sameValue(r[Symbol.replace]('abcd', replacer), 'ab2cd'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-length-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-length-err.js new file mode 100644 index 0000000000..2123cb3b17 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-length-err.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: > + Behavior when error is thrown while type coercing `length` property of + result +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + [...] + 16. Repeat, for each result in results, + a. Let nCaptures be ToLength(Get(result, "length")). + b. ReturnIfAbrupt(nCaptures). +features: [Symbol.replace] +---*/ + +var r = /./; +var uncoercibleLength = { + length: { + valueOf: function() { + throw new Test262Error(); + } + } +}; +r.exec = function() { + return uncoercibleLength; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', 'b'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-length.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-length.js new file mode 100644 index 0000000000..ce35f50bc8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-length.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. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Type coercion of "length" property of the value returned by RegExpExec. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + a. Let nCaptures be ? LengthOfArrayLike(result). + [...] +features: [Symbol.replace] +---*/ + +var r = /./; +var coercibleIndex = { + length: { + valueOf: function() { + return 3.9; + }, + }, + 0: '', + 1: 'foo', + 2: 'bar', + 3: 'baz', + index: 0, +}; +r.exec = function() { + return coercibleIndex; +}; + +assert.sameValue(r[Symbol.replace]('', '$1$2$3'), 'foobar$3'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched-err.js new file mode 100644 index 0000000000..6e001de0b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched-err.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: > + Behavior when error is thrown while type coercing `0` property of result +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + [...] + 16. Repeat, for each result in results, + [...] + d. Let matched be ToString(Get(result, "0")). + e. ReturnIfAbrupt(matched). +features: [Symbol.replace] +---*/ + +var r = /./; +var uncoercibleValue = { + 0: { + toString: function() { + throw new Test262Error(); + } + } +}; +r.exec = function() { + return uncoercibleValue; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', 'b'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched-global.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched-global.js new file mode 100644 index 0000000000..05776dd56c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched-global.js @@ -0,0 +1,55 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + String coercion of "0" property of the value returned by RegExpExec. + (global RegExp) +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 11. Repeat, while done is false + a. Let result be ? RegExpExec(rx, S). + b. If result is null, set done to true. + c. Else, + i. Append result to the end of results. + ii. If global is false, set done to true. + iii. Else, + 1. Let matchStr be ? ToString(? Get(result, "0")). + 2. If matchStr is the empty String, then + a. Let thisIndex be ? ToLength(? Get(rx, "lastIndex")). + b. Let nextIndex be AdvanceStringIndex(S, thisIndex, fullUnicode). + c. Perform ? Set(rx, "lastIndex", nextIndex, true). +features: [Symbol.replace] +---*/ + +var r = /./g; +var coercibleValueWasReturned = false; +var coercibleValue = { + length: 1, + 0: { + toString: function() { + return ''; + }, + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + }, + index: 0, +}; + +r.exec = function() { + if (coercibleValueWasReturned) { + return null; + } + + coercibleValueWasReturned = true; + return coercibleValue; +}; + +assert.sameValue(r[Symbol.replace]('', 'foo'), 'foo'); +assert.sameValue(r.lastIndex, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched.js new file mode 100644 index 0000000000..7d0ba81931 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-matched.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + String coercion of "0" property of the value returned by RegExpExec. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 11. Repeat, while done is false + a. Let result be ? RegExpExec(rx, S). + [...] + 14. For each result in results, do + [...] + c. Let matched be ? ToString(? Get(result, "0")). +features: [Symbol.replace] +---*/ + +var r = /./; +var coercibleValue = { + length: 1, + 0: { + toString: function() { + return 'toString value'; + }, + valueOf: function() { + throw new Test262Error('This method should not be invoked.'); + }, + }, + index: 0, +}; +r.exec = function() { + return coercibleValue; +}; + +assert.sameValue( + r[Symbol.replace]('', 'foo[$&]bar'), 'foo[toString value]bar' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-capture-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-capture-err.js new file mode 100644 index 0000000000..d2ec490339 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-capture-err.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: > + Behavior when error is thrown while accessing `1` property of result +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + [...] + 16. Repeat, for each result in results, + [...] + l. Repeat while n ≤ nCaptures + i. Let capN be Get(result, ToString(n)). + ii. ReturnIfAbrupt(capN). +features: [Symbol.replace] +---*/ + +var r = /./; +var poisonedValue = { + length: 2, + get 1() { + throw new Test262Error(); + } +}; +r.exec = function() { + return poisonedValue; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', 'b'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-groups-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-groups-err.js new file mode 100644 index 0000000000..808cb84b15 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-groups-err.js @@ -0,0 +1,36 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Abrupt completion during lookup of "groups" + property of the value returned by RegExpExec. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + j. Let namedCaptures be ? Get(result, "groups"). +features: [Symbol.replace, regexp-named-groups] +---*/ + +var r = /./; +var coercibleValue = { + length: 0, + index: 0, + get groups() { + throw new Test262Error(); + }, +}; + +r.exec = function() { + return coercibleValue; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', '$<foo>'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-groups-prop-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-groups-prop-err.js new file mode 100644 index 0000000000..b4103c1ed5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-groups-prop-err.js @@ -0,0 +1,64 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@replace +description: > + Abrupt completion during lookup of value of "groups" object. +info: | + RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 14. For each result in results, do + [...] + j. Let namedCaptures be ? Get(result, "groups"). + k. If functionalReplace is true, then + [...] + l. Else, + [...] + ii. Let replacement be ? GetSubstitution(matched, S, position, captures, namedCaptures, replaceValue). + + Runtime Semantics: GetSubstitution ( matched, str, position, captures, namedCaptures, replacement ) + + [...] + 11. Let result be the String value derived from replacement by copying code unit elements + from replacement to result while performing replacements as specified in Table 54. + These $ replacements are done left-to-right, and, once such a replacement is performed, + the new replacement text is not subject to further replacements. + 12. Return result. + + Table 54: Replacement Text Symbol Substitutions + + $< + + 1. If namedCaptures is undefined, the replacement text is the String "$<". + 2. Else, + a. Assert: Type(namedCaptures) is Object. + b. Scan until the next > U+003E (GREATER-THAN SIGN). + c. If none is found, the replacement text is the String "$<". + d. Else, + i. Let groupName be the enclosed substring. + ii. Let capture be ? Get(namedCaptures, groupName). +features: [Symbol.replace, regexp-named-groups] +---*/ + +var r = /./; +var coercibleValue = { + length: 0, + index: 0, + groups: { + get foo() { + throw new Test262Error(); + }, + }, +}; + +r.exec = function() { + return coercibleValue; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', '$<foo>'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-index-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-index-err.js new file mode 100644 index 0000000000..9114a3ab5f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-index-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. + +/*--- +description: > + Behavior when error is thrown while accessing `index` property of result +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + [...] + 16. Repeat, for each result in results, + [...] + g. Let position be ToInteger(Get(result, "index")). + h. ReturnIfAbrupt(position). +features: [Symbol.replace] +---*/ + +var r = /./; +var poisonedIndex = { + get index() { + throw new Test262Error(); + } +}; +r.exec = function() { + return poisonedIndex; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', 'b'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-length-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-length-err.js new file mode 100644 index 0000000000..9f74da963a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-length-err.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. + +/*--- +description: > + Behavior when error is thrown while accessing `length` property of result +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + [...] + 16. Repeat, for each result in results, + a. Let nCaptures be ToLength(Get(result, "length")). + b. ReturnIfAbrupt(nCaptures). +features: [Symbol.replace] +---*/ + +var r = /./; +var poisonedLength = { + get length() { + throw new Test262Error(); + } +}; +r.exec = function() { + return poisonedLength; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', 'b'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-matched-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-matched-err.js new file mode 100644 index 0000000000..c38b17596e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-get-matched-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. + +/*--- +description: > + Behavior when error is thrown while accessing `0` property of result +es6id: 21.2.5.8 +info: | + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + [...] + 16. Repeat, for each result in results, + [...] + d. Let matched be ToString(Get(result, "0")). + e. ReturnIfAbrupt(matched). +features: [Symbol.replace] +---*/ + +var r = /./; +var poisonedValue = { + get 0() { + throw new Test262Error(); + } +}; +r.exec = function() { + return poisonedValue; +}; + +assert.throws(Test262Error, function() { + r[Symbol.replace]('a', 'b'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-after.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-after.js new file mode 100644 index 0000000000..92dcae5319 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-after.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. + +/*--- +description: > + Substitution pattern: text after match +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + [...] + n. Else, + i. Let replacement be GetSubstitution(matched, S, position, + captures, replaceValue). + [...] + + 21.1.3.14.1 Runtime Semantics: GetSubstitution + + Code units: 0x0024, 0x0027 + + Unicode Characters: $' + + Replacement text: + If tailPos ≥ stringLength, the replacement is the empty String. Otherwise + the replacement is the substring of str that starts at index tailPos and + continues to the end of str. +features: [Symbol.replace] +---*/ + +assert.sameValue(/c/[Symbol.replace]('abc', '[$\']'), 'ab[]'); +assert.sameValue(/b/[Symbol.replace]('abc', '[$\']'), 'a[c]c'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-before.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-before.js new file mode 100644 index 0000000000..71d88fb145 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-before.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. + +/*--- +description: > + Substitution pattern: text before match +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + [...] + n. Else, + i. Let replacement be GetSubstitution(matched, S, position, + captures, replaceValue). + [...] + + 21.1.3.14.1 Runtime Semantics: GetSubstitution + + Code units: 0x0024, 0x0060 + + Unicode Characters: $` + + Replacement text: + If position is 0, the replacement is the empty String. Otherwise the + replacement is the substring of str that starts at index 0 and whose last + code unit is at index `position-1`. +features: [Symbol.replace] +---*/ + +assert.sameValue(/a/[Symbol.replace]('abc', '[$`]'), '[]bc'); +assert.sameValue(/b/[Symbol.replace]('abc', '[$`]'), 'a[a]c'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-capture-idx-1.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-capture-idx-1.js new file mode 100644 index 0000000000..bd0cc5b6e8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-capture-idx-1.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Substitution pattern: one-digit capturing group reference +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + [...] + n. Else, + i. Let replacement be GetSubstitution(matched, S, position, + captures, replaceValue). + [...] + + 21.1.3.14.1 Runtime Semantics: GetSubstitution + + Code units: + 0x0024, N + Where 0x0031 ≤ N ≤ 0x0039 + + Unicode Characters: + $n where + n is one of 1 2 3 4 5 6 7 8 9 and $n is not followed by a decimal digit + + Replacement text: + The nth element of captures, where n is a single digit in the range 1 to 9. + If n≤m and the nth element of captures is undefined, use the empty String + instead. If n>m, no replacement is done. +features: [Symbol.replace] +---*/ + +assert.sameValue(/b(c)(z)?(.)/[Symbol.replace]('abcde', '[$1$2$3]'), 'a[cd]e'); + +assert.sameValue(/b(c)(z)?(.)/[Symbol.replace]('abcde', '[$1$2$3$4$0]'), 'a[cd$4$0]e'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-capture-idx-2.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-capture-idx-2.js new file mode 100644 index 0000000000..b9138d009d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-capture-idx-2.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Substitution pattern: two-digit capturing group reference +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + [...] + n. Else, + i. Let replacement be GetSubstitution(matched, S, position, + captures, replaceValue). + [...] + + 21.1.3.14.1 Runtime Semantics: GetSubstitution + + Code units: + 0x0024, N, N + Where 0x0030 ≤ N ≤ 0x0039 + + Unicode Characters: + $nn where + n is one of 0 1 2 3 4 5 6 7 8 9 + + Replacement text: + The nnth element of captures, where nn is a two-digit decimal number in the + range 01 to 99. If nn≤m and the nnth element of captures is undefined, use + the empty String instead. If nn is 00 or nn>m, no replacement is done. +features: [Symbol.replace] +---*/ + +assert.sameValue( + /b(c)(z)?(.)/[Symbol.replace]('abcde', '[$01$02$03]'), 'a[cd]e' +); + +assert.sameValue( + /b(c)(z)?(.)/[Symbol.replace]('abcde', '[$01$02$03$04$00]'), 'a[cd$04$00]e' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-dollar.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-dollar.js new file mode 100644 index 0000000000..946e33e2d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-dollar.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. + +/*--- +description: > + Substitution pattern: dollar sign +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + [...] + n. Else, + i. Let replacement be GetSubstitution(matched, S, position, + captures, replaceValue). + [...] + + 21.1.3.14.1 Runtime Semantics: GetSubstitution + + Code units: 0x0024, 0x0024 + Unicode Characters: $$ + Replacement text: $ + + [...] + + Code units: 0x0024 + Unicode Characters: $ in any context that does not match any of the above. + Replacement text: $ +features: [Symbol.replace] +---*/ + +assert.sameValue(/./[Symbol.replace]('abc', '$$'), '$bc', '"escaped" version'); +assert.sameValue( + /./[Symbol.replace]('abc', '$'), '$bc', '"unescaped" version' +); +assert.sameValue( + /./[Symbol.replace]('abc', '\\$'), '\\$bc', 'backslash-prefixed' +); +assert.sameValue( + /./[Symbol.replace]('abc', '$$$'), + '$$bc', + '"escaped" followed by "unuescaped"' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-matched.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-matched.js new file mode 100644 index 0000000000..67438ee100 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/subst-matched.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. + +/*--- +description: > + Substitution pattern: matched string +es6id: 21.2.5.8 +info: | + 16. Repeat, for each result in results, + [...] + m. If functionalReplace is true, then + [...] + n. Else, + i. Let replacement be GetSubstitution(matched, S, position, + captures, replaceValue). + [...] + + 21.1.3.14.1 Runtime Semantics: GetSubstitution + + Code units: 0x0024, 0x0026 + Unicode Characters: $& + Replacement text: matched +features: [Symbol.replace] +---*/ + +assert.sameValue(/.4?./[Symbol.replace]('abc', '[$&]'), '[ab]c'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/this-val-non-obj.js new file mode 100644 index 0000000000..2d840e32be --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/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.8 +info: | + 1. Let rx be the this value. + 2. If Type(rx) is not Object, throw a TypeError exception. +features: [Symbol.replace] +---*/ + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.replace].call(); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.replace].call(undefined); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.replace].call(null); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.replace].call(true); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.replace].call('string'); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.replace].call(Symbol.replace); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.replace].call(86); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/u-advance-after-empty.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/u-advance-after-empty.js new file mode 100644 index 0000000000..69d57d61fb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/u-advance-after-empty.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. + +/*--- +description: lastIndex is advanced according to width of astral symbols +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 10. If global is true, then + a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). + b. ReturnIfAbrupt(fullUnicode). + [...] + 13. Repeat, while done is false + [...] + d. Else result is not null, + [...] + iii. Else, + [...] + 3. If matchStr is the empty String, then + [...] + c. Let nextIndex be AdvanceStringIndex(S, thisIndex, + fullUnicode). + d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). +features: [Symbol.replace] +---*/ + +var str = /^|\udf06/ug[Symbol.replace]('\ud834\udf06', 'XXX'); +assert.sameValue(str, 'XXX\ud834\udf06'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-global-return.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-global-return.js new file mode 100644 index 0000000000..69248ba6a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-global-return.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: Replaces consecutive matches when the `g` flag is present +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + b. ReturnIfAbrupt(result). + c. If result is null, set done to true. + d. Else result is not null, + i. Append result to the end of results. + ii. If global is false, set done to true. + iii. Else, + 1. Let matchStr be ToString(Get(result, "0")). + [...] + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + [...] + 3. Return null. +features: [Symbol.replace] +---*/ + +assert.sameValue(/a/yg[Symbol.replace]('aaba', 'x'), 'xxba'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-lastindex-no-write.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-lastindex-no-write.js new file mode 100644 index 0000000000..3c2cae7431 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-lastindex-no-write.js @@ -0,0 +1,40 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Match failure with non-writable `lastIndex` property +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). + 2. ReturnIfAbrupt(setStatus). +features: [Symbol.replace] +---*/ + +var r = /c/y; +Object.defineProperty(r, 'lastIndex', { + writable: false +}); + +assert.throws(TypeError, function() { + r[Symbol.replace]('abc', 'x'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-lastindex.js new file mode 100644 index 0000000000..d469580c81 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-lastindex.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. + +/*--- +description: Resets the `lastIndex` property to zero after a match failure +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). +features: [Symbol.replace] +---*/ + +var r = /c/y; +r.lastIndex = 1; + +r[Symbol.replace]('abc', 'x'); + +assert.sameValue(r.lastIndex, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-return.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-return.js new file mode 100644 index 0000000000..b836ce2851 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-fail-return.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. + +/*--- +description: Stops match execution after first match failure +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + [...] + 3. Return null. +features: [Symbol.replace] +---*/ + +assert.sameValue(/b/y[Symbol.replace]('ab', 'x'), 'ab'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-init-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-init-lastindex.js new file mode 100644 index 0000000000..1c71ab2f6d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-init-lastindex.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. + +/*--- +description: Honors initial value of the `lastIndex` property +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + 9. ReturnIfAbrupt(sticky). + 10. If global is false and sticky is false, let lastIndex be 0. +features: [Symbol.replace] +---*/ + +var r = /./y; +r.lastIndex = 1; +assert.sameValue(r[Symbol.replace]('aaa', 'x'), 'axa'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-set-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-set-lastindex.js new file mode 100644 index 0000000000..d97b19cbab --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/y-set-lastindex.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: Sets the `lastIndex` property to the end index of the first match +es6id: 21.2.5.8 +info: | + 21.2.5.8 RegExp.prototype [ @@replace ] ( string, replaceValue ) + + [...] + 13. Repeat, while done is false + a. Let result be RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 18. If global is true or sticky is true, + a. Let setStatus be Set(R, "lastIndex", e, true). +features: [Symbol.replace] +---*/ + +var r = /abc/y; + +r[Symbol.replace]('abc', 'x'); + +assert.sameValue(r.lastIndex, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/coerce-string-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/coerce-string-err.js new file mode 100644 index 0000000000..a0be9089cd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/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.9 +description: Behavior when error thrown while coercing `string` argument +info: | + [...] + 3. Let S be ToString(string). + 4. ReturnIfAbrupt(S). +features: [Symbol.search] +---*/ + +var uncoercibleObj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + /./[Symbol.search](uncoercibleObj); +}); + +assert.throws(TypeError, function() { + /./[Symbol.search](Symbol.search); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/coerce-string.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/coerce-string.js new file mode 100644 index 0000000000..b649f6f1bb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/coerce-string.js @@ -0,0 +1,22 @@ +// 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.9 +description: String coercion of `string` argument +info: | + [...] + 3. Let S be ToString(string). + [...] +features: [Symbol.search] +---*/ + +var obj = { + toString: function() { + return 'toString value'; + } +}; + +assert.sameValue(/ring/[Symbol.search](obj), 4); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/cstm-exec-return-index.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/cstm-exec-return-index.js new file mode 100644 index 0000000000..01410d1bdb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/cstm-exec-return-index.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.9 +description: Index value returned by a custom `exec` method +info: | + [...] + 9. Let result be RegExpExec(rx, S). + [...] + 14. Return Get(result, "index"). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 5. If IsCallable(exec) is true, then + a. Let result be Call(exec, R, «S»). + b. ReturnIfAbrupt(result). + c. If Type(result) is neither Object or Null, throw a TypeError + exception. + d. Return result. + +features: [Symbol.search] +---*/ + +var fakeRe = { + exec: function() { + return { index: 86 }; + } +}; + +assert.sameValue(RegExp.prototype[Symbol.search].call(fakeRe, 'abc'), 86); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/cstm-exec-return-invalid.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/cstm-exec-return-invalid.js new file mode 100644 index 0000000000..81d509c332 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/cstm-exec-return-invalid.js @@ -0,0 +1,58 @@ +// Copyright (C) 2015 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.9 +description: Behavior when invalid value is returned by custom `exec` method +info: | + [...] + 9. Let result be RegExpExec(rx, S). + 10. ReturnIfAbrupt(result). + [...] + 14. Return Get(result, "index"). + + 21.2.5.2.1 Runtime Semantics: RegExpExec ( R, S ) + + [...] + 5. If IsCallable(exec) is true, then + a. Let result be Call(exec, R, «S»). + b. ReturnIfAbrupt(result). + c. If Type(result) is neither Object or Null, throw a TypeError + exception. + +features: [Symbol, Symbol.search] +---*/ + +var retVal; +var fakeRe = { + exec: function() { + return retVal; + } +}; + +retVal = undefined; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(fakeRe, 'a'); +}); + +retVal = 86; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(fakeRe, 'a'); +}); + +retVal = 'string'; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(fakeRe, 'a'); +}); + +retVal = true; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(fakeRe, 'a'); +}); + +retVal = Symbol(); +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(fakeRe, 'a'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/failure-return-val.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/failure-return-val.js new file mode 100644 index 0000000000..466a65a52c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/failure-return-val.js @@ -0,0 +1,15 @@ +// 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.9 +description: Return value when no match is found +info: | + [...] + 13. If result is null, return –1. +features: [Symbol.search] +---*/ + +assert.sameValue(/z/[Symbol.search]('a'), -1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/get-lastindex-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/get-lastindex-err.js new file mode 100644 index 0000000000..523cd80f97 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/get-lastindex-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.9 +description: Behavior when error thrown while accessing `lastIndex` property +info: | + [...] + 5. Let previousLastIndex be Get(rx, "lastIndex"). + 6. ReturnIfAbrupt(previousLastIndex). +features: [Symbol.search] +---*/ + +var poisonedLastIndex = { + get lastIndex() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.search].call(poisonedLastIndex); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/lastindex-no-restore.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/lastindex-no-restore.js new file mode 100644 index 0000000000..066d67da3e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/lastindex-no-restore.js @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.9 +description: Behavior when some lastIndex writes should be skipped. +info: | + [...] + 4. Let previousLastIndex be ? Get(rx, "lastIndex"). + 5. If SameValue(previousLastIndex, 0) is false, then + a. Perform ? Set(rx, "lastIndex", 0, true). + [...] + 7. Let currentLastIndex be ? Get(rx, "lastIndex"). + 8. If SameValue(currentLastIndex, previousLastIndex) is false, then + a. Perform ? Set(rx, "lastIndex", previousLastIndex, true). + [...] +features: [Symbol.search] +---*/ + +var lastIndexValue; +var lastIndexValueAfterExec; +var lastIndexReads; +var lastIndexWrites; +var execCallCount; +var result; + +var fakeRe = { + get lastIndex() { + lastIndexReads++; + return lastIndexValue; + }, + set lastIndex(_) { + lastIndexWrites++; + lastIndexValue = _; + }, + exec: function() { + execCallCount++; + lastIndexValue = lastIndexValueAfterExec; + return null; + } +}; + +function reset(value, valueAfterExec) { + lastIndexValue = value; + lastIndexValueAfterExec = valueAfterExec; + lastIndexReads = 0; + lastIndexWrites = 0; + execCallCount = 0; +} + +reset(0, 0); +result = RegExp.prototype[Symbol.search].call(fakeRe); +assert.sameValue(result, -1); +assert.sameValue(lastIndexValue, 0); +assert.sameValue(lastIndexReads, 2); +assert.sameValue(lastIndexWrites, 0); +assert.sameValue(execCallCount, 1); + +reset(420, 420); +result = RegExp.prototype[Symbol.search].call(fakeRe); +assert.sameValue(result, -1); +assert.sameValue(lastIndexValue, 420); +assert.sameValue(lastIndexReads, 2); +assert.sameValue(lastIndexWrites, 1); +assert.sameValue(execCallCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/length.js new file mode 100644 index 0000000000..86a0b3051c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/length.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.9 +description: RegExp.prototype[Symbol.search] `length` property +info: | + ES6 section 17: + + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this value + is equal to the largest number of named arguments shown in the subclause + headings for the function description, including optional parameters. + + [...] + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +features: [Symbol.search] +includes: [propertyHelper.js] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.search].length, 1); + +verifyNotEnumerable(RegExp.prototype[Symbol.search], 'length'); +verifyNotWritable(RegExp.prototype[Symbol.search], 'length'); +verifyConfigurable(RegExp.prototype[Symbol.search], 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/match-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/match-err.js new file mode 100644 index 0000000000..6d541aebea --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/match-err.js @@ -0,0 +1,27 @@ +// 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.9 +description: Behavior when error thrown while executing match +info: | + [...] + 9. Let result be RegExpExec(rx, S). + 10. ReturnIfAbrupt(result). +features: [Symbol.search] +---*/ + +var fakeRe = { + lastIndex: 86, + exec: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.search].call(fakeRe); +}); + +assert.sameValue(fakeRe.lastIndex, 0, '`lastIndex` property is not restored'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/name.js new file mode 100644 index 0000000000..08a4452f48 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/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.9 +description: RegExp.prototype[Symbol.search] `name` property +info: | + The value of the name property of this function is "[Symbol.search]". + + 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 }. +features: [Symbol.search] +includes: [propertyHelper.js] +---*/ + +assert.sameValue(RegExp.prototype[Symbol.search].name, '[Symbol.search]'); + +verifyNotEnumerable(RegExp.prototype[Symbol.search], 'name'); +verifyNotWritable(RegExp.prototype[Symbol.search], 'name'); +verifyConfigurable(RegExp.prototype[Symbol.search], 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/not-a-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/not-a-constructor.js new file mode 100644 index 0000000000..0403b2e6da --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/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.search] 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.search, arrow-function] +---*/ + +assert.sameValue( + isConstructor(RegExp.prototype[Symbol.search]), + false, + 'isConstructor(RegExp.prototype[Symbol.search]) must return false' +); + +assert.throws(TypeError, () => { + let re = new RegExp(''); new re[Symbol.search](); +}, '`let re = new RegExp(\'\'); new re[Symbol.search]()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/prop-desc.js new file mode 100644 index 0000000000..c38f0f62d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/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.9 +description: RegExp.prototype[Symbol.search] 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.search] +---*/ + +verifyNotEnumerable(RegExp.prototype, Symbol.search); +verifyWritable(RegExp.prototype, Symbol.search); +verifyConfigurable(RegExp.prototype, Symbol.search); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-init-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-init-err.js new file mode 100644 index 0000000000..9df6ae6fc3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-init-err.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.9 +description: > + Behavior when error thrown while initially setting `lastIndex` property +info: | + [...] + 7. Let status be Set(rx, "lastIndex", 0, true). + 8. ReturnIfAbrupt(status). +features: [Symbol.search] +---*/ + +var callCount; +var poisonedLastIndex = { + get lastIndex() { + callCount += 1; + }, + set lastIndex(_) { + throw new Test262Error(); + } +}; +var nonWritableLastIndex = { + get lastIndex() { + callCount += 1; + }, + // This method defined to avoid false positives from unrelated TypeErrors + exec: function() { + return null; + } +}; + +callCount = 0; +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.search].call(poisonedLastIndex); +}); +assert.sameValue( + callCount, + 1, + 'Property value was accessed before being set ("poisoned" lastIndex)' +); + +callCount = 0; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(nonWritableLastIndex); +}); +assert.sameValue( + callCount, + 1, + 'Property value was accessed before being set (non-writable lastIndex)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-init-samevalue.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-init-samevalue.js new file mode 100644 index 0000000000..155420d028 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-init-samevalue.js @@ -0,0 +1,32 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@search +description: > + `previousLastIndex` value is compared using SameValue. +info: | + RegExp.prototype [ @@search ] ( string ) + + [...] + 4. Let previousLastIndex be ? Get(rx, "lastIndex"). + 5. If SameValue(previousLastIndex, 0) is false, then + a. Perform ? Set(rx, "lastIndex", 0, true). + 6. Let result be ? RegExpExec(rx, S). + [...] +features: [Symbol.search] +---*/ + +var re = /(?:)/; +var execLastIndex; + +re.lastIndex = -0; +re.exec = function() { + execLastIndex = re.lastIndex; + return null; +}; + +assert.sameValue(re[Symbol.search](""), -1); +assert.sameValue(execLastIndex, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-init.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-init.js new file mode 100644 index 0000000000..17360b72f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-init.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.9 +description: > + The `lastIndex` value is set to 0 immediately prior to match execution +info: | + [...] + 7. Let status be Set(rx, "lastIndex", 0, true). + 8. ReturnIfAbrupt(status). + 9. Let result be RegExpExec(rx, S). + [...] +features: [Symbol.search] +---*/ + +var duringExec; +var fakeRe = { + lastIndex: 34, + exec: function() { + duringExec = fakeRe.lastIndex; + return null; + } +}; + +RegExp.prototype[Symbol.search].call(fakeRe); + +assert.sameValue(duringExec, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore-err.js new file mode 100644 index 0000000000..03f11054ba --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore-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.9 +description: > + Behavior when error thrown while restoring `lastIndex` property following + match execution +info: | + [...] + 8. If SameValue(currentLastIndex, previousLastIndex) is false, then + a. Perform ? Set(rx, "lastIndex", previousLastIndex, true). +features: [Symbol.search] +---*/ + +var callCount; +var poisonedLastIndex = { + get lastIndex() { return this.lastIndex_; }, + set lastIndex(_) { + if (callCount === 1) { + throw new Test262Error(); + } + this.lastIndex_ = _; + }, + exec: function() { + callCount += 1; + return null; + } +}; +var nonWritableLastIndex = { + exec: function() { + Object.defineProperty( + nonWritableLastIndex, 'lastIndex', { writable: false } + ); + callCount += 1; + return null; + } +}; + +callCount = 0; +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.search].call(poisonedLastIndex); +}); +assert.sameValue(callCount, 1, 'Match executed ("poisoned" lastIndex)'); + +callCount = 0; +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(nonWritableLastIndex); +}); +assert.sameValue(callCount, 1, 'Match executed (non-writable lastIndex)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore-samevalue.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore-samevalue.js new file mode 100644 index 0000000000..a7a909fe72 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore-samevalue.js @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype-@@search +description: > + `currentLastIndex` value is compared using SameValue. +info: | + RegExp.prototype [ @@search ] ( string ) + + [...] + 6. Let result be ? RegExpExec(rx, S). + 7. Let currentLastIndex be ? Get(rx, "lastIndex"). + 8. If SameValue(currentLastIndex, previousLastIndex) is false, then + a. Perform ? Set(rx, "lastIndex", previousLastIndex, true). + [...] +features: [Symbol.search] +---*/ + +var re = /(?:)/; +re.exec = function() { + re.lastIndex = -0; + return null; +}; + +assert.sameValue(re[Symbol.search](""), -1); +assert.sameValue(re.lastIndex, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore.js new file mode 100644 index 0000000000..393d02a14e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/set-lastindex-restore.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.9 +description: The `lastIndex` value is restored following match execution +info: | + [...] + 8. If SameValue(currentLastIndex, previousLastIndex) is false, then + a. Perform ? Set(rx, "lastIndex", previousLastIndex, true). + [...] +features: [Symbol.search] +---*/ + +var latestValue = 86; +var callCount = 0; +var fakeRe = { + get lastIndex() { + return latestValue; + }, + set lastIndex(_) { + latestValue = _; + }, + exec: function() { + callCount++; + latestValue = null; + return null; + } +}; + +RegExp.prototype[Symbol.search].call(fakeRe); + +assert.sameValue(callCount, 1); +assert.sameValue(latestValue, 86); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/success-get-index-err.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/success-get-index-err.js new file mode 100644 index 0000000000..104c75de96 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/success-get-index-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.9 +description: > + Behavior when error thrown while accessing `index` property of match result +info: | + [...] + 14. Return Get(result, "index"). +features: [Symbol.search] +---*/ + +var poisonedIndex = { + get index() { + throw new Test262Error(); + } +}; +var fakeRe = { + exec: function() { + return poisonedIndex; + } +}; + +assert.throws(Test262Error, function() { + RegExp.prototype[Symbol.search].call(fakeRe); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/success-return-val.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/success-return-val.js new file mode 100644 index 0000000000..06020ea0f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/success-return-val.js @@ -0,0 +1,17 @@ +// 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.9 +description: Return value following successful match +info: | + [...] + 14. Return Get(result, "index"). +features: [Symbol.search] +---*/ + +assert.sameValue(/a/[Symbol.search]('abc'), 0); +assert.sameValue(/b/[Symbol.search]('abc'), 1); +assert.sameValue(/c/[Symbol.search]('abc'), 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/this-val-non-obj.js new file mode 100644 index 0000000000..185e2cca72 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/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.9 +info: | + 1. Let rx be the this value. + 2. If Type(rx) is not Object, throw a TypeError exception. +features: [Symbol.search] +---*/ + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(undefined); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(null); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(true); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call('string'); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(Symbol.search); +}); + +assert.throws(TypeError, function() { + RegExp.prototype[Symbol.search].call(86); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/u-lastindex-advance.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/u-lastindex-advance.js new file mode 100644 index 0000000000..a0dbf1022d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/u-lastindex-advance.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Advancement of lastIndex +es6id: 21.2.5.9 +info: | + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 12. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 13. If flags contains "u", let fullUnicode be true, else let fullUnicode be + false. + [...] + 15. Repeat, while matchSucceeded is false + [...] + c. If r is failure, then + [...] + ii. Let lastIndex be AdvanceStringIndex(S, lastIndex, fullUnicode). +features: [Symbol.search] +---*/ + +assert.sameValue(/\udf06/u[Symbol.search]('\ud834\udf06'), -1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/y-fail-return.js b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/y-fail-return.js new file mode 100644 index 0000000000..4944a8ad49 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search/y-fail-return.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. + +/*--- +description: Stops match execution after first match failure +es6id: 21.2.5.9 +info: | + 21.2.5.9 RegExp.prototype [ @@search ] ( string ) + + [...] + 9. Let result be RegExpExec(rx, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + [...] + 3. Return null. +features: [Symbol.search] +---*/ + +assert.sameValue(/a/y[Symbol.search]('ba'), -1); + +reportCompare(0, 0); 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); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/cross-realm.js new file mode 100644 index 0000000000..baa13fadd5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/cross-realm.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.dotall +description: Invoked on a cross-realm object +info: | + get RegExp.prototype.dotAll + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +features: [regexp-dotall, cross-realm] +---*/ + +var dotAll = Object.getOwnPropertyDescriptor(RegExp.prototype, 'dotAll').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'dotAll').get; + +assert.throws(TypeError, function() { + dotAll.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/length.js new file mode 100644 index 0000000000..1a6bb3afe2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/length.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.dotall +description: > + get RegExp.prototype.dotAll.length is 0. +info: | + get RegExp.prototype.dotAll + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [regexp-dotall] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "dotAll"); + +assert.sameValue(desc.get.length, 0); + +verifyProperty(desc.get, "length", { + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/name.js new file mode 100644 index 0000000000..15d9117e62 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.dotall +description: > + RegExp.prototype.dotAll name +info: | + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. +includes: [propertyHelper.js] +features: [regexp-dotall] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "dotAll"); + +assert.sameValue( + desc.get.name, + "get dotAll" +); + +verifyProperty(desc.get, "name", { + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/prop-desc.js new file mode 100644 index 0000000000..dd00e948bb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/prop-desc.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.dotall +description: > + `pending` property descriptor +info: | + RegExp.prototype.dotAll is an accessor property whose set accessor + function is undefined. + + 17 ECMAScript Standard Built-in Objects + + Every accessor property described in clauses 18 through 26 and in Annex B.2 has the attributes + { [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. If only a get + accessor function is described, the set accessor function is the default value, undefined. If + only a set accessor is described the get accessor is the default value, undefined. +includes: [propertyHelper.js] +features: [regexp-dotall] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "dotAll"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyProperty(RegExp.prototype, "dotAll", { + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-invalid-obj.js new file mode 100644 index 0000000000..76196d39f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-invalid-obj.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.dotall +description: Invoked on an object without an [[OriginalFlags]] internal slot +info: | + get RegExp.prototype.dotAll + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +features: [regexp-dotall] +---*/ + +var dotAll = Object.getOwnPropertyDescriptor(RegExp.prototype, 'dotAll').get; + +assert.throws(TypeError, function() { + dotAll.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + dotAll.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + dotAll.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + dotAll.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-non-obj.js new file mode 100644 index 0000000000..1e6e0b16de --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-non-obj.js @@ -0,0 +1,46 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.dotall +description: > + `dotAll` accessor invoked on a non-object value +info: | + get RegExp.prototype.dotAll + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol, regexp-dotall] +---*/ + +var dotAll = Object.getOwnPropertyDescriptor(RegExp.prototype, "dotAll").get; + +assert.throws(TypeError, function() { + dotAll.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + dotAll.call(null); +}, "null"); + +assert.throws(TypeError, function() { + dotAll.call(true); +}, "true"); + +assert.throws(TypeError, function() { + dotAll.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + dotAll.call(Symbol("s")); +}, "symbol"); + +assert.throws(TypeError, function() { + dotAll.call(4); +}, "number"); + +assert.throws(TypeError, function() { + dotAll.call(4n); +}, "bigint"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-regexp-prototype.js new file mode 100644 index 0000000000..fc4f7178c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-regexp-prototype.js @@ -0,0 +1,21 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.dotall +description: > + Return value of `undefined` when the "this" value is the RegExp prototype + object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. +features: [regexp-dotall] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "dotAll").get; + +assert.sameValue(get.call(RegExp.prototype), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-regexp.js b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-regexp.js new file mode 100644 index 0000000000..428d2c78dc --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/dotAll/this-val-regexp.js @@ -0,0 +1,41 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.dotall +description: > + `dotAll` accessor function invoked on a RegExp instance +info: | + 21.2.5.12 get RegExp.prototype.dotAll + + 4. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 5. If flags contains the code unit "s", return true. + 6. Return false. +features: [regexp-dotall] +---*/ + +assert.sameValue(/./.dotAll, false, "/./.dotAll"); +assert.sameValue(/./i.dotAll, false, "/./i.dotAll"); +assert.sameValue(/./g.dotAll, false, "/./g.dotAll"); +assert.sameValue(/./y.dotAll, false, "/./y.dotAll"); +assert.sameValue(/./m.dotAll, false, "/./m.dotAll"); + +assert.sameValue(/./s.dotAll, true, "/./s.dotAll"); +assert.sameValue(/./is.dotAll, true, "/./is.dotAll"); +assert.sameValue(/./sg.dotAll, true, "/./sg.dotAll"); +assert.sameValue(/./sy.dotAll, true, "/./sy.dotAll"); +assert.sameValue(/./ms.dotAll, true, "/./ms.dotAll"); + +assert.sameValue(new RegExp(".", "").dotAll, false, "new RegExp('.', '').dotAll"); +assert.sameValue(new RegExp(".", "i").dotAll, false, "new RegExp('.', 'i').dotAll"); +assert.sameValue(new RegExp(".", "g").dotAll, false, "new RegExp('.', 'g').dotAll"); +assert.sameValue(new RegExp(".", "y").dotAll, false, "new RegExp('.', 'y').dotAll"); +assert.sameValue(new RegExp(".", "m").dotAll, false, "new RegExp('.', 'm').dotAll"); + +assert.sameValue(new RegExp(".", "s").dotAll, true, "new RegExp('.', 's').dotAll"); +assert.sameValue(new RegExp(".", "is").dotAll, true, "new RegExp('.', 'is').dotAll"); +assert.sameValue(new RegExp(".", "sg").dotAll, true, "new RegExp('.', 'sg').dotAll"); +assert.sameValue(new RegExp(".", "sy").dotAll, true, "new RegExp('.', 'sy').dotAll"); +assert.sameValue(new RegExp(".", "ms").dotAll, true, "new RegExp('.', 'ms').dotAll"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/15.10.6.2-9-e-1.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/15.10.6.2-9-e-1.js new file mode 100644 index 0000000000..ec873a700c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/15.10.6.2-9-e-1.js @@ -0,0 +1,18 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 15.10.6.2-9-e-1 +description: > + RegExp.prototype.exec - the removed step 9.e won't affected + current algorithm +---*/ + + var str = "Hello World!"; + var regObj = new RegExp("World"); + var result = false; + result = regObj.exec(str).toString() === "World"; + +assert(result, 'result !== true'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A10.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A10.js new file mode 100644 index 0000000000..30f70bedac --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A10.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype.exec.length property has the attribute ReadOnly +es5id: 15.10.6.2_A10 +description: Checking if varying the RegExp.prototype.exec.length property fails +includes: [propertyHelper.js] +---*/ +assert.sameValue( + RegExp.prototype.exec.hasOwnProperty('length'), + true, + 'RegExp.prototype.exec.hasOwnProperty(\'length\') must return true' +); + +var __obj = RegExp.prototype.exec.length; + +verifyNotWritable(RegExp.prototype.exec, "length", null, function(){return "shifted";}); + +assert.sameValue( + RegExp.prototype.exec.length, + __obj, + 'The value of RegExp.prototype.exec.length is expected to equal the value of __obj' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A11.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A11.js new file mode 100644 index 0000000000..2cd62c397f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A11.js @@ -0,0 +1,17 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The length property of the exec method is 1 +es5id: 15.10.6.2_A11 +description: Checking RegExp.prototype.exec.length +---*/ +assert.sameValue( + RegExp.prototype.exec.hasOwnProperty("length"), + true, + 'RegExp.prototype.exec.hasOwnProperty("length") must return true' +); + +assert.sameValue(RegExp.prototype.exec.length, 1, 'The value of RegExp.prototype.exec.length is expected to be 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A12.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A12.js new file mode 100644 index 0000000000..86c5b57945 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A12.js @@ -0,0 +1,15 @@ +// Copyright 2011 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: regExp exec() acts like regExp.exec('undefined') (step 2) +es5id: 15.10.6.2_A12 +description: Checking RegExp.prototype.exec +---*/ + +(/foo/).test('xfoox'); +var match = new RegExp('(.|\r|\n)*','').exec()[0]; +assert.notSameValue(match, 'xfoox', 'The value of match is not "xfoox"'); +assert.sameValue(match, 'undefined', 'The value of match is expected to be "undefined"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T1.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T1.js new file mode 100644 index 0000000000..afbac70c61 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T1.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T1 +description: String is "123" and RegExp is /1|12/ +---*/ + +var __executed = /1|12/.exec("123"); + +var __expected = ["1"]; +__expected.index=0; +__expected.input="123"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T10.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T10.js new file mode 100644 index 0000000000..8da7239544 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T10.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T10 +description: String is 1.01 and RegExp is /1|12/ +---*/ + +var __executed = /1|12/.exec(1.01); + +var __expected = ["1"]; +__expected.index=0; +__expected.input="1.01"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T11.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T11.js new file mode 100644 index 0000000000..826e9f1f0b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T11.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T11 +description: String is new Number(1.012) and RegExp is /2|12/ +---*/ + +var __executed = /2|12/.exec(new Number(1.012)); + +var __expected = ["12"]; +__expected.index=3; +__expected.input="1.012"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T12.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T12.js new file mode 100644 index 0000000000..25924e5aa6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T12.js @@ -0,0 +1,52 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T12 +description: > + String is {toString:function(){return Math.PI;}} and RegExp is + /\.14/ +---*/ + +var __executed = /\.14/.exec({toString:function(){return Math.PI}}); + +var __expected = [".14"]; +__expected.index=1; +__expected.input=String(Math.PI); + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T13.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T13.js new file mode 100644 index 0000000000..c727f0db2b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T13.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T13 +description: String is true and RegExp is /t[a-b|q-s]/ +---*/ + +var __executed = /t[a-b|q-s]/.exec(true); + +var __expected = ["tr"]; +__expected.index=0; +__expected.input="true"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T14.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T14.js new file mode 100644 index 0000000000..4b447fc451 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T14.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T14 +description: String is new Boolean and RegExp is /AL|se/ +---*/ + +var __executed = /AL|se/.exec(new Boolean); + +var __expected = ["se"]; +__expected.index=3; +__expected.input="false"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T15.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T15.js new file mode 100644 index 0000000000..37eb4c6689 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T15.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T15 +description: "String is {toString:function(){return false;}} and RegExp is /LS/i" +---*/ + +var __executed = /LS/i.exec({toString:function(){return false}}); + +var __expected = ["ls"]; +__expected.index=2; +__expected.input="false"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T16.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T16.js new file mode 100644 index 0000000000..45318b1bf6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T16.js @@ -0,0 +1,15 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T16 +description: RegExp is /undefined/ and call exec() without arguments +---*/ + +var __re = /undefined/.exec()[0]; +assert.sameValue(__re, "undefined", 'The value of __re is expected to be "undefined"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T17.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T17.js new file mode 100644 index 0000000000..ed4f5280de --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T17.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T17 +description: String is null and RegExp is /ll|l/ +---*/ + +var __executed = /ll|l/.exec(null); + +var __expected = ["ll"]; +__expected.index=2; +__expected.input="null"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T18.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T18.js new file mode 100644 index 0000000000..4682802f69 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T18.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T18 +description: String is undefined and RegExp is /nd|ne/ +---*/ + +var __executed = /nd|ne/.exec(undefined); + +var __expected = ["nd"]; +__expected.index=1; +__expected.input="undefined"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T19.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T19.js new file mode 100644 index 0000000000..1a904a79df --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T19.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T19 +description: String is void 0 and RegExp is /e{1}/ +---*/ + +var __executed = /e{1}/.exec(void 0); + +var __expected = ["e"]; +__expected.index=3; +__expected.input="undefined"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T2.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T2.js new file mode 100644 index 0000000000..1260136aa1 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T2.js @@ -0,0 +1,51 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T2 +description: String is new String("123") and RegExp is /((1)|(12))((3)|(23))/ +---*/ + +var __re = /((1)|(12))((3)|(23))/; +var __executed = __re.exec(new String("123")); + +var __expected = ["123", "1", "1", undefined, "23", undefined, "23"]; +__expected.index=0; +__expected.input="123"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T20.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T20.js new file mode 100644 index 0000000000..338e7ef05f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T20.js @@ -0,0 +1,52 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T20 +description: String is x and RegExp is /[a-f]d/, where x is undefined variable +---*/ + +var __executed = /[a-f]d/.exec(x); + +var __expected = ["ed"]; +__expected.index=7; +__expected.input="undefined"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +var x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T21.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T21.js new file mode 100644 index 0000000000..f35ae8d538 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T21.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T21 +description: String is function(){}() and RegExp is /[a-z]n/ +---*/ + +var __executed = /[a-z]n/.exec(function(){}()); + +var __expected = ["un"]; +__expected.index=0; +__expected.input="undefined"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T3.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T3.js new file mode 100644 index 0000000000..c6e0d2f775 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T3.js @@ -0,0 +1,50 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T3 +description: String is new Object("abcdefghi") and RegExp is /a[a-z]{2,4}/ +---*/ + +var __executed = /a[a-z]{2,4}/.exec(new Object("abcdefghi")); + +var __expected = ["abcde"]; +__expected.index=0; +__expected.input="abcdefghi"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T4.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T4.js new file mode 100644 index 0000000000..fc4bdb79c7 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T4.js @@ -0,0 +1,52 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T4 +description: > + String is {toString:function(){return "abcdefghi";}} and RegExp is + /a[a-z]{2,4}?/ +---*/ + +var __executed = /a[a-z]{2,4}?/.exec({toString:function(){return "abcdefghi"}}); + +var __expected = ["abc"]; +__expected.index=0; +__expected.input="abcdefghi"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T5.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T5.js new file mode 100644 index 0000000000..228127b9cd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T5.js @@ -0,0 +1,53 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T5 +description: > + String is {toString:function(){return {};}, + valueOf:function(){return "aabaac";}} and RegExp is + /(aa|aabaac|ba|b|c)* / +---*/ + +var __executed = /(aa|aabaac|ba|b|c)*/.exec({toString:function(){return {};}, valueOf:function(){return "aabaac";}}); + +var __expected = ["aaba", "ba"]; +__expected.index=0; +__expected.input="aabaac"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T6.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T6.js new file mode 100644 index 0000000000..a06db4b6eb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T6.js @@ -0,0 +1,52 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T6 +description: > + String is (function(){return "zaacbbbcac"})() and RegExp is + /(z)((a+)?(b+)?(c))* / +---*/ + +var __executed = /(z)((a+)?(b+)?(c))*/.exec((function(){return "zaacbbbcac"})()); + +var __expected = ["zaacbbbcac", "z", "ac", "a", undefined, "c"]; +__expected.index=0; +__expected.input="zaacbbbcac"; + +assert.sameValue( + __executed instanceof Array, + true, + 'The result of evaluating (__executed instanceof Array) is expected to be true' +); + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T7.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T7.js new file mode 100644 index 0000000000..8d51e48ea1 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T7.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T7 +description: > + String is {toString:function(){throw "intostr";}} and RegExp is + /[a-z]/ +---*/ + +try { + throw new Test262Error('#1.1: /[a-z]/.exec({toString:function(){throw "intostr"}}) throw "intostr". Actual: ' + (/[a-z]/.exec({toString:function(){throw "intostr"}}))); +} catch (e) { + assert.sameValue(e, "intostr", 'The value of e is expected to be "intostr"'); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T8.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T8.js new file mode 100644 index 0000000000..c842675bb8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T8.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T8 +description: > + String is {toString:void 0, valueOf:function(){throw "invalof";}} + and RegExp is /[a-z]/ +---*/ + +try { + throw new Test262Error('#1.1: /[a-z]/.exec({toString:void 0, valueOf:function(){throw "invalof"}}) throw "invalof". Actual: ' + (/[a-z]/.exec({toString:void 0, valueOf:function(){throw "invalof"}}))); +} catch (e) { + assert.sameValue(e, "invalof", 'The value of e is expected to be "invalof"'); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T9.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T9.js new file mode 100644 index 0000000000..42bda957e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A1_T9.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec(string) Performs a regular expression match of ToString(string) against the regular expression and + returns an Array object containing the results of the match, or null if the string did not match +es5id: 15.10.6.2_A1_T9 +description: String is undefined variable and RegExp is /1|12/ +---*/ + +var __string; + +var __re = /1|12/; +assert.sameValue(__re.exec(__string), null, '__re.exec() must return null'); + +function __string(){} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T1.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T1.js new file mode 100644 index 0000000000..160fe731cd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T1.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T1 +description: The internal [[Class]] property is "Object" +---*/ + +var __instance = new Object; + +__instance.exec = RegExp.prototype.exec; + +try { + throw new Test262Error('#1.1: __instance = new Object; __instance.exec = RegExp.prototype.exec; __instance.exec("message to investigate"). Actual: ' + (__instance.exec("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T10.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T10.js new file mode 100644 index 0000000000..377601dd09 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T10.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T10 +description: The tested object is undefined +---*/ + +var exec = RegExp.prototype.exec; + +try { + throw new Test262Error('#1.1: exec = RegExp.prototype.exec; exec("message to investigate"). Actual: ' + (exec("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T2.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T2.js new file mode 100644 index 0000000000..b00031334e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T2.js @@ -0,0 +1,29 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T2 +description: The tested object is Math +---*/ + +var __instance = Math; + +__instance.exec = RegExp.prototype.exec; + +try { + __instance.exec("message to investigate"); + throw new Test262Error('#1.1: __instance = Math; __instance.exec = RegExp.prototype.exec; __instance.exec("message to investigate")'); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T3.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T3.js new file mode 100644 index 0000000000..36cedabf51 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T3.js @@ -0,0 +1,29 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T3 +description: The tested object is function object +---*/ + +__instance.exec = RegExp.prototype.exec; + +try { + __instance.exec("message to investigate"); + throw new Test262Error('#1.1: __instance.exec = RegExp.prototype.exec; __instance.exec("message to investigate"); function __instance(){}'); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +function __instance(){}; + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T4.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T4.js new file mode 100644 index 0000000000..5cf0ba8d34 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T4.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T4 +description: The tested object is new String("[a-b]") +---*/ + +var __instance = new String("[a-b]"); + +__instance.exec = RegExp.prototype.exec; + + try { + throw new Test262Error('#1.1: __instance = new String("[a-b]"); __instance.exec = RegExp.prototype.exec; exec("message to investigate"). Actual: ' + (__instance.exec("message to investigate"))); + } catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); + } + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T5.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T5.js new file mode 100644 index 0000000000..4128d2a5c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T5.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T5 +description: The tested object is new Boolean(false) +---*/ + +var __instance = new Boolean(false); + +__instance.exec = RegExp.prototype.exec; + + try { + throw new Test262Error('#1.1: __instance = new Boolean(false); __instance.exec = RegExp.prototype.exec; exec("message to investigate"). Actual: ' + (__instance.exec("message to investigate"))); + } catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); + } + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T6.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T6.js new file mode 100644 index 0000000000..ebbb2a8a2a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T6.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T6 +description: The tested object is new Number(1.0) +---*/ + +var __instance = new Number(1.0); + +__instance.exec = RegExp.prototype.exec; + +try { + throw new Test262Error('#1.1: __instance = new Number(1.0); __instance.exec = RegExp.prototype.exec; __instance["exec"]("message to investigate"). Actual: ' + (__instance["exec"]("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T7.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T7.js new file mode 100644 index 0000000000..be09f460f8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T7.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T7 +description: The tested object is false +---*/ + +var __instance = false; + +Object.prototype.exec = RegExp.prototype.exec; + +try { + throw new Test262Error('#1.1: __instance = false; Object.prototype.exec = RegExp.prototype.exec; __instance.exec("message to investigate"). Actual: ' + (__instance.exec("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T8.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T8.js new file mode 100644 index 0000000000..4118289d6f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T8.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T8 +description: The tested object is "." +---*/ + +var __instance = "."; + +Object.prototype.exec = RegExp.prototype.exec; + +try { + throw new Test262Error('#1.1: __instance = "."; Object.prototype.exec = RegExp.prototype.exec; __instance.exec("message to investigate"). Actual: ' + (__instance.exec("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T9.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T9.js new file mode 100644 index 0000000000..83f8f5945a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A2_T9.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.2_A2_T9 +description: The tested object is 1.0 +---*/ + +var __instance = 1.0; + +Object.prototype.exec = RegExp.prototype.exec; + +try { + throw new Test262Error('#1.1: __instance = 1.0; Object.prototype.exec = RegExp.prototype.exec; __instance.exec("message to investigate"). Actual: ' + (__instance.exec("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T1.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T1.js new file mode 100644 index 0000000000..52d3ccc26d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T1.js @@ -0,0 +1,42 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true and lastIndex not changed manually, + next exec calling start to match from position where current match finished +es5id: 15.10.6.2_A3_T1 +description: "RegExp is /(?:ab|cd)\\d?/g and tested string is \"ab cd2 ab34 cd\"" +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __matched = []; + +var __expected = ["ab", "cd2", "ab3", "cd"]; + +do{ + var __executed = __re.exec("ab cd2 ab34 cd"); + if (__executed !== null) { + __matched.push(__executed[0]); + } else { + break; + } +}while(true); + +assert.sameValue( + __expected.length, + __matched.length, + 'The value of __expected.length is expected to equal the value of __matched.length' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __expected[index], + __matched[index], + 'The value of __expected[index] is expected to equal the value of __matched[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T2.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T2.js new file mode 100644 index 0000000000..2c9c8b5171 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T2.js @@ -0,0 +1,153 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true and lastIndex not changed manually, + next exec calling start to match from position where current match finished +es5id: 15.10.6.2_A3_T2 +description: RegExp is /[Nn]evermore/g and tested string is very long string +---*/ + +var __the__raven = " Once upon a midnight dreary, while I pondered weak and weary," + + "Over many a quaint and curious volume of forgotten lore," + + "While I nodded, nearly napping, suddenly there came a tapping," + + "As of some one gently rapping, rapping at my chamber door." + + "`'Tis some visitor,' I muttered, `tapping at my chamber door -" + + "Only this, and nothing more.'" + + "Ah, distinctly I remember it was in the bleak December," + + "And each separate dying ember wrought its ghost upon the floor." + + "Eagerly I wished the morrow; - vainly I had sought to borrow" + + "From my books surcease of sorrow - sorrow for the lost Lenore -" + + "For the rare and radiant maiden whom the angels named Lenore -" + + "Nameless here for evermore." + + "\n" + + "And the silken sad uncertain rustling of each purple curtain" + + "Thrilled me - filled me with fantastic terrors never felt before;" + + "So that now, to still the beating of my heart, I stood repeating" + + "`'Tis some visitor entreating entrance at my chamber door -" + + "Some late visitor entreating entrance at my chamber door; -" + + "This it is, and nothing more,'" + + "Presently my soul grew stronger; hesitating then no longer," + + "`Sir,' said I, `or Madam, truly your forgiveness I implore;" + + "But the fact is I was napping, and so gently you came rapping," + + "And so faintly you came tapping, tapping at my chamber door," + + "That I scarce was sure I heard you' - here I opened wide the door; -" + + "Darkness there, and nothing more." + + "\n" + + "Deep into that darkness peering, long I stood there wondering, fearing," + + "Doubting, dreaming dreams no mortal ever dared to dream before" + + "But the silence was unbroken, and the darkness gave no token," + + "And the only word there spoken was the whispered word, `Lenore!'" + + "This I whispered, and an echo murmured back the word, `Lenore!'" + + "Merely this and nothing more." + + "\n" + + "Back into the chamber turning, all my soul within me burning," + + "Soon again I heard a tapping somewhat louder than before." + + "`Surely,' said I, `surely that is something at my window lattice;" + + "Let me see then, what thereat is, and this mystery explore -" + + "Let my heart be still a moment and this mystery explore; -" + + "'Tis the wind and nothing more!'" + + "\n" + + "Open here I flung the shutter, when, with many a flirt and flutter," + + "In there stepped a stately raven of the saintly days of yore." + + "Not the least obeisance made he; not a minute stopped or stayed he;" + + "But, with mien of lord or lady, perched above my chamber door -" + + "Perched upon a bust of Pallas just above my chamber door -" + + "Perched, and sat, and nothing more." + + "\n" + + "Then this ebony bird beguiling my sad fancy into smiling," + + "By the grave and stern decorum of the countenance it wore," + + "`Though thy crest be shorn and shaven, thou,' I said, `art sure no craven." + + "Ghastly grim and ancient raven wandering from the nightly shore -" + + "Tell me what thy lordly name is on the Night's Plutonian shore!'" + + "Quoth the raven, `Nevermore.'" + + "-n" + + "Much I marvelled this ungainly fowl to hear discourse so plainly," + + "Though its answer little meaning - little relevancy bore;" + + "For we cannot help agreeing that no living human being" + + "Ever yet was blessed with seeing bird above his chamber door -" + + "Bird or beast above the sculptured bust above his chamber door," + + "With such name as `Nevermore.'" + + "\n" + + "But the raven, sitting lonely on the placid bust, spoke only," + + "That one word, as if his soul in that one word he did outpour." + + "Nothing further then he uttered - not a feather then he fluttered -" + + "Till I scarcely more than muttered `Other friends have flown before -" + + "On the morrow he will leave me, as my hopes have flown before.'" + + "Then the bird said, `Nevermore.'" + + "\n" + + "Startled at the stillness broken by reply so aptly spoken," + + "`Doubtless,' said I, `what it utters is its only stock and store," + + "Caught from some unhappy master whom unmerciful disaster" + + "Followed fast and followed faster till his songs one burden bore -" + + "Till the dirges of his hope that melancholy burden bore" + + "Of \"Never-nevermore.\"'" + + "\n" + + "But the raven still beguiling all my sad soul into smiling," + + "Straight I wheeled a cushioned seat in front of bird and bust and door;" + + "Then, upon the velvet sinking, I betook myself to linking" + + "Fancy unto fancy, thinking what this ominous bird of yore -" + + "What this grim, ungainly, ghastly, gaunt, and ominous bird of yore" + + "Meant in croaking `Nevermore.'" + + "\n" + + "This I sat engaged in guessing, but no syllable expressing" + + "To the fowl whose fiery eyes now burned into my bosom's core;" + + "This and more I sat divining, with my head at ease reclining" + + "On the cushion's velvet lining that the lamp-light gloated o'er," + + "But whose velvet violet lining with the lamp-light gloating o'er," + + "She shall press, ah, nevermore!" + + "\n" + + "Then, methought, the air grew denser, perfumed from an unseen censer" + + "Swung by Seraphim whose foot-falls tinkled on the tufted floor." + + "`Wretch,' I cried, `thy God hath lent thee - by these angels he has sent thee" + + "Respite - respite and nepenthe from thy memories of Lenore!" + + "Quaff, oh quaff this kind nepenthe, and forget this lost Lenore!'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "`Prophet!' said I, `thing of evil! - prophet still, if bird or devil! -" + + "Whether tempter sent, or whether tempest tossed thee here ashore," + + "Desolate yet all undaunted, on this desert land enchanted -" + + "On this home by horror haunted - tell me truly, I implore -" + + "Is there - is there balm in Gilead? - tell me - tell me, I implore!'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "`Prophet!' said I, `thing of evil! - prophet still, if bird or devil!" + + "By that Heaven that bends above us - by that God we both adore -" + + "Tell this soul with sorrow laden if, within the distant Aidenn," + + "It shall clasp a sainted maiden whom the angels named Lenore -" + + "Clasp a rare and radiant maiden, whom the angels named Lenore?'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "`Be that word our sign of parting, bird or fiend!' I shrieked upstarting -" + + "`Get thee back into the tempest and the Night's Plutonian shore!" + + "Leave no black plume as a token of that lie thy soul hath spoken!" + + "Leave my loneliness unbroken! - quit the bust above my door!" + + "Take thy beak from out my heart, and take thy form from off my door!'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "And the raven, never flitting, still is sitting, still is sitting" + + "On the pallid bust of Pallas just above my chamber door;" + + "And his eyes have all the seeming of a demon's that is dreaming," + + "And the lamp-light o'er him streaming throws his shadow on the floor;" + + "And my soul from out that shadow that lies floating on the floor" + + "Shall be lifted - nevermore!" + +var NEVERMORE=11; + +var __re = /[Nn]evermore/g; +var __matched=0; + +do{ + var __executed = __re.exec(__the__raven); + if (__executed !== null) { + __matched++; + } else { + break; + } +}while(1); + +assert.sameValue(__matched, NEVERMORE, 'The value of __matched is expected to equal the value of NEVERMORE'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T3.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T3.js new file mode 100644 index 0000000000..dec512cc87 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T3.js @@ -0,0 +1,157 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true and lastIndex not changed manually, + next exec calling start to match from position where current match finished +es5id: 15.10.6.2_A3_T3 +description: RegExp is /[Nn]?evermore/g and tested string is very long string +---*/ + +var __the__raven = " Once upon a midnight dreary, while I pondered weak and weary," + + "Over many a quaint and curious volume of forgotten lore," + + "While I nodded, nearly napping, suddenly there came a tapping," + + "As of some one gently rapping, rapping at my chamber door." + + "`'Tis some visitor,' I muttered, `tapping at my chamber door -" + + "Only this, and nothing more.'" + + "Ah, distinctly I remember it was in the bleak December," + + "And each separate dying ember wrought its ghost upon the floor." + + "Eagerly I wished the morrow; - vainly I had sought to borrow" + + "From my books surcease of sorrow - sorrow for the lost Lenore -" + + "For the rare and radiant maiden whom the angels named Lenore -" + + "Nameless here for evermore." + + "\n" + + "And the silken sad uncertain rustling of each purple curtain" + + "Thrilled me - filled me with fantastic terrors never felt before;" + + "So that now, to still the beating of my heart, I stood repeating" + + "`'Tis some visitor entreating entrance at my chamber door -" + + "Some late visitor entreating entrance at my chamber door; -" + + "This it is, and nothing more,'" + + "Presently my soul grew stronger; hesitating then no longer," + + "`Sir,' said I, `or Madam, truly your forgiveness I implore;" + + "But the fact is I was napping, and so gently you came rapping," + + "And so faintly you came tapping, tapping at my chamber door," + + "That I scarce was sure I heard you' - here I opened wide the door; -" + + "Darkness there, and nothing more." + + "\n" + + "Deep into that darkness peering, long I stood there wondering, fearing," + + "Doubting, dreaming dreams no mortal ever dared to dream before" + + "But the silence was unbroken, and the darkness gave no token," + + "And the only word there spoken was the whispered word, `Lenore!'" + + "This I whispered, and an echo murmured back the word, `Lenore!'" + + "Merely this and nothing more." + + "\n" + + "Back into the chamber turning, all my soul within me burning," + + "Soon again I heard a tapping somewhat louder than before." + + "`Surely,' said I, `surely that is something at my window lattice;" + + "Let me see then, what thereat is, and this mystery explore -" + + "Let my heart be still a moment and this mystery explore; -" + + "'Tis the wind and nothing more!'" + + "\n" + + "Open here I flung the shutter, when, with many a flirt and flutter," + + "In there stepped a stately raven of the saintly days of yore." + + "Not the least obeisance made he; not a minute stopped or stayed he;" + + "But, with mien of lord or lady, perched above my chamber door -" + + "Perched upon a bust of Pallas just above my chamber door -" + + "Perched, and sat, and nothing more." + + "\n" + + "Then this ebony bird beguiling my sad fancy into smiling," + + "By the grave and stern decorum of the countenance it wore," + + "`Though thy crest be shorn and shaven, thou,' I said, `art sure no craven." + + "Ghastly grim and ancient raven wandering from the nightly shore -" + + "Tell me what thy lordly name is on the Night's Plutonian shore!'" + + "Quoth the raven, `Nevermore.'" + + "-n" + + "Much I marvelled this ungainly fowl to hear discourse so plainly," + + "Though its answer little meaning - little relevancy bore;" + + "For we cannot help agreeing that no living human being" + + "Ever yet was blessed with seeing bird above his chamber door -" + + "Bird or beast above the sculptured bust above his chamber door," + + "With such name as `Nevermore.'" + + "\n" + + "But the raven, sitting lonely on the placid bust, spoke only," + + "That one word, as if his soul in that one word he did outpour." + + "Nothing further then he uttered - not a feather then he fluttered -" + + "Till I scarcely more than muttered `Other friends have flown before -" + + "On the morrow he will leave me, as my hopes have flown before.'" + + "Then the bird said, `Nevermore.'" + + "\n" + + "Startled at the stillness broken by reply so aptly spoken," + + "`Doubtless,' said I, `what it utters is its only stock and store," + + "Caught from some unhappy master whom unmerciful disaster" + + "Followed fast and followed faster till his songs one burden bore -" + + "Till the dirges of his hope that melancholy burden bore" + + "Of \"Never-nevermore.\"'" + + "\n" + + "But the raven still beguiling all my sad soul into smiling," + + "Straight I wheeled a cushioned seat in front of bird and bust and door;" + + "Then, upon the velvet sinking, I betook myself to linking" + + "Fancy unto fancy, thinking what this ominous bird of yore -" + + "What this grim, ungainly, ghastly, gaunt, and ominous bird of yore" + + "Meant in croaking `Nevermore.'" + + "\n" + + "This I sat engaged in guessing, but no syllable expressing" + + "To the fowl whose fiery eyes now burned into my bosom's core;" + + "This and more I sat divining, with my head at ease reclining" + + "On the cushion's velvet lining that the lamp-light gloated o'er," + + "But whose velvet violet lining with the lamp-light gloating o'er," + + "She shall press, ah, nevermore!" + + "\n" + + "Then, methought, the air grew denser, perfumed from an unseen censer" + + "Swung by Seraphim whose foot-falls tinkled on the tufted floor." + + "`Wretch,' I cried, `thy God hath lent thee - by these angels he has sent thee" + + "Respite - respite and nepenthe from thy memories of Lenore!" + + "Quaff, oh quaff this kind nepenthe, and forget this lost Lenore!'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "`Prophet!' said I, `thing of evil! - prophet still, if bird or devil! -" + + "Whether tempter sent, or whether tempest tossed thee here ashore," + + "Desolate yet all undaunted, on this desert land enchanted -" + + "On this home by horror haunted - tell me truly, I implore -" + + "Is there - is there balm in Gilead? - tell me - tell me, I implore!'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "`Prophet!' said I, `thing of evil! - prophet still, if bird or devil!" + + "By that Heaven that bends above us - by that God we both adore -" + + "Tell this soul with sorrow laden if, within the distant Aidenn," + + "It shall clasp a sainted maiden whom the angels named Lenore -" + + "Clasp a rare and radiant maiden, whom the angels named Lenore?'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "`Be that word our sign of parting, bird or fiend!' I shrieked upstarting -" + + "`Get thee back into the tempest and the Night's Plutonian shore!" + + "Leave no black plume as a token of that lie thy soul hath spoken!" + + "Leave my loneliness unbroken! - quit the bust above my door!" + + "Take thy beak from out my heart, and take thy form from off my door!'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "And the raven, never flitting, still is sitting, still is sitting" + + "On the pallid bust of Pallas just above my chamber door;" + + "And his eyes have all the seeming of a demon's that is dreaming," + + "And the lamp-light o'er him streaming throws his shadow on the floor;" + + "And my soul from out that shadow that lies floating on the floor" + + "Shall be lifted - nevermore!" + +var NEVERMORE_AND_EVERMORE=12; + +var __re = /[Nn]?evermore/g; +var __matched=0; + +do{ + var __executed = __re.exec(__the__raven); + if (__executed !== null) { + __matched++; + } else { + break; + } +}while(1); + +assert.sameValue( + __matched, + NEVERMORE_AND_EVERMORE, + 'The value of __matched is expected to equal the value of NEVERMORE_AND_EVERMORE' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T4.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T4.js new file mode 100644 index 0000000000..dd54ccca23 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T4.js @@ -0,0 +1,159 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true and lastIndex not changed manually, + next exec calling start to match from position where current match finished +es5id: 15.10.6.2_A3_T4 +description: > + RegExp is /([Nn]?ever|([Nn]othing\s{1,}))more/g and tested string + is very long string +---*/ + +var __the__raven = " Once upon a midnight dreary, while I pondered weak and weary," + + "Over many a quaint and curious volume of forgotten lore," + + "While I nodded, nearly napping, suddenly there came a tapping," + + "As of some one gently rapping, rapping at my chamber door." + + "`'Tis some visitor,' I muttered, `tapping at my chamber door -" + + "Only this, and nothing more.'" + + "Ah, distinctly I remember it was in the bleak December," + + "And each separate dying ember wrought its ghost upon the floor." + + "Eagerly I wished the morrow; - vainly I had sought to borrow" + + "From my books surcease of sorrow - sorrow for the lost Lenore -" + + "For the rare and radiant maiden whom the angels named Lenore -" + + "Nameless here for evermore." + + "\n" + + "And the silken sad uncertain rustling of each purple curtain" + + "Thrilled me - filled me with fantastic terrors never felt before;" + + "So that now, to still the beating of my heart, I stood repeating" + + "`'Tis some visitor entreating entrance at my chamber door -" + + "Some late visitor entreating entrance at my chamber door; -" + + "This it is, and nothing more,'" + + "Presently my soul grew stronger; hesitating then no longer," + + "`Sir,' said I, `or Madam, truly your forgiveness I implore;" + + "But the fact is I was napping, and so gently you came rapping," + + "And so faintly you came tapping, tapping at my chamber door," + + "That I scarce was sure I heard you' - here I opened wide the door; -" + + "Darkness there, and nothing more." + + "\n" + + "Deep into that darkness peering, long I stood there wondering, fearing," + + "Doubting, dreaming dreams no mortal ever dared to dream before" + + "But the silence was unbroken, and the darkness gave no token," + + "And the only word there spoken was the whispered word, `Lenore!'" + + "This I whispered, and an echo murmured back the word, `Lenore!'" + + "Merely this and nothing more." + + "\n" + + "Back into the chamber turning, all my soul within me burning," + + "Soon again I heard a tapping somewhat louder than before." + + "`Surely,' said I, `surely that is something at my window lattice;" + + "Let me see then, what thereat is, and this mystery explore -" + + "Let my heart be still a moment and this mystery explore; -" + + "'Tis the wind and nothing more!'" + + "\n" + + "Open here I flung the shutter, when, with many a flirt and flutter," + + "In there stepped a stately raven of the saintly days of yore." + + "Not the least obeisance made he; not a minute stopped or stayed he;" + + "But, with mien of lord or lady, perched above my chamber door -" + + "Perched upon a bust of Pallas just above my chamber door -" + + "Perched, and sat, and nothing more." + + "\n" + + "Then this ebony bird beguiling my sad fancy into smiling," + + "By the grave and stern decorum of the countenance it wore," + + "`Though thy crest be shorn and shaven, thou,' I said, `art sure no craven." + + "Ghastly grim and ancient raven wandering from the nightly shore -" + + "Tell me what thy lordly name is on the Night's Plutonian shore!'" + + "Quoth the raven, `Nevermore.'" + + "-n" + + "Much I marvelled this ungainly fowl to hear discourse so plainly," + + "Though its answer little meaning - little relevancy bore;" + + "For we cannot help agreeing that no living human being" + + "Ever yet was blessed with seeing bird above his chamber door -" + + "Bird or beast above the sculptured bust above his chamber door," + + "With such name as `Nevermore.'" + + "\n" + + "But the raven, sitting lonely on the placid bust, spoke only," + + "That one word, as if his soul in that one word he did outpour." + + "Nothing further then he uttered - not a feather then he fluttered -" + + "Till I scarcely more than muttered `Other friends have flown before -" + + "On the morrow he will leave me, as my hopes have flown before.'" + + "Then the bird said, `Nevermore.'" + + "\n" + + "Startled at the stillness broken by reply so aptly spoken," + + "`Doubtless,' said I, `what it utters is its only stock and store," + + "Caught from some unhappy master whom unmerciful disaster" + + "Followed fast and followed faster till his songs one burden bore -" + + "Till the dirges of his hope that melancholy burden bore" + + "Of \"Never-nevermore.\"'" + + "\n" + + "But the raven still beguiling all my sad soul into smiling," + + "Straight I wheeled a cushioned seat in front of bird and bust and door;" + + "Then, upon the velvet sinking, I betook myself to linking" + + "Fancy unto fancy, thinking what this ominous bird of yore -" + + "What this grim, ungainly, ghastly, gaunt, and ominous bird of yore" + + "Meant in croaking `Nevermore.'" + + "\n" + + "This I sat engaged in guessing, but no syllable expressing" + + "To the fowl whose fiery eyes now burned into my bosom's core;" + + "This and more I sat divining, with my head at ease reclining" + + "On the cushion's velvet lining that the lamp-light gloated o'er," + + "But whose velvet violet lining with the lamp-light gloating o'er," + + "She shall press, ah, nevermore!" + + "\n" + + "Then, methought, the air grew denser, perfumed from an unseen censer" + + "Swung by Seraphim whose foot-falls tinkled on the tufted floor." + + "`Wretch,' I cried, `thy God hath lent thee - by these angels he has sent thee" + + "Respite - respite and nepenthe from thy memories of Lenore!" + + "Quaff, oh quaff this kind nepenthe, and forget this lost Lenore!'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "`Prophet!' said I, `thing of evil! - prophet still, if bird or devil! -" + + "Whether tempter sent, or whether tempest tossed thee here ashore," + + "Desolate yet all undaunted, on this desert land enchanted -" + + "On this home by horror haunted - tell me truly, I implore -" + + "Is there - is there balm in Gilead? - tell me - tell me, I implore!'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "`Prophet!' said I, `thing of evil! - prophet still, if bird or devil!" + + "By that Heaven that bends above us - by that God we both adore -" + + "Tell this soul with sorrow laden if, within the distant Aidenn," + + "It shall clasp a sainted maiden whom the angels named Lenore -" + + "Clasp a rare and radiant maiden, whom the angels named Lenore?'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "`Be that word our sign of parting, bird or fiend!' I shrieked upstarting -" + + "`Get thee back into the tempest and the Night's Plutonian shore!" + + "Leave no black plume as a token of that lie thy soul hath spoken!" + + "Leave my loneliness unbroken! - quit the bust above my door!" + + "Take thy beak from out my heart, and take thy form from off my door!'" + + "Quoth the raven, `Nevermore.'" + + "\n" + + "And the raven, never flitting, still is sitting, still is sitting" + + "On the pallid bust of Pallas just above my chamber door;" + + "And his eyes have all the seeming of a demon's that is dreaming," + + "And the lamp-light o'er him streaming throws his shadow on the floor;" + + "And my soul from out that shadow that lies floating on the floor" + + "Shall be lifted - nevermore!" + +var ALL_THE_HOPELESS_MORE=18; + +var __re = /([Nn]?ever|([Nn]othing\s{1,}))more/g; +var __matched=0; + +do{ + var __executed = __re.exec(__the__raven); + if (__executed !== null) { + __matched++; + } else { + break; + } +}while(1); + +assert.sameValue( + __matched, + ALL_THE_HOPELESS_MORE, + 'The value of __matched is expected to equal the value of ALL_THE_HOPELESS_MORE' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T5.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T5.js new file mode 100644 index 0000000000..a457312611 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T5.js @@ -0,0 +1,42 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true and lastIndex not changed manually, + next exec calling start to match from position where current match finished +es5id: 15.10.6.2_A3_T5 +description: RegExp is /\d+/g and tested string is "123 456 789" +---*/ + +var __re = /\d+/g; + +var __matched = []; + +var __expected = ["123","456","789"]; + +do{ + var __executed = __re.exec("123 456 789"); + if (__executed !== null) { + __matched.push(__executed[0]); + } else { + break; + } +}while(true); + +assert.sameValue( + __expected.length, + __matched.length, + 'The value of __expected.length is expected to equal the value of __matched.length' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __expected[index], + __matched[index], + 'The value of __expected[index] is expected to equal the value of __matched[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T6.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T6.js new file mode 100644 index 0000000000..4c4c1491a6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T6.js @@ -0,0 +1,42 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true and lastIndex not changed manually, + next exec calling start to match from position where current match finished +es5id: 15.10.6.2_A3_T6 +description: RegExp is /(\d+)/g and tested string is "123 456 789" +---*/ + +var __re = /(\d+)/g; + +var __matched = []; + +var __expected = ["123","456","789"]; + +do{ + var __executed = __re.exec("123 456 789"); + if (__executed !== null) { + __matched.push(__executed[0]); + } else { + break; + } +}while(true); + +assert.sameValue( + __expected.length, + __matched.length, + 'The value of __expected.length is expected to equal the value of __matched.length' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __expected[index], + __matched[index], + 'The value of __expected[index] is expected to equal the value of __matched[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T7.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T7.js new file mode 100644 index 0000000000..75232f1ea3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A3_T7.js @@ -0,0 +1,42 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true and lastIndex not changed manually, + next exec calling start to match from position where current match finished +es5id: 15.10.6.2_A3_T7 +description: RegExp is /\d+/ and tested string is "123 456 789" +---*/ + +var __re = /\d+/; + +var __matched = []; + +var __expected = ["123","123","123","123","123","123","123","123","123","123"]; + +do{ + var __executed = __re.exec("123 456 789"); + if (__executed !== null) { + __matched.push(__executed[0]); + } else { + break; + } +}while(__matched.length<10); + +assert.sameValue( + __expected.length, + __matched.length, + 'The value of __expected.length is expected to equal the value of __matched.length' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __expected[index], + __matched[index], + 'The value of __expected[index] is expected to equal the value of __matched[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T1.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T1.js new file mode 100644 index 0000000000..22fa388398 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T1.js @@ -0,0 +1,80 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T1 +description: Call first exec, then set re.lastIndex = 12 and again call exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__re.lastIndex = 12; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["ab4"]; +__expected.index = 17; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T10.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T10.js new file mode 100644 index 0000000000..5c3cbd0ff4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T10.js @@ -0,0 +1,84 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T10 +description: > + Call first exec, then set re.lastIndex = + {valueOf:function(){return 12;}} and again call exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +var __obj = {valueOf:function(){return 12;}}; + +__re.lastIndex = __obj; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["ab4"]; +__expected.index = 17; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T11.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T11.js new file mode 100644 index 0000000000..6d8559da56 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T11.js @@ -0,0 +1,60 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T11 +description: > + Call first exec, then set re.lastIndex = {valueOf:function(){throw + "intoint";}} and again call exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +var __obj = {valueOf:function(){throw "intoint";}}; + +__re.lastIndex = __obj; + +try { + throw new Test262Error('#5.1: __obj = {valueOf:function(){throw "intoint";}}; __re.lastIndex = __obj; __executed = __re.exec("aacd2233ab12nm444ab42") throw "intoint". Actual: ' + (__re.exec("aacd2233ab12nm444ab42"))); +} catch (e) { + assert.sameValue(e, "intoint", 'The value of e is expected to be "intoint"'); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T12.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T12.js new file mode 100644 index 0000000000..f9e6a6df38 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T12.js @@ -0,0 +1,85 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T12 +description: > + Call first exec, then set re.lastIndex = + {toString:function(){return 12;},valueOf:function(){return {};}} + and again call exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +var __obj = {toString:function(){return 12;},valueOf:function(){return {};}}; + +__re.lastIndex = __obj; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["ab4"]; +__expected.index = 17; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T2.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T2.js new file mode 100644 index 0000000000..cc3d4a67ee --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T2.js @@ -0,0 +1,82 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T2 +description: > + Call first exec, then set re.lastIndex = undefined and again call + exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__re.lastIndex = undefined; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T3.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T3.js new file mode 100644 index 0000000000..eec144fd72 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T3.js @@ -0,0 +1,80 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T3 +description: Call first exec, then set re.lastIndex = void 0 and again call exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__re.lastIndex = void 0; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T4.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T4.js new file mode 100644 index 0000000000..b87cb4b9f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T4.js @@ -0,0 +1,80 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T4 +description: Call first exec, then set re.lastIndex = null and again call exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__re.lastIndex = null; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T5.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T5.js new file mode 100644 index 0000000000..00e8e21fc3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T5.js @@ -0,0 +1,84 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T5 +description: > + Call first exec, then set re.lastIndex = x and again call exec, + where x is undefined variable +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__re.lastIndex = x; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +var x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T6.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T6.js new file mode 100644 index 0000000000..ccd2eff07c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T6.js @@ -0,0 +1,80 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T6 +description: Call first exec, then set re.lastIndex = false and again call exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__re.lastIndex = false; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T7.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T7.js new file mode 100644 index 0000000000..5d90fa0435 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T7.js @@ -0,0 +1,82 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T7 +description: > + Call first exec, then set re.lastIndex = Math.NaN and again call + exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__re.lastIndex = Math.NaN; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T8.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T8.js new file mode 100644 index 0000000000..77c7f9c4d4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T8.js @@ -0,0 +1,80 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T8 +description: Call first exec, then set re.lastIndex = "12" and again call exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__re.lastIndex = "12"; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["ab4"]; +__expected.index = 17; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T9.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T9.js new file mode 100644 index 0000000000..dc4902a6bb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A4_T9.js @@ -0,0 +1,82 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + If global is true next exec calling start to match from lastIndex position +es5id: 15.10.6.2_A4_T9 +description: > + Call first exec, then set re.lastIndex = "eleven" and again call + exec +---*/ + +var __re = /(?:ab|cd)\d?/g; + +var __executed = __re.exec("aacd2233ab12nm444ab42"); + +var __expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__re.lastIndex = "eleven"; + +__executed = __re.exec("aacd2233ab12nm444ab42"); + +__expected = ["cd2"]; +__expected.index = 2; +__expected.input = "aacd2233ab12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T1.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T1.js new file mode 100644 index 0000000000..c290de421b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T1.js @@ -0,0 +1,53 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + Let global is true and let I = If ToInteger(lastIndex). + Then if I<0 orI>length then set lastIndex to 0 and return null +es5id: 15.10.6.2_A5_T1 +description: > + First call /(?:ab|cd)\d?/g.exec("aac1dz2233a1bz12nm444ab42"), and + then First call /(?:ab|cd)\d?/g.exec("aacd22") +---*/ + +var __re = /(?:ab|cd)\d?/g; +var __executed = __re.exec("aac1dz2233a1bz12nm444ab42"); + +var __expected = ["ab4"]; +__expected.index = 21; +__expected.input = "aac1dz2233a1bz12nm444ab42"; + +assert.sameValue( + __executed.length, + __expected.length, + 'The value of __executed.length is expected to equal the value of __expected.length' +); + +assert.sameValue( + __executed.index, + __expected.index, + 'The value of __executed.index is expected to equal the value of __expected.index' +); + +assert.sameValue( + __executed.input, + __expected.input, + 'The value of __executed.input is expected to equal the value of __expected.input' +); + +for(var index=0; index<__expected.length; index++) { + assert.sameValue( + __executed[index], + __expected[index], + 'The value of __executed[index] is expected to equal the value of __expected[index]' + ); +} + +__executed = __re.exec("aacd22"); + +assert(!__executed, 'The value of !__executed is expected to be true'); +assert.sameValue(__re.lastIndex, 0, 'The value of __re.lastIndex is expected to be 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T2.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T2.js new file mode 100644 index 0000000000..5661d8d609 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T2.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on global property. + Let global is true and let I = If ToInteger(lastIndex). + Then if I<0 orI>length then set lastIndex to 0 and return null +es5id: 15.10.6.2_A5_T2 +description: "Set lastIndex to 100 and call /(?:ab|cd)\\d?/g.exec(\"aacd22 \")" +---*/ + +var __re = /(?:ab|cd)\d?/g; +__re.lastIndex=100; +var __executed = __re.exec("aacd22 "); + +assert(!__executed, 'The value of !__executed is expected to be true'); +assert.sameValue(__re.lastIndex, 0, 'The value of __re.lastIndex is expected to be 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T3.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T3.js new file mode 100644 index 0000000000..274ae6775f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A5_T3.js @@ -0,0 +1,26 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.exec behavior depends on the lastIndex property: + ToLength(lastIndex) is the starting point for the search, so + negative numbers result in searching from 0. +es5id: 15.10.6.2_A5_T3 +description: "Set lastIndex to -1 and call /(?:ab|cd)\\d?/g.exec(\"aacd22 \")" +---*/ + +var __re = /(?:ab|cd)\d?/g; +__re.lastIndex=-1; +var __executed = __re.exec("aacd22 "); + +assert.sameValue(__executed[0], "cd2", 'The value of __executed[0] is expected to be "cd2"'); +assert.sameValue(__re.lastIndex, 5, 'The value of __re.lastIndex is expected to be 5'); + +__re.lastIndex=-100; +__executed = __re.exec("aacd22 "); + +assert.sameValue(__executed[0], "cd2", 'The value of __executed[0] is expected to be "cd2"'); +assert.sameValue(__re.lastIndex, 5, 'The value of __re.lastIndex is expected to be 5'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A6.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A6.js new file mode 100644 index 0000000000..87f4b0238f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A6.js @@ -0,0 +1,15 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: RegExp.prototype.exec has not prototype property +es5id: 15.10.6.2_A6 +description: Checking RegExp.prototype.exec.prototype +---*/ +assert.sameValue( + RegExp.prototype.exec.prototype, + undefined, + 'The value of RegExp.prototype.exec.prototype is expected to equal undefined' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A7.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A7.js new file mode 100644 index 0000000000..f5ac4392c1 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A7.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: RegExp.prototype.exec can't be used as constructor +es5id: 15.10.6.2_A7 +description: Checking if creating the RegExp.prototype.exec object fails +---*/ + +var __FACTORY = RegExp.prototype.exec; + +try { + var __instance = new __FACTORY; + throw new Test262Error('#1.1: __FACTORY = RegExp.prototype.exec throw TypeError. Actual: ' + (__instance)); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A8.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A8.js new file mode 100644 index 0000000000..bef663772f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A8.js @@ -0,0 +1,35 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype.exec.length property has the attribute DontEnum +es5id: 15.10.6.2_A8 +description: > + Checking if enumerating the RegExp.prototype.exec.length property + fails +---*/ +assert.sameValue( + RegExp.prototype.exec.hasOwnProperty('length'), + true, + 'RegExp.prototype.exec.hasOwnProperty(\'length\') must return true' +); + +assert.sameValue( + RegExp.prototype.exec.propertyIsEnumerable('length'), + false, + 'RegExp.prototype.exec.propertyIsEnumerable(\'length\') must return false' +); + +var count=0; + +for (var p in RegExp.prototype.exec){ + if (p==="length") { + count++; + } +} + +assert.sameValue(count, 0, 'The value of count is expected to be 0'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A9.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A9.js new file mode 100644 index 0000000000..ec0dda3895 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/S15.10.6.2_A9.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The RegExp.prototype.exec.length property does not have the attribute + DontDelete +es5id: 15.10.6.2_A9 +description: > + Checking if deleting the RegExp.prototype.exec.length property + fails +---*/ +assert.sameValue( + RegExp.prototype.exec.hasOwnProperty('length'), + true, + 'RegExp.prototype.exec.hasOwnProperty(\'length\') must return true' +); + +assert.sameValue( + delete RegExp.prototype.exec.length, + true, + 'The value of `delete RegExp.prototype.exec.length` is expected to be true' +); + +assert.sameValue( + RegExp.prototype.exec.hasOwnProperty('length'), + false, + 'RegExp.prototype.exec.hasOwnProperty(\'length\') must return false' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/duplicate-named-groups-properties.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/duplicate-named-groups-properties.js new file mode 100644 index 0000000000..890f8302b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/duplicate-named-groups-properties.js @@ -0,0 +1,39 @@ +// |reftest| skip -- regexp-duplicate-named-groups is not supported +// Copyright 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Properties on groups object with duplicate named capture groups +esid: prod-GroupSpecifier +features: [regexp-duplicate-named-groups] +includes: [compareArray.js] +---*/ + +const matcher = /(?:(?<x>a)|(?<y>a)(?<x>b))(?:(?<z>c)|(?<z>d))/; + +const threeMatchResult = matcher.exec("abc"); +assert.sameValue(threeMatchResult.groups.x, "b", "group x matches b"); +assert.sameValue(threeMatchResult.groups.y, "a", "group y matches a"); +assert.sameValue(threeMatchResult.groups.z, "c", "group z matches c"); +assert.compareArray( + Object.keys(threeMatchResult.groups), + ["x", "y", "z"], + "Properties of groups are ordered in RegExp source order despite y matching before x in this alternative" +); + +const twoMatchResult = matcher.exec("ad"); +assert.sameValue(twoMatchResult.groups.x, "a", "group x matches a"); +assert.sameValue(twoMatchResult.groups.y, undefined, "group y does not match"); +assert.sameValue(twoMatchResult.groups.z, "d", "group z matches d"); +assert.compareArray( + Object.keys(twoMatchResult.groups), + ["x", "y", "z"], + "y is still present on groups object, in the right order, despite not matching" +); + +const iteratedMatcher = /(?:(?:(?<x>a)|(?<x>b)|c)\k<x>){2}/; + +const matchedInPrevIterationResult = iteratedMatcher.exec("aac"); +assert.sameValue(matchedInPrevIterationResult.groups.x, undefined, "group x does not match in the last iteration"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/duplicate-named-indices-groups-properties.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/duplicate-named-indices-groups-properties.js new file mode 100644 index 0000000000..ca0faac957 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/duplicate-named-indices-groups-properties.js @@ -0,0 +1,39 @@ +// |reftest| skip -- regexp-duplicate-named-groups is not supported +// Copyright 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Properties on indices.groups object with duplicate named capture groups +esid: prod-GroupSpecifier +features: [regexp-duplicate-named-groups, regexp-match-indices] +includes: [compareArray.js] +---*/ + +const matcher = /(?:(?<x>a)|(?<y>a)(?<x>b))(?:(?<z>c)|(?<z>d))/d; + +const threeMatchResult = matcher.exec("abc"); +assert.compareArray(threeMatchResult.indices.groups.x, [1, 2], "group x matches b"); +assert.compareArray(threeMatchResult.indices.groups.y, [0, 1], "group y matches a"); +assert.compareArray(threeMatchResult.indices.groups.z, [2, 3], "group z matches c"); +assert.compareArray( + Object.keys(threeMatchResult.indices.groups), + ["x", "y", "z"], + "Properties of groups are ordered in RegExp source order despite y matching before x in this alternative" +); + +const twoMatchResult = matcher.exec("ad"); +assert.compareArray(twoMatchResult.indices.groups.x, [0, 1], "group x matches a"); +assert.sameValue(twoMatchResult.indices.groups.y, undefined, "group y does not match"); +assert.compareArray(twoMatchResult.indices.groups.z, [1, 2], "group z matches d"); +assert.compareArray( + Object.keys(twoMatchResult.indices.groups), + ["x", "y", "z"], + "y is still present on groups object, in the right order, despite not matching" +); + +const iteratedMatcher = /(?:(?:(?<x>a)|(?<x>b)|c)\k<x>){2}/d; + +const matchedInPrevIterationResult = iteratedMatcher.exec("aac"); +assert.sameValue(matchedInPrevIterationResult.indices.groups.x, undefined, "group x does not match in the last iteration"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-g-lastindex-reset.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-g-lastindex-reset.js new file mode 100644 index 0000000000..8b3dd5e333 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-g-lastindex-reset.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + lastIndex is read and reset to 0 when global is set and the match fails. +es6id: 21.2.5.2.2 +info: | + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let flags be R.[[OriginalFlags]]. + 5. If flags contains "g", let global be true, else let global be false. + [...] + 7. If global is false and sticky is false, let lastIndex be 0. + 8. Else, let lastIndex be ? ToLength(? Get(R, "lastIndex")). + [...] + 12. Repeat, while matchSucceeded is false + [...] + c. If r is failure, then + i. If sticky is true, then + 1. Perform ? Set(R, "lastIndex", 0, true). + 2. Return null. + ii. Let lastIndex be AdvanceStringIndex(S, lastIndex, fullUnicode). +---*/ + +var lastIndexReads; +var result; + +var r = /a/g; + +function reset(value) { + r.lastIndex = { + valueOf: function() { + lastIndexReads++; + return value; + } + }; + lastIndexReads = 0; +} + +reset(42); // lastIndex beyond end of string. +result = r.exec('abc'); +assert.sameValue(result, null); +assert.sameValue(r.lastIndex, 0); +assert.sameValue(lastIndexReads, 1); + +reset(-1); // No match. +result = r.exec('nbc'); +assert.sameValue(result, null); +assert.sameValue(r.lastIndex, 0); +assert.sameValue(lastIndexReads, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-lastindex-access.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-lastindex-access.js new file mode 100644 index 0000000000..9925767e23 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-lastindex-access.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: lastIndex is read but not written when global and sticky are unset. +es6id: 21.2.5.2.2 +info: | + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + 4. Let lastIndex be ? ToLength(? Get(R, "lastIndex")). + [...] + 8. If global is false and sticky is false, let lastIndex be 0. + [...] + 12. Repeat, while matchSucceeded is false + [...] + c. If r is failure, then + i. If sticky is true, then + 1. Perform ? Set(R, "lastIndex", 0, true). + 2. Return null. +---*/ + +var gets = 0; +var counter = { + valueOf: function() { + gets++; + return 0; + } +}; + +var r = /a/; +r.lastIndex = counter; + +var result = r.exec('nbc'); +assert.sameValue(result, null); +assert.sameValue(r.lastIndex, counter); +assert.sameValue(gets, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-lastindex-set.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-lastindex-set.js new file mode 100644 index 0000000000..f5ff21f355 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/failure-lastindex-set.js @@ -0,0 +1,74 @@ +// Copyright (C) 2021 Richard Gibson. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + lastIndex is set to 0 after exhausting the string when global and/or sticky are set. +esid: sec-regexpbuiltinexec +info: | + RegExpBuiltinExec ( + _R_: an initialized RegExp instance, + _S_: a String, + ) + ... + 1. Let _length_ be the number of code units in _S_. + 2. Let _lastIndex_ be ℝ(? ToLength(? Get(_R_, *"lastIndex"*))). + 3. Let _flags_ be _R_.[[OriginalFlags]]. + 4. If _flags_ contains *"g"*, let _global_ be *true*; else let _global_ be *false*. + 5. If _flags_ contains *"y"*, let _sticky_ be *true*; else let _sticky_ be *false*. + ... + 9. Let _matchSucceeded_ be *false*. + 10. Repeat, while _matchSucceeded_ is *false*, + a. If _lastIndex_ > _length_, then + i. If _global_ is *true* or _sticky_ is *true*, then + 1. Perform ? Set(_R_, *"lastIndex"*, *+0*<sub>𝔽</sub>, *true*). + ii. Return *null*. +features: [exponentiation] +---*/ + +var R_g = /./g, R_y = /./y, R_gy = /./gy; + +var S = "test"; + +var lastIndex; +var bigLastIndexes = [ + Infinity, + Number.MAX_VALUE, + Number.MAX_SAFE_INTEGER, + Number.MAX_SAFE_INTEGER - 1, + 2**32 + 4, + 2**32 + 3, + 2**32 + 2, + 2**32 + 1, + 2**32, + 2**32 - 1, + 5 +]; +for ( var i = 0; i < bigLastIndexes.length; i++ ) { + lastIndex = bigLastIndexes[i]; + R_g.lastIndex = lastIndex; + R_y.lastIndex = lastIndex; + R_gy.lastIndex = lastIndex; + + assert.sameValue(R_g.exec(S), null, + "global RegExp instance must fail to match against '" + S + + "' at lastIndex " + lastIndex); + assert.sameValue(R_y.exec(S), null, + "sticky RegExp instance must fail to match against '" + S + + "' at lastIndex " + lastIndex); + assert.sameValue(R_gy.exec(S), null, + "global sticky RegExp instance must fail to match against '" + S + + "' at lastIndex " + lastIndex); + + assert.sameValue(R_g.lastIndex, 0, + "global RegExp instance lastIndex must be reset after " + lastIndex + + " exceeds string length"); + assert.sameValue(R_y.lastIndex, 0, + "sticky RegExp instance lastIndex must be reset after " + lastIndex + + " exceeds string length"); + assert.sameValue(R_gy.lastIndex, 0, + "global sticky RegExp instance lastIndex must be reset after " + lastIndex + + " exceeds string length"); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/name.js new file mode 100644 index 0000000000..89d0243a20 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.2 +description: > + RegExp.prototype.exec.name is "exec". +info: | + RegExp.prototype.exec ( string ) + + 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] +---*/ + +assert.sameValue(RegExp.prototype.exec.name, "exec"); + +verifyNotEnumerable(RegExp.prototype.exec, "name"); +verifyNotWritable(RegExp.prototype.exec, "name"); +verifyConfigurable(RegExp.prototype.exec, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/not-a-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/not-a-constructor.js new file mode 100644 index 0000000000..c4492952dd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/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.exec 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, arrow-function] +---*/ + +assert.sameValue( + isConstructor(RegExp.prototype.exec), + false, + 'isConstructor(RegExp.prototype.exec) must return false' +); + +assert.throws(TypeError, () => { + let re = new RegExp(''); new re.exec(); +}, '`let re = new RegExp(\'\'); new re.exec()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/success-g-lastindex-no-access.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/success-g-lastindex-no-access.js new file mode 100644 index 0000000000..0642cd4fe8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/success-g-lastindex-no-access.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: lastIndex is accessed when global is set. +es6id: 21.2.5.2.2 +info: | + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let flags be R.[[OriginalFlags]]. + 5. If flags contains "g", let global be true, else let global be false. + [...] + 15. If global is true or sticky is true, then + a. Perform ? Set(R, "lastIndex", e, true). +---*/ + +var lastIndexReads = 0; + +var r = /./g; +r.lastIndex = { + valueOf: function() { + lastIndexReads++; + return 0; + } +}; + +var result = r.exec('abc'); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 'a'); +assert.sameValue(r.lastIndex, 1); +assert.sameValue(lastIndexReads, 1); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/success-lastindex-access.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/success-lastindex-access.js new file mode 100644 index 0000000000..30f3c62d3f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/success-lastindex-access.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: lastIndex read but not written when global and sticky are unset. +es6id: 21.2.5.2.2 +info: | + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ? ToLength(? Get(R, "lastIndex")). + 5. Let flags be R.[[OriginalFlags]]. + 6. If flags contains "g", let global be true, else let global be false. + [...] + 15. If global is true or sticky is true, then + a. Perform ? Set(R, "lastIndex", e, true). +---*/ + +var gets = 0; +var counter = { + valueOf: function() { + gets++; + return 0; + } +}; + +var r = /./; +r.lastIndex = counter; + +var result = r.exec('abc'); + +assert.notSameValue(result, null); +assert.sameValue(result.length, 1); +assert.sameValue(result[0], 'a'); +assert.sameValue(r.lastIndex, counter); +assert.sameValue(gets, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/u-captured-value.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/u-captured-value.js new file mode 100644 index 0000000000..40b419e1c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/u-captured-value.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Encoding of `capturedValue` +es6id: 21.2.5.2.2 +info: | + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 12. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 13. If flags contains "u", let fullUnicode be true, else let fullUnicode be + false. + [...] + 28. For each integer i such that i > 0 and i ≤ n + a. Let captureI be ith element of r's captures List. + b. If captureI is undefined, let capturedValue be undefined. + c. Else if fullUnicode is true, + i. Assert: captureI is a List of code points. + ii. Let capturedValue be a string whose code units are the + UTF16Encoding (10.1.1) of the code points of captureI. + [...] + e. Perform CreateDataProperty(A, ToString(i) , capturedValue). + 29. Return A. +---*/ + +var match = /./u.exec('𝌆'); + +assert(match !== null); +assert.sameValue(match.length, 1); +assert.sameValue(match[0].length, 2); +assert.sameValue(match[0][0], '\ud834'); +assert.sameValue(match[0][1], '\udf06'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/u-lastindex-adv.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/u-lastindex-adv.js new file mode 100644 index 0000000000..405fc8cd43 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/u-lastindex-adv.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. + +/*--- +description: Advancement of lastIndex +es6id: 21.2.5.2.2 +info: | + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 12. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 13. If flags contains "u", let fullUnicode be true, else let fullUnicode be + false. + [...] + 15. Repeat, while matchSucceeded is false + [...] + c. If r is failure, then + [...] + ii. Let lastIndex be AdvanceStringIndex(S, lastIndex, fullUnicode). +---*/ + +assert.sameValue(/\udf06/u.exec('\ud834\udf06'), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/u-lastindex-value.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/u-lastindex-value.js new file mode 100644 index 0000000000..5c31efb0ef --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/u-lastindex-value.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. + +/*--- +description: Definition of `lastIndex` property value +es6id: 21.2.5.2.2 +info: | + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 12. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 13. If flags contains "u", let fullUnicode be true, else let fullUnicode be + false. + [...] + 16. Let e be r's endIndex value. + 17. If fullUnicode is true, then + a. e is an index into the Input character list, derived from S, matched + by matcher. Let eUTF be the smallest index into S that corresponds + to the character at element e of Input. If e is greater than or + equal to the length of Input, then eUTF is the number of code units + in S. + b. Let e be eUTF. + 18. If global is true or sticky is true, + a. Let setStatus be Set(R, "lastIndex", e, true). + b. ReturnIfAbrupt(setStatus). +---*/ + +var r = /./ug; +r.exec('𝌆'); +assert.sameValue(r.lastIndex, 2); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-fail-lastindex-no-write.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-fail-lastindex-no-write.js new file mode 100644 index 0000000000..5c353da177 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-fail-lastindex-no-write.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. + +/*--- +description: Match failure with non-writable `lastIndex` property +es6id: 21.2.5.2 +info: | + 21.2.5.2 RegExp.prototype.exec ( string ) + + [...] + 6. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). + 2. ReturnIfAbrupt(setStatus). +---*/ + +var r = /c/y; +Object.defineProperty(r, 'lastIndex', { + writable: false +}); + +assert.throws(TypeError, function() { + r.exec('abc'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-fail-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-fail-lastindex.js new file mode 100644 index 0000000000..f0da74c13f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-fail-lastindex.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Resets the `lastIndex` property to zero after a match failure +es6id: 21.2.5.2 +info: | + 21.2.5.2 RegExp.prototype.exec ( string ) + + [...] + 6. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). +---*/ + +var r = /c/y; +r.lastIndex = 1; + +r.exec('abc'); + +assert.sameValue(r.lastIndex, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-fail-return.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-fail-return.js new file mode 100644 index 0000000000..54767c3f16 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-fail-return.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: Stops match execution after first match failure +es6id: 21.2.5.2 +info: | + 21.2.5.2 RegExp.prototype.exec ( string ) + + [...] + 6. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + [...] + 3. Return null. +---*/ + +assert.sameValue(/b/y.exec('ab'), null); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-init-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-init-lastindex.js new file mode 100644 index 0000000000..ca5b7ea03b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-init-lastindex.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. + +/*--- +description: Honors initial value of the `lastIndex` property +es6id: 21.2.5.2 +info: | + 21.2.5.2 RegExp.prototype.exec ( string ) + + [...] + 6. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + 9. ReturnIfAbrupt(sticky). + 10. If global is false and sticky is false, let lastIndex be 0. +---*/ + +var r = /./y; +var match; +r.lastIndex = 1; + +match = r.exec('abc'); + +assert(match !== null); +assert.sameValue(match.length, 1); +assert.sameValue(match[0], 'b'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-set-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-set-lastindex.js new file mode 100644 index 0000000000..ff58a9aa61 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/exec/y-set-lastindex.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Sets the `lastIndex` property to the end index of the first match +es6id: 21.2.5.2 +info: | + 21.2.5.2 RegExp.prototype.exec ( string ) + + [...] + 6. Return RegExpBuiltinExec(R, S). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 18. If global is true or sticky is true, + a. Let setStatus be Set(R, "lastIndex", e, true). +---*/ + +var r = /abc/y; +r.exec('abc'); + +assert.sameValue(r.lastIndex, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-dotall.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-dotall.js new file mode 100644 index 0000000000..7b6afe6f54 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-dotall.js @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Boolean coercion of the dotAll property +info: | + get RegExp.prototype.flags + + ... + 10. Let dotAll be ToBoolean(? Get(R, "dotAll")). + ... +features: [Symbol, regexp-dotall] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get; + +var r = {}; + +r.dotAll = undefined; +assert.sameValue(get.call(r), "", "dotAll: undefined"); + +r.dotAll = null; +assert.sameValue(get.call(r), "", "dotAll: null"); + +r.dotAll = NaN; +assert.sameValue(get.call(r), "", "dotAll: NaN"); + +r.dotAll = ""; +assert.sameValue(get.call(r), "", "dotAll: the empty string"); + +r.dotAll = "string"; +assert.sameValue(get.call(r), "s", "dotAll: string"); + +r.dotAll = 86; +assert.sameValue(get.call(r), "s", "dotAll: 86"); + +r.dotAll = Symbol(); +assert.sameValue(get.call(r), "s", "dotAll: Symbol()"); + +r.dotAll = []; +assert.sameValue(get.call(r), "s", "dotAll: []"); + +r.dotAll = {}; +assert.sameValue(get.call(r), "s", "dotAll: {}"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-global.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-global.js new file mode 100644 index 0000000000..1ad31f0647 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-global.js @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Boolean coercion of the global property +info: | + get RegExp.prototype.flags + + ... + 4. Let global be ToBoolean(? Get(R, "global")). + ... +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get; + +var r = {}; + +r.global = undefined; +assert.sameValue(get.call(r), "", "global: undefined"); + +r.global = null; +assert.sameValue(get.call(r), "", "global: null"); + +r.global = NaN; +assert.sameValue(get.call(r), "", "global: NaN"); + +r.global = ""; +assert.sameValue(get.call(r), "", "global: the empty string"); + +r.global = "string"; +assert.sameValue(get.call(r), "g", "global: string"); + +r.global = 86; +assert.sameValue(get.call(r), "g", "global: 86"); + +r.global = Symbol(); +assert.sameValue(get.call(r), "g", "global: Symbol()"); + +r.global = []; +assert.sameValue(get.call(r), "g", "global: []"); + +r.global = {}; +assert.sameValue(get.call(r), "g", "global: {}"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-hasIndices.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-hasIndices.js new file mode 100644 index 0000000000..7e791b33a3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-hasIndices.js @@ -0,0 +1,47 @@ +// Copyright (C) 2021 Ron Buckton and Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Boolean coercion of the hasIndices property +info: | + get RegExp.prototype.flags + + ... + 10. Let hasIndices be ToBoolean(? Get(R, "hasIndices")). + ... +features: [Symbol, regexp-match-indices] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get; + +var r = {}; + +r.hasIndices = undefined; +assert.sameValue(get.call(r), "", "hasIndices: undefined"); + +r.hasIndices = null; +assert.sameValue(get.call(r), "", "hasIndices: null"); + +r.hasIndices = NaN; +assert.sameValue(get.call(r), "", "hasIndices: NaN"); + +r.hasIndices = ""; +assert.sameValue(get.call(r), "", "hasIndices: the empty string"); + +r.hasIndices = "string"; +assert.sameValue(get.call(r), "d", "hasIndices: string"); + +r.hasIndices = 86; +assert.sameValue(get.call(r), "d", "hasIndices: 86"); + +r.hasIndices = Symbol(); +assert.sameValue(get.call(r), "d", "hasIndices: Symbol()"); + +r.hasIndices = []; +assert.sameValue(get.call(r), "d", "hasIndices: []"); + +r.hasIndices = {}; +assert.sameValue(get.call(r), "d", "hasIndices: {}"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-ignoreCase.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-ignoreCase.js new file mode 100644 index 0000000000..076b7feca2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-ignoreCase.js @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Boolean coercion of the ignoreCase property +info: | + get RegExp.prototype.flags + + ... + 6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + ... +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get; + +var r = {}; + +r.ignoreCase = undefined; +assert.sameValue(get.call(r), "", "ignoreCase: undefined"); + +r.ignoreCase = null; +assert.sameValue(get.call(r), "", "ignoreCase: null"); + +r.ignoreCase = NaN; +assert.sameValue(get.call(r), "", "ignoreCase: NaN"); + +r.ignoreCase = ""; +assert.sameValue(get.call(r), "", "ignoreCase: the empty string"); + +r.ignoreCase = "string"; +assert.sameValue(get.call(r), "i", "ignoreCase: string"); + +r.ignoreCase = 86; +assert.sameValue(get.call(r), "i", "ignoreCase: 86"); + +r.ignoreCase = Symbol(); +assert.sameValue(get.call(r), "i", "ignoreCase: Symbol()"); + +r.ignoreCase = []; +assert.sameValue(get.call(r), "i", "ignoreCase: []"); + +r.ignoreCase = {}; +assert.sameValue(get.call(r), "i", "ignoreCase: {}"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-multiline.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-multiline.js new file mode 100644 index 0000000000..976c94aa13 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-multiline.js @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Boolean coercion of the multiline property +info: | + get RegExp.prototype.flags + + ... + 8. Let multiline be ToBoolean(? Get(R, "multiline")). + ... +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get; + +var r = {}; + +r.multiline = undefined; +assert.sameValue(get.call(r), "", "multiline: undefined"); + +r.multiline = null; +assert.sameValue(get.call(r), "", "multiline: null"); + +r.multiline = NaN; +assert.sameValue(get.call(r), "", "multiline: NaN"); + +r.multiline = ""; +assert.sameValue(get.call(r), "", "multiline: the empty string"); + +r.multiline = "string"; +assert.sameValue(get.call(r), "m", "multiline: string"); + +r.multiline = 86; +assert.sameValue(get.call(r), "m", "multiline: 86"); + +r.multiline = Symbol(); +assert.sameValue(get.call(r), "m", "multiline: Symbol()"); + +r.multiline = []; +assert.sameValue(get.call(r), "m", "multiline: []"); + +r.multiline = {}; +assert.sameValue(get.call(r), "m", "multiline: {}"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-sticky.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-sticky.js new file mode 100644 index 0000000000..6ebd0cf5e9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-sticky.js @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Boolean coercion of the sticky property +info: | + get RegExp.prototype.flags + + ... + 14. Let sticky be ToBoolean(? Get(R, "sticky")). + ... +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get; + +var r = {}; + +r.sticky = undefined; +assert.sameValue(get.call(r), "", "sticky: undefined"); + +r.sticky = null; +assert.sameValue(get.call(r), "", "sticky: null"); + +r.sticky = NaN; +assert.sameValue(get.call(r), "", "sticky: NaN"); + +r.sticky = ""; +assert.sameValue(get.call(r), "", "sticky: the empty string"); + +r.sticky = "string"; +assert.sameValue(get.call(r), "y", "sticky: string"); + +r.sticky = 86; +assert.sameValue(get.call(r), "y", "sticky: 86"); + +r.sticky = Symbol(); +assert.sameValue(get.call(r), "y", "sticky: Symbol()"); + +r.sticky = []; +assert.sameValue(get.call(r), "y", "sticky: []"); + +r.sticky = {}; +assert.sameValue(get.call(r), "y", "sticky: {}"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-unicode.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-unicode.js new file mode 100644 index 0000000000..e6c2ed48a7 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/coercion-unicode.js @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Boolean coercion of the unicode property +info: | + get RegExp.prototype.flags + + ... + 12. Let unicode be ToBoolean(? Get(R, "unicode")). + ... +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get; + +var r = {}; + +r.unicode = undefined; +assert.sameValue(get.call(r), "", "unicode: undefined"); + +r.unicode = null; +assert.sameValue(get.call(r), "", "unicode: null"); + +r.unicode = NaN; +assert.sameValue(get.call(r), "", "unicode: NaN"); + +r.unicode = ""; +assert.sameValue(get.call(r), "", "unicode: the empty string"); + +r.unicode = "string"; +assert.sameValue(get.call(r), "u", "unicode: string"); + +r.unicode = 86; +assert.sameValue(get.call(r), "u", "unicode: 86"); + +r.unicode = Symbol(); +assert.sameValue(get.call(r), "u", "unicode: Symbol()"); + +r.unicode = []; +assert.sameValue(get.call(r), "u", "unicode: []"); + +r.unicode = {}; +assert.sameValue(get.call(r), "u", "unicode: {}"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/get-order.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/get-order.js new file mode 100644 index 0000000000..4b8e8acc52 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/get-order.js @@ -0,0 +1,51 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Gets are performed in specified order +info: | + get RegExp.prototype.flags + + [...] + 4. let hasIndices be ToBoolean(? Get(R, "hasIndices")) + 6. Let global be ToBoolean(? Get(R, "global")). + 8. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + 10. Let multiline be ToBoolean(? Get(R, "multiline")). + 12. Let dotAll be ToBoolean(? Get(R, "dotAll")). + 14. Let unicode be ToBoolean(? Get(R, "unicode")). + 18. Let sticky be ToBoolean(? Get(R, "sticky")). +features: [regexp-dotall, regexp-match-indices] +---*/ + +var calls = ''; +var re = { + get hasIndices() { + calls += 'd'; + }, + get global() { + calls += 'g'; + }, + get ignoreCase() { + calls += 'i'; + }, + get multiline() { + calls += 'm'; + }, + get dotAll() { + calls += 's'; + }, + get unicode() { + calls += 'u'; + }, + get sticky() { + calls += 'y'; + }, +}; + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + +get.call(re); +assert.sameValue(calls, 'dgimsuy'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/length.js new file mode 100644 index 0000000000..6ceb16cd22 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/length.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-get-regexp.prototype.flags +description: > + get RegExp.prototype.flags.length is 0. +info: | + get RegExp.prototype.flags + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + +verifyProperty(get, 'length', { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/name.js new file mode 100644 index 0000000000..0ea73c639d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/name.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. + +/*--- +esid: sec-get-regexp.prototype.flags +description: > + get RegExp.prototype.flags.name is "get flags". +info: | + get RegExp.prototype.flags + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + + 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] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + +verifyProperty(get, 'name', { + value: 'get flags', + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/prop-desc.js new file mode 100644 index 0000000000..ad0bf43336 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/prop-desc.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: > + get RegExp.prototype.flags property descriptor +info: | + get RegExp.prototype.flags + + RegExp.prototype.flags is an accessor property whose set accessor + function is undefined +includes: [propertyHelper.js] +---*/ + +var d = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'); + +assert.sameValue(typeof d.get, 'function', 'typeof d.get'); +assert.sameValue(d.set, undefined, 'd.set'); + +verifyProperty(RegExp.prototype, 'flags', { + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/rethrow.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/rethrow.js new file mode 100644 index 0000000000..b6ca38a3f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/rethrow.js @@ -0,0 +1,79 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: Rethrows exceptions raised in property gets +info: | + get RegExp.prototype.flags + + [...] + 4. let hasIndices be ToBoolean(? Get(R, "hasIndices")) + 6. Let global be ToBoolean(? Get(R, "global")). + 8. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + 10. Let multiline be ToBoolean(? Get(R, "multiline")). + 12. Let dotAll be ToBoolean(? Get(R, "dotAll")). + 14. Let unicode be ToBoolean(? Get(R, "unicode")). + 18. Let sticky be ToBoolean(? Get(R, "sticky")). +features: [regexp-dotall, regexp-match-indices] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + +assert.throws(Test262Error, function() { + get.call({ + get hasIndices() { + throw new Test262Error(); + }, + }); +}, 'Let hasIndices be ToBoolean(? Get(R, "hasIndices"))'); + +assert.throws(Test262Error, function() { + get.call({ + get global() { + throw new Test262Error(); + }, + }); +}, 'Let global be ToBoolean(? Get(R, "global"))'); + +assert.throws(Test262Error, function() { + get.call({ + get ignoreCase() { + throw new Test262Error(); + }, + }); +}, 'Let ignoreCase be ToBoolean(? Get(R, "ignoreCase"))'); + +assert.throws(Test262Error, function() { + get.call({ + get multiline() { + throw new Test262Error(); + }, + }); +}, 'Let multiline be ToBoolean(? Get(R, "multiline"))'); + +assert.throws(Test262Error, function() { + get.call({ + get dotAll() { + throw new Test262Error(); + }, + }); +}, 'Let dotAll be ToBoolean(? Get(R, "dotAll"))'); + +assert.throws(Test262Error, function() { + get.call({ + get unicode() { + throw new Test262Error(); + }, + }); +}, 'Let unicode be ToBoolean(? Get(R, "unicode"))'); + +assert.throws(Test262Error, function() { + get.call({ + get sticky() { + throw new Test262Error(); + }, + }); +}, 'Let sticky be ToBoolean(? Get(R, "sticky"))'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/return-order.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/return-order.js new file mode 100644 index 0000000000..437f27daeb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/return-order.js @@ -0,0 +1,29 @@ +// Copyright (C) 2017 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: > + RegExp.prototype.flags come in a single order, independent of source order +info: | + 4. Let global be ToBoolean(? Get(R, "global")). + 5. If global is true, append "g" as the last code unit of result. + 6. Let global be ToBoolean(? Get(R, "global")). + 7. If global is true, append "g" as the last code unit of result. + 8. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + 9. If ignoreCase is true, append "i" as the last code unit of result. + 10. Let multiline be ToBoolean(? Get(R, "multiline")). + 11. If multiline is true, append "m" as the last code unit of result. + 12. Let dotAll be ToBoolean(? Get(R, "dotAll")). + 13. If dotAll is true, append "s" as the last code unit of result. + 14. Let unicode be ToBoolean(? Get(R, "unicode")). + 15. If unicode is true, append "u" as the last code unit of result. + 16. Let sticky be ToBoolean(? Get(R, "sticky")). + 17. If sticky is true, append "y" as the last code unit of result. +features: [regexp-dotall, regexp-match-indices] +---*/ + +assert.sameValue(new RegExp("", "dgimsuy").flags, "dgimsuy", "dgimsuy => dgimsuy"); +assert.sameValue(new RegExp("", "yusmigd").flags, "dgimsuy", "yusmigd => dgimsuy"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/this-val-non-obj.js new file mode 100644 index 0000000000..305e729589 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/this-val-non-obj.js @@ -0,0 +1,43 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: A TypeError is thrown when the `this` value is not an Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + +assert.throws(TypeError, function() { + get.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + get.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + get.call(4); +}, 'number'); + +assert.throws(TypeError, function() { + get.call('string'); +}, 'string'); + +assert.throws(TypeError, function() { + get.call(false); +}, 'boolean'); + +assert.throws(TypeError, function() { + get.call(Symbol()); +}, 'symbol'); + +assert.throws(TypeError, function() { + get.call(4n); +}, 'bigint'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/this-val-regexp-prototype.js new file mode 100644 index 0000000000..a182860c73 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/this-val-regexp-prototype.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: > + Return "" when the `this` value is the RegExp.prototype object +info: | + 3. Let result be the empty String. + 4. Let global be ToBoolean(? Get(R, "global")). + 5. If global is true, append "g" as the last code unit of result. + 6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + 7. If ignoreCase is true, append "i" as the last code unit of result. + 8. Let multiline be ToBoolean(? Get(R, "multiline")). + 9. If multiline is true, append "m" as the last code unit of result. + 10. Let dotAll be ToBoolean(? Get(R, "dotAll")). + 11. If dotAll is true, append "s" as the last code unit of result. + 12. Let unicode be ToBoolean(? Get(R, "unicode")). + 13. If unicode is true, append "u" as the last code unit of result. + 14. Let sticky be ToBoolean(? Get(R, "sticky")). + 15. If sticky is true, append "y" as the last code unit of result. + 16. Return result. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags').get; + +assert.sameValue(get.call(RegExp.prototype), ''); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/flags/this-val-regexp.js b/js/src/tests/test262/built-ins/RegExp/prototype/flags/this-val-regexp.js new file mode 100644 index 0000000000..48ffaf6938 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/flags/this-val-regexp.js @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.flags +description: > + RegExp.prototype.flags returns RegExp flags as a string +info: | + 3. Let result be the empty String. + 4. Let global be ToBoolean(? Get(R, "global")). + 5. If global is true, append "g" as the last code unit of result. + 6. Let ignoreCase be ToBoolean(? Get(R, "ignoreCase")). + 7. If ignoreCase is true, append "i" as the last code unit of result. + 8. Let multiline be ToBoolean(? Get(R, "multiline")). + 9. If multiline is true, append "m" as the last code unit of result. + 10. Let dotAll be ToBoolean(? Get(R, "dotAll")). + 11. If dotAll is true, append "s" as the last code unit of result. + 12. Let unicode be ToBoolean(? Get(R, "unicode")). + 13. If unicode is true, append "u" as the last code unit of result. + 14. Let unicodeSets be ! ToBoolean(? Get(R, "unicodeSets")). + 15. If unicodeSets is true, append "v" as the last code unit of result. + 16. Let sticky be ToBoolean(? Get(R, "sticky")). + 17. If sticky is true, append "y" as the last code unit of result. + 18. Return result. +features: [regexp-dotall, regexp-match-indices, regexp-v-flag] +---*/ + +assert.sameValue(/./.flags, '', 'no flags'); +assert.sameValue(/./d.flags, 'd', 'hasIndices'); +assert.sameValue(/./g.flags, 'g', 'global'); +assert.sameValue(/./i.flags, 'i', 'ignoreCase'); +assert.sameValue(/./m.flags, 'm', 'multiline'); +assert.sameValue(/./s.flags, 's', 'dotAll'); +assert.sameValue(/./u.flags, 'u', 'unicode'); +assert.sameValue(/./v.flags, 'v', 'unicodeSets'); +assert.sameValue(/./y.flags, 'y', 'sticky'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/15.10.7.2-2.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/15.10.7.2-2.js new file mode 100644 index 0000000000..c615203c44 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/15.10.7.2-2.js @@ -0,0 +1,19 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 15.10.7.2-2 +description: > + RegExp.prototype.global is an accessor property whose set accessor + function is undefined +---*/ + + var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'global'); + + +assert.sameValue(typeof desc.get, 'function', 'typeof desc.get'); +assert.sameValue(desc.set, undefined, 'desc.set'); +assert.sameValue(desc.enumerable, false, 'desc.enumerable'); +assert.sameValue(desc.configurable, true, 'desc.configurable'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/S15.10.7.2_A10.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/S15.10.7.2_A10.js new file mode 100644 index 0000000000..9f1722c642 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/S15.10.7.2_A10.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype global property does not have a set accessor +es5id: 15.10.7.2_A10 +description: Checking if varying the global property fails +includes: [propertyHelper.js] +---*/ + +var __re = RegExp.prototype; + +assert.sameValue(__re.hasOwnProperty('global'), true, '__re.hasOwnProperty(\'global\') must return true'); + +var __sample = /^|^/; +var __obj = __sample.global; + +verifyNotWritable(__sample, "global", "global", "shifted"); + +assert.sameValue(__sample.global, __obj, 'The value of __sample.global is expected to equal the value of __obj'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/S15.10.7.2_A8.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/S15.10.7.2_A8.js new file mode 100644 index 0000000000..c2f69b59ae --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/S15.10.7.2_A8.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype global property has the attribute DontEnum +es5id: 15.10.7.2_A8 +description: > + Checking if enumerating the global property of RegExp.prototype + fails +---*/ + +var __re = RegExp.prototype; + +assert.sameValue(__re.hasOwnProperty('global'), true, '__re.hasOwnProperty(\'global\') must return true'); + +assert.sameValue( + __re.propertyIsEnumerable('global'), + false, + '__re.propertyIsEnumerable(\'global\') must return false' +); + +var count = 0 +for (var p in __re){ + if (p==="global") { + count++ + } +} + +assert.sameValue(count, 0, 'The value of count is expected to be 0'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/S15.10.7.2_A9.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/S15.10.7.2_A9.js new file mode 100644 index 0000000000..2a2f0f14c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/S15.10.7.2_A9.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The RegExp.prototype global property does not have the attribute + DontDelete +es5id: 15.10.7.2_A9 +description: Checking if deleting the global property succeeds +---*/ + +var __re = RegExp.prototype; + +assert.sameValue(__re.hasOwnProperty('global'), true, '__re.hasOwnProperty(\'global\') must return true'); +assert.sameValue(delete __re.global, true, 'The value of `delete __re.global` is expected to be true'); +assert.sameValue(__re.hasOwnProperty('global'), false, '__re.hasOwnProperty(\'global\') must return false'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/cross-realm.js new file mode 100644 index 0000000000..b903f21996 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/cross-realm.js @@ -0,0 +1,28 @@ +// 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-get-regexp.prototype.global +description: A TypeError is thrown when the "this" value is an invalid cross-realm Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +features: [cross-realm] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'global').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'global').get; + +assert.throws(TypeError, function() { + get.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/length.js new file mode 100644 index 0000000000..d2802441f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.4 +description: > + get RegExp.prototype.global.length is 0. +info: | + get RegExp.prototype.global + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "global"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/name.js new file mode 100644 index 0000000000..ba8ace9def --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/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.4 +description: > + RegExp.prototype.global name +info: | + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'global'); + +assert.sameValue( + descriptor.get.name, + 'get global' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/this-val-invalid-obj.js new file mode 100644 index 0000000000..3e51f470cd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/this-val-invalid-obj.js @@ -0,0 +1,32 @@ +// 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-get-regexp.prototype.global +description: A TypeError is thrown when the "this" value is an invalid Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'global').get; + +assert.throws(TypeError, function() { + get.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + get.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + get.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + get.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/this-val-non-obj.js new file mode 100644 index 0000000000..daf345583d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/this-val-non-obj.js @@ -0,0 +1,43 @@ +// 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-get-regexp.prototype.global +description: A TypeError is thrown when the "this" value is not an Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'global').get; +var symbol = Symbol(); + +assert.throws(TypeError, function() { + get.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + get.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + get.call(3); +}, 'number'); + +assert.throws(TypeError, function() { + get.call('string'); +}, 'string'); + +assert.throws(TypeError, function() { + get.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + get.call(symbol); +}, 'symbol'); + +assert.throws(TypeError, function() { + get.call(4n); +}, 'bigint'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/global/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/global/this-val-regexp-prototype.js new file mode 100644 index 0000000000..9d899b1021 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/global/this-val-regexp-prototype.js @@ -0,0 +1,19 @@ +// 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-get-regexp.prototype.global +description: > + Return value of `undefined` when the "this" value is the RegExp prototype + object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'global').get; + +assert.sameValue(get.call(RegExp.prototype), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/cross-realm.js new file mode 100644 index 0000000000..93d85a4160 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/cross-realm.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.hasindices +description: Invoked on a cross-realm object +info: | + get RegExp.prototype.hasIndices + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +features: [regexp-match-indices, cross-realm] +---*/ + +var hasIndices = Object.getOwnPropertyDescriptor(RegExp.prototype, 'hasIndices').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'hasIndices').get; + +assert.throws(TypeError, function() { + hasIndices.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/length.js new file mode 100644 index 0000000000..2a6c54f440 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/length.js @@ -0,0 +1,36 @@ +// Copyright (C) 2021 Ron Buckton and André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.hasindices +description: > + get RegExp.prototype.hasIndices.length is 0. +info: | + get RegExp.prototype.hasIndices + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [regexp-match-indices] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices"); + +assert.sameValue(desc.get.length, 0); + +verifyProperty(desc.get, "length", { + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/name.js new file mode 100644 index 0000000000..9649fd3133 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2021 Ron buckton and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.hasindices +description: > + RegExp.prototype.hasIndices name +info: | + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. +includes: [propertyHelper.js] +features: [regexp-match-indices] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices"); + +assert.sameValue( + desc.get.name, + "get hasIndices" +); + +verifyProperty(desc.get, "name", { + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/prop-desc.js new file mode 100644 index 0000000000..27a593b5c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/prop-desc.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 Ron Buckton and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.hasIndices +description: > + `pending` property descriptor +info: | + RegExp.prototype.hasIndices is an accessor property whose set accessor + function is undefined. + + 17 ECMAScript Standard Built-in Objects + + Every accessor property described in clauses 18 through 26 and in Annex B.2 has the attributes + { [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. If only a get + accessor function is described, the set accessor function is the default value, undefined. If + only a set accessor is described the get accessor is the default value, undefined. +includes: [propertyHelper.js] +features: [regexp-match-indices] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyProperty(RegExp.prototype, "hasIndices", { + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-invalid-obj.js new file mode 100644 index 0000000000..44bb0c8880 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-invalid-obj.js @@ -0,0 +1,36 @@ +// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.hasindices +description: Invoked on an object without an [[OriginalFlags]] internal slot +info: | + get RegExp.prototype.hasIndices + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +features: [regexp-match-indices] +---*/ + +var hasIndices = Object.getOwnPropertyDescriptor(RegExp.prototype, 'hasIndices').get; + +assert.throws(TypeError, function() { + hasIndices.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + hasIndices.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + hasIndices.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + hasIndices.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-non-obj.js new file mode 100644 index 0000000000..ac6f7d78e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-non-obj.js @@ -0,0 +1,46 @@ +// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.hasindices +description: > + `hasIndices` accessor invoked on a non-object value +info: | + get RegExp.prototype.hasIndices + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol, regexp-match-indices] +---*/ + +var hasIndices = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices").get; + +assert.throws(TypeError, function() { + hasIndices.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + hasIndices.call(null); +}, "null"); + +assert.throws(TypeError, function() { + hasIndices.call(true); +}, "true"); + +assert.throws(TypeError, function() { + hasIndices.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + hasIndices.call(Symbol("s")); +}, "symbol"); + +assert.throws(TypeError, function() { + hasIndices.call(4); +}, "number"); + +assert.throws(TypeError, function() { + hasIndices.call(4n); +}, "bigint"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-regexp-prototype.js new file mode 100644 index 0000000000..8bdd4394c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-regexp-prototype.js @@ -0,0 +1,21 @@ +// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.hasIndices +description: > + Return value of `undefined` when the "this" value is the RegExp prototype + object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. +features: [regexp-match-indices] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "hasIndices").get; + +assert.sameValue(get.call(RegExp.prototype), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-regexp.js b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-regexp.js new file mode 100644 index 0000000000..b029c46a47 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/hasIndices/this-val-regexp.js @@ -0,0 +1,49 @@ +// Copyright (C) 2021 Ron Buckton and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.hasindices +description: > + `hasIndices` accessor function invoked on a RegExp instance +info: | + 21.2.5.12 get RegExp.prototype.hasIndices + + 4. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 5. If flags contains the code unit "s", return true. + 6. Return false. +features: [regexp-match-indices] +---*/ + +assert.sameValue(/./.hasIndices, false, "/./.hasIndices"); +assert.sameValue(/./i.hasIndices, false, "/./i.hasIndices"); +assert.sameValue(/./g.hasIndices, false, "/./g.hasIndices"); +assert.sameValue(/./y.hasIndices, false, "/./y.hasIndices"); +assert.sameValue(/./m.hasIndices, false, "/./m.hasIndices"); +assert.sameValue(/./s.hasIndices, false, "/./s.hasIndices"); +assert.sameValue(/./u.hasIndices, false, "/./u.hasIndices"); + +assert.sameValue(/./d.hasIndices, true, "/./d.hasIndices"); +assert.sameValue(/./di.hasIndices, true, "/./di.hasIndices"); +assert.sameValue(/./dg.hasIndices, true, "/./dg.hasIndices"); +assert.sameValue(/./dy.hasIndices, true, "/./dy.hasIndices"); +assert.sameValue(/./dm.hasIndices, true, "/./dm.hasIndices"); +assert.sameValue(/./ds.hasIndices, true, "/./ds.hasIndices"); +assert.sameValue(/./du.hasIndices, true, "/./du.hasIndices"); + +assert.sameValue(new RegExp(".", "").hasIndices, false, "new RegExp('.', '').hasIndices"); +assert.sameValue(new RegExp(".", "i").hasIndices, false, "new RegExp('.', 'i').hasIndices"); +assert.sameValue(new RegExp(".", "g").hasIndices, false, "new RegExp('.', 'g').hasIndices"); +assert.sameValue(new RegExp(".", "y").hasIndices, false, "new RegExp('.', 'y').hasIndices"); +assert.sameValue(new RegExp(".", "m").hasIndices, false, "new RegExp('.', 'm').hasIndices"); +assert.sameValue(new RegExp(".", "s").hasIndices, false, "new RegExp('.', 's').hasIndices"); +assert.sameValue(new RegExp(".", "u").hasIndices, false, "new RegExp('.', 'u').hasIndices"); + +assert.sameValue(new RegExp(".", "d").hasIndices, true, "new RegExp('.', 'd').hasIndices"); +assert.sameValue(new RegExp(".", "di").hasIndices, true, "new RegExp('.', 'di').hasIndices"); +assert.sameValue(new RegExp(".", "dg").hasIndices, true, "new RegExp('.', 'dg').hasIndices"); +assert.sameValue(new RegExp(".", "dy").hasIndices, true, "new RegExp('.', 'dy').hasIndices"); +assert.sameValue(new RegExp(".", "dm").hasIndices, true, "new RegExp('.', 'dm').hasIndices"); +assert.sameValue(new RegExp(".", "ds").hasIndices, true, "new RegExp('.', 'ds').hasIndices"); +assert.sameValue(new RegExp(".", "du").hasIndices, true, "new RegExp('.', 'du').hasIndices"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/15.10.7.3-2.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/15.10.7.3-2.js new file mode 100644 index 0000000000..125ec41eb4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/15.10.7.3-2.js @@ -0,0 +1,19 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 15.10.7.3-2 +description: > + RegExp.prototype.ignoreCase is an accessor property whose set + accessor function is undefined +---*/ + + var d = Object.getOwnPropertyDescriptor(RegExp.prototype, 'ignoreCase'); + + +assert.sameValue(typeof d.get, 'function', 'typeof d.get'); +assert.sameValue(d.set, undefined, 'd.set'); +assert.sameValue(d.enumerable, false, 'd.enumerable'); +assert.sameValue(d.configurable, true, 'd.configurable'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A10.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A10.js new file mode 100644 index 0000000000..17c3ecb5bb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A10.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype ignoreCase property does not have a set accessor +es5id: 15.10.7.3_A10 +description: Checking if varying the ignoreCase property fails +includes: [propertyHelper.js] +---*/ + +var __re = RegExp.prototype; + +assert.sameValue(__re.hasOwnProperty('ignoreCase'), true, '__re.hasOwnProperty(\'ignoreCase\') must return true'); + +var __sample = /a|b|c/; +var __obj = __sample.ignoreCase; + +verifyNotWritable(__sample, "ignoreCase", "ignoreCase", "shifted"); + +assert.sameValue( + __sample.ignoreCase, + __obj, + 'The value of __sample.ignoreCase is expected to equal the value of __obj' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A8.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A8.js new file mode 100644 index 0000000000..a70df8a51e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A8.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype ignoreCase property has the attribute DontEnum +es5id: 15.10.7.3_A8 +description: > + Checking if enumerating the ignoreCase property of + RegExp.prototype fails +---*/ + +var __re = RegExp.prototype; + +assert.sameValue(__re.hasOwnProperty('ignoreCase'), true, '__re.hasOwnProperty(\'ignoreCase\') must return true'); + +assert.sameValue( + __re.propertyIsEnumerable('ignoreCase'), + false, + '__re.propertyIsEnumerable(\'ignoreCase\') must return false' +); + +var count = 0 +for (var p in __re){ + if (p==="ignoreCase") { + count++ + } +} + +assert.sameValue(count, 0, 'The value of count is expected to be 0'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A9.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A9.js new file mode 100644 index 0000000000..70edcce662 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/S15.10.7.3_A9.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The RegExp.prototype ignoreCase property does not have the attribute + DontDelete +es5id: 15.10.7.3_A9 +description: Checking if deleting the ignoreCase property succeeds +---*/ + +var __re = RegExp.prototype; + +assert.sameValue(__re.hasOwnProperty('ignoreCase'), true, '__re.hasOwnProperty(\'ignoreCase\') must return true'); +assert.sameValue(delete __re.ignoreCase, true, 'The value of `delete __re.ignoreCase` is expected to be true'); +assert.sameValue(__re.hasOwnProperty('ignoreCase'), false, '__re.hasOwnProperty(\'ignoreCase\') must return false'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/cross-realm.js new file mode 100644 index 0000000000..8a56805273 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/cross-realm.js @@ -0,0 +1,28 @@ +// 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-get-regexp.prototype.ignorecase +description: A TypeError is thrown when the "this" value is an invalid cross-realm Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +features: [cross-realm] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'ignoreCase').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'ignoreCase').get; + +assert.throws(TypeError, function() { + get.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/length.js new file mode 100644 index 0000000000..3707ec5ad1 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.5 +description: > + get RegExp.prototype.ignoreCase.length is 0. +info: | + get RegExp.prototype.ignoreCase + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "ignoreCase"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/name.js new file mode 100644 index 0000000000..1f3894cbbe --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/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.5 +description: > + RegExp.prototype.ignoreCase name +info: | + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'ignoreCase'); + +assert.sameValue( + descriptor.get.name, + 'get ignoreCase' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/this-val-invalid-obj.js new file mode 100644 index 0000000000..4ffb9390e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/this-val-invalid-obj.js @@ -0,0 +1,32 @@ +// 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-get-regexp.prototype.ignorecase +description: A TypeError is thrown when the "this" value is an invalid Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'ignoreCase').get; + +assert.throws(TypeError, function() { + get.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + get.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + get.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + get.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/this-val-non-obj.js new file mode 100644 index 0000000000..00ac21cc25 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/this-val-non-obj.js @@ -0,0 +1,43 @@ +// 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-get-regexp.prototype.ignorecase +description: A TypeError is thrown when the "this" value is not an Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'ignoreCase').get; +var symbol = Symbol(); + +assert.throws(TypeError, function() { + get.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + get.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + get.call(3); +}, 'number'); + +assert.throws(TypeError, function() { + get.call('string'); +}, 'string'); + +assert.throws(TypeError, function() { + get.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + get.call(symbol); +}, 'symbol'); + +assert.throws(TypeError, function() { + get.call(4n); +}, 'bigint'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/this-val-regexp-prototype.js new file mode 100644 index 0000000000..51157d86b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/ignoreCase/this-val-regexp-prototype.js @@ -0,0 +1,19 @@ +// 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-get-regexp.prototype.ignorecase +description: > + Return value of `undefined` when the "this" value is the RegExp prototype + object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'ignoreCase').get; + +assert.sameValue(get.call(RegExp.prototype), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/15.10.7.4-2.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/15.10.7.4-2.js new file mode 100644 index 0000000000..d554e1046c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/15.10.7.4-2.js @@ -0,0 +1,19 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 15.10.7.4-2 +description: > + RegExp.prototype.multiline is an accessor property whose set + accessor function is undefined +---*/ + + var d = Object.getOwnPropertyDescriptor(RegExp.prototype, 'multiline'); + + +assert.sameValue(typeof d.get, 'function', 'typeof d.get'); +assert.sameValue(d.set, undefined, 'd.set'); +assert.sameValue(d.enumerable, false, 'd.enumerable'); +assert.sameValue(d.configurable, true, 'd.configurable'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/S15.10.7.4_A10.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/S15.10.7.4_A10.js new file mode 100644 index 0000000000..b5d5653e08 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/S15.10.7.4_A10.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype multiline property does not have a set accessor +es5id: 15.10.7.4_A10 +description: Checking if varying the multiline property fails +includes: [propertyHelper.js] +---*/ + +var __re = RegExp.prototype; + +assert.sameValue(__re.hasOwnProperty('multiline'), true, '__re.hasOwnProperty(\'multiline\') must return true'); + +var __sample = /\n/; +var __obj = __sample.multiline; + +verifyNotWritable(__sample, "multiline", "multiline", "shifted"); + +assert.sameValue(__sample.multiline, __obj, 'The value of __sample.multiline is expected to equal the value of __obj'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/S15.10.7.4_A8.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/S15.10.7.4_A8.js new file mode 100644 index 0000000000..f4a2868a7b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/S15.10.7.4_A8.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype multiline property has the attribute DontEnum +es5id: 15.10.7.4_A8 +description: > + Checking if enumerating the multiline property of RegExp.prototype + fails +---*/ + +var __re = RegExp.prototype; + +assert.sameValue(__re.hasOwnProperty('multiline'), true, '__re.hasOwnProperty(\'multiline\') must return true'); + +assert.sameValue( + __re.propertyIsEnumerable('multiline'), + false, + '__re.propertyIsEnumerable(\'multiline\') must return false' +); + +var count = 0 +for (var p in __re){ + if (p==="multiline") { + count++ + } +} + +assert.sameValue(count, 0, 'The value of count is expected to be 0'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/S15.10.7.4_A9.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/S15.10.7.4_A9.js new file mode 100644 index 0000000000..89a576a978 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/S15.10.7.4_A9.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The RegExp.prototype multiline property does not have the attribute + DontDelete +es5id: 15.10.7.4_A9 +description: Checking if deleting the multiline property succeeds +---*/ + +var __re = RegExp.prototype; + +assert.sameValue(__re.hasOwnProperty('multiline'), true, '__re.hasOwnProperty(\'multiline\') must return true'); +assert.sameValue(delete __re.multiline, true, 'The value of `delete __re.multiline` is expected to be true'); +assert.sameValue(__re.hasOwnProperty('multiline'), false, '__re.hasOwnProperty(\'multiline\') must return false'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/cross-realm.js new file mode 100644 index 0000000000..ef0b1bb2e7 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/cross-realm.js @@ -0,0 +1,28 @@ +// 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-get-regexp.prototype.multiline +description: A TypeError is thrown when the "this" value is an invalid cross-realm Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +features: [cross-realm] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'multiline').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'multiline').get; + +assert.throws(TypeError, function() { + get.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/length.js new file mode 100644 index 0000000000..08105090e0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.7 +description: > + get RegExp.prototype.multiline.length is 0. +info: | + get RegExp.prototype.multiline + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "multiline"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/name.js new file mode 100644 index 0000000000..674dec6f70 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/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.7 +description: > + RegExp.prototype.multiline name +info: | + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'multiline'); + +assert.sameValue( + descriptor.get.name, + 'get multiline' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/this-val-invalid-obj.js new file mode 100644 index 0000000000..f2d3a6e69b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/this-val-invalid-obj.js @@ -0,0 +1,32 @@ +// 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-get-regexp.prototype.multiline +description: A TypeError is thrown when the "this" value is an invalid Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'multiline').get; + +assert.throws(TypeError, function() { + get.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + get.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + get.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + get.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/this-val-non-obj.js new file mode 100644 index 0000000000..4ae30ee5b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/this-val-non-obj.js @@ -0,0 +1,43 @@ +// 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-get-regexp.prototype.multiline +description: A TypeError is thrown when the "this" value is not an Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'multiline').get; +var symbol = Symbol(); + +assert.throws(TypeError, function() { + get.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + get.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + get.call(3); +}, 'number'); + +assert.throws(TypeError, function() { + get.call('string'); +}, 'string'); + +assert.throws(TypeError, function() { + get.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + get.call(symbol); +}, 'symbol'); + +assert.throws(TypeError, function() { + get.call(4n); +}, 'bigint'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/multiline/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/this-val-regexp-prototype.js new file mode 100644 index 0000000000..bbc533b46a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/multiline/this-val-regexp-prototype.js @@ -0,0 +1,19 @@ +// 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-get-regexp.prototype.multiline +description: > + Return value of `undefined` when the "this" value is the RegExp prototype + object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'multiline').get; + +assert.sameValue(get.call(RegExp.prototype), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/no-regexp-matcher.js b/js/src/tests/test262/built-ins/RegExp/prototype/no-regexp-matcher.js new file mode 100644 index 0000000000..27fc38ac8a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/no-regexp-matcher.js @@ -0,0 +1,24 @@ +// 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-properties-of-the-regexp-prototype-object +description: > + The RegExp prototype object does not have a [[RegExpMatcher]] internal slot +info: | + The RegExp prototype object is an ordinary object. It is not a RegExp + instance and does not have a [[RegExpMatcher]] internal slot or any of the + other internal slots of RegExp instance objects. + + 21.2.5.2 RegExp.prototype.exec + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have a [[RegExpMatcher]] internal slot, throw a TypeError + exception. +---*/ + +assert.throws(TypeError, function() { + RegExp.prototype.exec(''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/cross-realm.js new file mode 100644 index 0000000000..faf9123f36 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/cross-realm.js @@ -0,0 +1,28 @@ +// 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-get-regexp.prototype.source +description: A TypeError is thrown when the "this" value is an invalid cross-realm Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return "(?:)". + b. Otherwise, throw a TypeError exception. +features: [cross-realm] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'source').get; + +assert.throws(TypeError, function() { + get.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/length.js new file mode 100644 index 0000000000..522f81227d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/length.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-get-regexp.prototype.source +description: > + get RegExp.prototype.source.length is 0. +info: | + get RegExp.prototype.source + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; + +verifyProperty(get, 'length', { + value: 0, + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/name.js new file mode 100644 index 0000000000..501762bb55 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/name.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. + +/*--- +esid: sec-get-regexp.prototype.source +description: > + get RegExp.prototype.source.name is "get source". +info: | + get RegExp.prototype.source + + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. + + 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] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; + +verifyProperty(get, 'name', { + value: 'get source', + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/prop-desc.js new file mode 100644 index 0000000000..00d66114f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/prop-desc.js @@ -0,0 +1,22 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.source +description: > + RegExp.prototype.source is an accessor property whose set accessor + function is undefined +includes: [propertyHelper.js] +---*/ + +var d = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source'); + +assert.sameValue(typeof d.get, 'function', 'typeof d.get'); +assert.sameValue(d.set, undefined, 'd.set'); + +verifyProperty(RegExp.prototype, 'source', { + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-invalid-obj.js new file mode 100644 index 0000000000..862a2d354e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-invalid-obj.js @@ -0,0 +1,32 @@ +// 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-get-regexp.prototype.source +description: A TypeError is thrown when the "this" value is an invalid Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return "(?:)". + b. Otherwise, throw a TypeError exception. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; + +assert.throws(TypeError, function() { + get.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + get.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + get.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + get.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-non-obj.js new file mode 100644 index 0000000000..9b0cbec7f7 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-non-obj.js @@ -0,0 +1,43 @@ +// 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-get-regexp.prototype.source +description: A TypeError is thrown when the "this" value is not an Object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; +var symbol = Symbol(); + +assert.throws(TypeError, function() { + get.call(undefined); +}, 'undefined'); + +assert.throws(TypeError, function() { + get.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + get.call(3); +}, 'number'); + +assert.throws(TypeError, function() { + get.call('string'); +}, 'string'); + +assert.throws(TypeError, function() { + get.call(true); +}, 'boolean'); + +assert.throws(TypeError, function() { + get.call(symbol); +}, 'symbol'); + +assert.throws(TypeError, function() { + get.call(4n); +}, 'bigint'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-regexp-prototype.js new file mode 100644 index 0000000000..ca630d5f12 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/this-val-regexp-prototype.js @@ -0,0 +1,18 @@ +// 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-get-regexp.prototype.source +description: > + Return "(?:)" when the `this` value is the RegExp.prototype object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return "(?:)". +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source').get; + +assert.sameValue(get.call(RegExp.prototype), '(?:)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value-empty.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-empty.js new file mode 100644 index 0000000000..50dbaf263d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-empty.js @@ -0,0 +1,26 @@ +// 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-get-regexp.prototype.source +description: > + Return value can be used to create an equivalent RegExp when the + [[OriginalSource]] internal slot is the empty string + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] the internal procedure that would result from evaluating S as a + Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the + internal procedure given by the constructed object's [[RegExpMatcher]] + internal slot. +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). +---*/ + +var re = eval('/' + new RegExp('').source + '/'); + +assert.sameValue(re.test(''), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value-line-terminator.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-line-terminator.js new file mode 100644 index 0000000000..bc52096f4d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-line-terminator.js @@ -0,0 +1,30 @@ +// 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-get-regexp.prototype.source +description: > + Return value can be used to create an equivalent RegExp when the + [[OriginalSource]] internal slot contains a LineTerminator +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] the internal procedure that would result from evaluating S as a + Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the + internal procedure given by the constructed object's [[RegExpMatcher]] + internal slot. +---*/ + +var re = eval('/' + new RegExp('\n').source + '/'); + +assert.sameValue(re.test('\n'), true, 'input: "\\n"'); +assert.sameValue(re.test('_\n_'), true, 'input: "_\\n_"'); +assert.sameValue(re.test('\\n'), false, 'input: "\\\\n"'); +assert.sameValue(re.test('\r'), false, 'input: "\\r"'); +assert.sameValue(re.test('n'), false, 'input: "n"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value-slash.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-slash.js new file mode 100644 index 0000000000..e0a6f23492 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-slash.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 Aleksey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.source +description: Return value can be used to create an equivalent RegExp +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] The code points / or any LineTerminator occurring in the pattern + shall be escaped in S as necessary to ensure that the String value + formed by concatenating the Strings "/", S, "/", and F can be parsed + (in an appropriate lexical context) as a RegularExpressionLiteral that + behaves identically to the constructed regular expression. +---*/ + +var re = eval('/' + new RegExp('/').source + '/'); + +assert(re.test('/'), 'input: "/"'); +assert(re.test('_/_'), 'input: "_/_"'); +assert(!re.test('\\'), 'input: "\\"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value-u.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-u.js new file mode 100644 index 0000000000..e7847b7287 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value-u.js @@ -0,0 +1,34 @@ +// 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-get-regexp.prototype.source +description: > + Return value can be used to create an equivalent RegExp when the + [[OriginalFlags]] internal slot contains the `u` flag +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] the internal procedure that would result from evaluating S as a + Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the + internal procedure given by the constructed object's [[RegExpMatcher]] + internal slot. +---*/ + +var re; + +re = eval('/' + /\ud834\udf06/u.source + '/u'); + +assert.sameValue(re.test('\ud834\udf06'), true); +assert.sameValue(re.test('𝌆'), true); + +re = eval('/' + /\u{1d306}/u.source + '/u'); + +assert.sameValue(re.test('\ud834\udf06'), true); +assert.sameValue(re.test('𝌆'), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/source/value.js b/js/src/tests/test262/built-ins/RegExp/prototype/source/value.js new file mode 100644 index 0000000000..5fdb1df936 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/source/value.js @@ -0,0 +1,36 @@ +// 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-get-regexp.prototype.source +description: Return value can be used to create an equivalent RegExp +info: | + [...] + 5. Let src be R.[[OriginalSource]]. + 6. Let flags be R.[[OriginalFlags]]. + 7. Return EscapeRegExpPattern(src, flags). + + 21.2.3.2.4 Runtime Semantics: EscapeRegExpPattern + + [...] the internal procedure that would result from evaluating S as a + Pattern[~U] (Pattern[+U] if F contains "u") must behave identically to the + internal procedure given by the constructed object's [[RegExpMatcher]] + internal slot. +---*/ + +var re = eval('/' + /ab{2,4}c$/.source + '/'); + +assert(re.test('abbc'), 'input: abbc'); +assert(re.test('abbbc'), 'input: abbbc'); +assert(re.test('abbbbc'), 'input: abbbbc'); +assert(re.test('xabbc'), 'input: xabbc'); +assert(re.test('xabbbc'), 'input: xabbbc'); +assert(re.test('xabbbbc'), 'input: xabbbbc'); + +assert.sameValue(re.test('ac'), false, 'input: ac'); +assert.sameValue(re.test('abc'), false, 'input: abc'); +assert.sameValue(re.test('abbcx'), false, 'input: abbcx'); +assert.sameValue(re.test('bbc'), false, 'input: bbc'); +assert.sameValue(re.test('abb'), false, 'input: abb'); +assert.sameValue(re.test('abbbbbc'), false, 'input: abbbbbc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/cross-realm.js new file mode 100644 index 0000000000..65b3b244c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/cross-realm.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: Invoked on a cross-realm object without an [[OriginalFlags]] internal slot +es6id: 21.2.5.12 +info: | + 21.2.5.12 get RegExp.prototype.sticky + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, throw a TypeError + exception. +features: [cross-realm] +---*/ + +var sticky = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'sticky').get; + +assert.throws(TypeError, function() { + sticky.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/length.js new file mode 100644 index 0000000000..220cf0a901 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.12 +description: > + get RegExp.prototype.sticky.length is 0. +info: | + get RegExp.prototype.sticky + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "sticky"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/name.js new file mode 100644 index 0000000000..8fa5b1ac0f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/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.12 +description: > + RegExp.prototype.sticky name +info: | + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky'); + +assert.sameValue( + descriptor.get.name, + 'get sticky' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/prop-desc.js new file mode 100644 index 0000000000..349219513b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/prop-desc.js @@ -0,0 +1,17 @@ +// 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.12 +description: > + `sticky` property descriptor +info: | + RegExp.prototype.sticky is an accessor property whose set accessor + function is undefined. +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky'); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-invalid-obj.js new file mode 100644 index 0000000000..41aaee539b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-invalid-obj.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. + +/*--- +description: Invoked on an object without an [[OriginalFlags]] internal slot +es6id: 21.2.5.12 +info: | + 21.2.5.12 get RegExp.prototype.sticky + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, throw a TypeError + exception. +---*/ + +var sticky = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky').get; + +assert.throws(TypeError, function() { + sticky.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + sticky.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + sticky.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + sticky.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-non-obj.js new file mode 100644 index 0000000000..b0e67154fd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-non-obj.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. + +/*--- +description: > + `sticky` accessor invoked on a non-object value +es6id: 21.2.5.12 +info: | + 21.2.5.12 get RegExp.prototype.sticky + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var sticky = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky').get; + +assert.throws(TypeError, function() { + sticky.call(undefined); +}); + +assert.throws(TypeError, function() { + sticky.call(null); +}); + +assert.throws(TypeError, function() { + sticky.call(true); +}); + +assert.throws(TypeError, function() { + sticky.call('string'); +}); + +assert.throws(TypeError, function() { + sticky.call(Symbol('s')); +}); + +assert.throws(TypeError, function() { + sticky.call(4); +}); + +assert.throws(TypeError, function() { + sticky.call(4n); +}, 'bigint'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-regexp-prototype.js new file mode 100644 index 0000000000..d3c9fc454e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-regexp-prototype.js @@ -0,0 +1,19 @@ +// 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-get-regexp.prototype.sticky +description: > + Return value of `undefined` when the "this" value is the RegExp prototype + object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'sticky').get; + +assert.sameValue(get.call(RegExp.prototype), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-regexp.js b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-regexp.js new file mode 100644 index 0000000000..4308d25afb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/sticky/this-val-regexp.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. + +/*--- +description: > + `sticky` accessor function invoked on a RegExp instance +es6id: 21.2.5.12 +info: | + 21.2.5.12 get RegExp.prototype.sticky + + 4. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 5. If flags contains the code unit "y", return true. + 6. Return false. +---*/ + +assert.sameValue(/./.sticky, false); +assert.sameValue(/./i.sticky, false); +assert.sameValue(/./g.sticky, false); +assert.sameValue(/./gi.sticky, false); + +assert.sameValue(/./y.sticky, true); +assert.sameValue(/./iy.sticky, true); +assert.sameValue(/./yg.sticky, true); +assert.sameValue(/./iyg.sticky, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A10.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A10.js new file mode 100644 index 0000000000..0a8d503e08 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A10.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype.test.length property has the attribute ReadOnly +es5id: 15.10.6.3_A10 +description: Checking if varying the RegExp.prototype.test.length property fails +includes: [propertyHelper.js] +---*/ +assert.sameValue( + RegExp.prototype.test.hasOwnProperty('length'), + true, + 'RegExp.prototype.test.hasOwnProperty(\'length\') must return true' +); + +var __obj = RegExp.prototype.test.length; + +verifyNotWritable(RegExp.prototype.test, "length", null, function(){return "shifted";}); + +assert.sameValue( + RegExp.prototype.test.length, + __obj, + 'The value of RegExp.prototype.test.length is expected to equal the value of __obj' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A11.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A11.js new file mode 100644 index 0000000000..3dbaa2d9ab --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A11.js @@ -0,0 +1,17 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The length property of the test method is 1 +es5id: 15.10.6.3_A11 +description: Checking RegExp.prototype.test.length +---*/ +assert.sameValue( + RegExp.prototype.test.hasOwnProperty("length"), + true, + 'RegExp.prototype.test.hasOwnProperty("length") must return true' +); + +assert.sameValue(RegExp.prototype.test.length, 1, 'The value of RegExp.prototype.test.length is expected to be 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T1.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T1.js new file mode 100644 index 0000000000..6a64ab568d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T1.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T1 +description: RegExp is /1|12/ and tested string is "123" +---*/ + +var __string = "123"; +var __re = /1|12/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test(""123"") must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T10.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T10.js new file mode 100644 index 0000000000..52d27fd635 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T10.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T10 +description: RegExp is /1|12/ and tested string is 1.01 +---*/ + +var __string = 1.01; +var __re = /1|12/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test(1.01) must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T11.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T11.js new file mode 100644 index 0000000000..3c0caf4afb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T11.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T11 +description: RegExp is /2|12/ and tested string is new Number(1.012) +---*/ + +var __string = new Number(1.012); +var __re = /2|12/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test(new Number(1.012)) must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T12.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T12.js new file mode 100644 index 0000000000..55adc94424 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T12.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T12 +description: > + RegExp is /\.14/ and tested string is {toString:function(){return + Math.PI;}} +---*/ + +var __string = {toString:function(){return Math.PI;}}; +var __re = /\.14/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test({toString:function(){return Math.PI;}}) must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T13.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T13.js new file mode 100644 index 0000000000..93b0405274 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T13.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T13 +description: RegExp is /t[a-b|q-s]/ and tested string is true +---*/ + +var __string = true; +var __re = /t[a-b|q-s]/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test(true) must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T14.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T14.js new file mode 100644 index 0000000000..95460d84fb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T14.js @@ -0,0 +1,19 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T14 +description: RegExp is /AL|se/ and tested string is new Boolean +---*/ + +var __string = new Boolean; +var __re = /AL|se/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test(new Boolean) must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T15.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T15.js new file mode 100644 index 0000000000..7017b295d3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T15.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T15 +description: > + RegExp is /LS/i and tested string is {toString:function(){return + false;}} +---*/ + +var __string = {toString:function(){return false;}}; +var __re = /LS/i; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test({toString:function(){return false;}}) must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T16.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T16.js new file mode 100644 index 0000000000..5bd90f169c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T16.js @@ -0,0 +1,14 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T16 +description: RegExp is /undefined/ and call test() without arguments +---*/ + +var __re = /undefined/; + +assert.sameValue(__re.test(), __re.exec() !== null, '__re.test() must return __re.exec() !== null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T17.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T17.js new file mode 100644 index 0000000000..2d2f52b5cb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T17.js @@ -0,0 +1,14 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T17 +description: RegExp is /ll|l/ and tested string is null +---*/ + +var __re = /ll|l/; + +assert.sameValue(__re.test(null), __re.exec(null) !== null, '__re.test(null) must return __re.exec(null) !== null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T18.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T18.js new file mode 100644 index 0000000000..0726b40eda --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T18.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T18 +description: RegExp is /nd|ne/ and tested string is undefined +---*/ + +var __re = /nd|ne/; + +assert.sameValue( + __re.test(undefined), + __re.exec(undefined) !== null, + '__re.test(undefined) must return __re.exec(undefined) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T19.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T19.js new file mode 100644 index 0000000000..a767ea20c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T19.js @@ -0,0 +1,18 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T19 +description: RegExp is /e{1}/ and tested string is void 0 +---*/ + +var __re = /e{1}/; + +assert.sameValue( + __re.test(void 0), + __re.exec(void 0) !== null, + '__re.test(void 0) must return __re.exec(void 0) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T2.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T2.js new file mode 100644 index 0000000000..abe89629f4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T2.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T2 +description: > + RegExp is /((1)|(12))((3)|(23))/ and tested string is new + String("123") +---*/ + +var __string = new String("123"); +var __re = /((1)|(12))((3)|(23))/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test("new String("123")") must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T20.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T20.js new file mode 100644 index 0000000000..50fcf0443c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T20.js @@ -0,0 +1,16 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T20 +description: RegExp is /[a-f]d/ and tested string is x, where x is undefined +---*/ + +var __re = /[a-f]d/; + +assert.sameValue(__re.test(x), __re.exec(x) !== null, '__re.test() must return __re.exec(x) !== null'); + +var x; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T21.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T21.js new file mode 100644 index 0000000000..1af7dfac0c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T21.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T21 +description: > + RegExp is /[a-z]n/ and tested string is x, where x is + function(){}() +---*/ + +var __re = /[a-z]n/; + +assert.sameValue( + __re.test(function(){}()), + __re.exec(function(){}()) !== null, + '__re.test(function(){}()) must return __re.exec(function(){}()) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T22.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T22.js new file mode 100644 index 0000000000..cadeb79c93 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T22.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + RegExp.prototype.test behavior depends on the lastIndex property: + ToLength(lastIndex) is the starting point for the search, so + negative numbers result in searching from 0. +es5id: 15.10.6.3_A1_T22 +description: "Set lastIndex to -1 and call /(?:ab|cd)\\d?/g.test(\"aacd22 \")" +---*/ + +var __re = /(?:ab|cd)\d?/g; +__re.lastIndex=-1; +var __executed = __re.test("aacd22 "); + +assert(!!__executed, 'The value of !!__executed is expected to be true'); +assert.sameValue(__re.lastIndex, 5, 'The value of __re.lastIndex is expected to be 5'); + +__re.lastIndex=-100; +__executed = __re.test("aacd22 "); + +assert(!!__executed, 'The value of !!__executed is expected to be true'); +assert.sameValue(__re.lastIndex, 5, 'The value of __re.lastIndex is expected to be 5'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T3.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T3.js new file mode 100644 index 0000000000..fe59bc5001 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T3.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T3 +description: > + RegExp is /a[a-z]{2,4}/ and tested string is new + Object("abcdefghi") +---*/ + +var __string = new Object("abcdefghi"); +var __re = /a[a-z]{2,4}/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test("new Object("abcdefghi")") must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T4.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T4.js new file mode 100644 index 0000000000..e4b4a1676b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T4.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T4 +description: > + RegExp is /a[a-z]{2,4}?/ and tested string is + {toString:function(){return "abcdefghi";}} +---*/ + +var __string = {toString:function(){return "abcdefghi";}}; +var __re = /a[a-z]{2,4}?/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test({toString:function(){return "abcdefghi";}}) must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T5.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T5.js new file mode 100644 index 0000000000..d15cd52808 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T5.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T5 +description: > + RegExp is /(aa|aabaac|ba|b|c)* / and tested string is + {toString:function(){return {};}, valueOf:function(){return + "aabaac";}} +---*/ + +var __string = {toString:function(){return {};}, valueOf:function(){return "aabaac";}}; +var __re = /(aa|aabaac|ba|b|c)*/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test("{toString:function(){return {};}, valueOf:function(){return "aabaac";}}) must return __re.exec(__string) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T6.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T6.js new file mode 100644 index 0000000000..dad55d3c3a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T6.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T6 +description: > + RegExp is /(z)((a+)?(b+)?(c))* / and tested string is + (function(){return "zaacbbbcac"})() +---*/ + +var __re = /(z)((a+)?(b+)?(c))*/; + +assert.sameValue( + __re.test((function(){return "zaacbbbcac"})()), + __re.exec((function(){return "zaacbbbcac"})()) !== null, + '__re.test((function(){return "zaacbbbcac"})()) must return __re.exec((function(){return "zaacbbbcac"})()) !== null' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T7.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T7.js new file mode 100644 index 0000000000..43abe4e04b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T7.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T7 +description: > + RegExp is /[a-z]/ and tested string is {toString:function(){throw + "intostr";}} +---*/ + +try { + throw new Test262Error('#1.1: /[a-z]/.test({toString:function(){throw "intostr";}}) throw "intostr". Actual: ' + (/[a-z]/.test({toString:function(){throw "intostr";}}))); +} catch (e) { + assert.sameValue(e, "intostr", 'The value of e is expected to be "intostr"'); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T8.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T8.js new file mode 100644 index 0000000000..a068a2da63 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T8.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T8 +description: > + RegExp is /[a-z]/ and tested string is {toString:void 0, + valueOf:function(){throw "invalof";}} +---*/ + +try { + throw new Test262Error('#1.1: /[a-z]/.test({toString:void 0, valueOf:function(){throw "invalof";}}) throw "invalof". Actual: ' + (/[a-z]/.test({toString:void 0, valueOf:function(){throw "invalof";}}))); +} catch (e) { + assert.sameValue(e, "invalof", 'The value of e is expected to be "invalof"'); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T9.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T9.js new file mode 100644 index 0000000000..dad72cb614 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A1_T9.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Equivalent to the expression RegExp.prototype.exec(string) != null +es5id: 15.10.6.3_A1_T9 +description: RegExp is /1|12/ and tested string is function object +---*/ + +var __string; +var __re = /1|12/; + +assert.sameValue( + __re.test(__string), + __re.exec(__string) !== null, + '__re.test() must return __re.exec(__string) !== null' +); + +function __string(){} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T1.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T1.js new file mode 100644 index 0000000000..aa7c948527 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T1.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T1 +description: The tested object is new Object +---*/ + +var __instance = new Object; + +__instance.test = RegExp.prototype.test; + +try { + throw new Test262Error('#1.1: __instance = new Object; __instance.test = RegExp.prototype.test; __instance.test("message to investigate"). Actual: ' + (__instance.test("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T10.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T10.js new file mode 100644 index 0000000000..d674d38ae8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T10.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T10 +description: The tested object is undefined +---*/ + +var test = RegExp.prototype.test; + +try { + throw new Test262Error('#1.1: test = RegExp.prototype.test; test("message to investigate"). Actual: ' + (test("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T2.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T2.js new file mode 100644 index 0000000000..0690647f9e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T2.js @@ -0,0 +1,29 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T2 +description: The tested object is Math +---*/ + +var __instance = Math; + +__instance.test = RegExp.prototype.test; + +try { + __instance.test("message to investigate"); + throw new Test262Error('#1.1: __instance = Math; __instance.test = RegExp.prototype.test; __instance.test("message to investigate")'); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T3.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T3.js new file mode 100644 index 0000000000..e304938ad0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T3.js @@ -0,0 +1,29 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T3 +description: The tested object is function object +---*/ + +__instance.test = RegExp.prototype.test; + +try { + __instance.test("message to investigate"); + throw new Test262Error('#1.1: __instance.test = RegExp.prototype.test; __instance.test("message to investigate"); function __instance(){}'); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +function __instance(){}; + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T4.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T4.js new file mode 100644 index 0000000000..b22f6dc1b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T4.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T4 +description: The tested object is new String("[a-b]") +---*/ + +var __instance = new String("[a-b]"); + +__instance.test = RegExp.prototype.test; + + try { + throw new Test262Error('#1.1: __instance = new String("[a-b]"); __instance.test = RegExp.prototype.test; test("message to investigate"). Actual: ' + (__instance.test("message to investigate"))); + } catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); + } + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T5.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T5.js new file mode 100644 index 0000000000..47fcde5b88 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T5.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T5 +description: The tested object is new Boolean(false) +---*/ + +var __instance = new Boolean(false); + +__instance.test = RegExp.prototype.test; + + try { + throw new Test262Error('#1.1: __instance = new Boolean(false); __instance.test = RegExp.prototype.test; test("message to investigate"). Actual: ' + (__instance.test("message to investigate"))); + } catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); + } + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T6.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T6.js new file mode 100644 index 0000000000..3f72ae9523 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T6.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T6 +description: The tested object is new Number(1.0) +---*/ + +var __instance = new Number(1.0); + +__instance.test = RegExp.prototype.test; + +try { + throw new Test262Error('#1.1: __instance = new Number(1.0); __instance.test = RegExp.prototype.test; __instance["test"]("message to investigate"). Actual: ' + (__instance["test"]("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T7.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T7.js new file mode 100644 index 0000000000..19794986f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T7.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T7 +description: The tested object is false +---*/ + +var __instance = false; + +Object.prototype.test = RegExp.prototype.test; + +try { + throw new Test262Error('#1.1: __instance = false; Object.prototype.test = RegExp.prototype.test; __instance.test("message to investigate"). Actual: ' + (__instance.test("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T8.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T8.js new file mode 100644 index 0000000000..a50d1fcedd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T8.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T8 +description: The tested object is "." +---*/ + +var __instance = "."; + +Object.prototype.test = RegExp.prototype.test; + +try { + throw new Test262Error('#1.1: __instance = "."; Object.prototype.test = RegExp.prototype.test; __instance.test("message to investigate"). Actual: ' + (__instance.test("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T9.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T9.js new file mode 100644 index 0000000000..0ff585e300 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A2_T9.js @@ -0,0 +1,28 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + A TypeError exception is thrown if the this value is not an object for + which the value of the internal [[Class]] property is "RegExp" +es5id: 15.10.6.3_A2_T9 +description: The tested object is 1.0 +---*/ + +var __instance = 1.0; + +Object.prototype.test = RegExp.prototype.test; + +try { + throw new Test262Error('#1.1: __instance = 1.0; Object.prototype.test = RegExp.prototype.test; __instance.test("message to investigate"). Actual: ' + (__instance.test("message to investigate"))); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A6.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A6.js new file mode 100644 index 0000000000..2888978604 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A6.js @@ -0,0 +1,15 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: RegExp.prototype.test has not prototype property +es5id: 15.10.6.3_A6 +description: Checking RegExp.prototype.test.prototype +---*/ +assert.sameValue( + RegExp.prototype.test.prototype, + undefined, + 'The value of RegExp.prototype.test.prototype is expected to equal undefined' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A7.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A7.js new file mode 100644 index 0000000000..db7364bd31 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A7.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: RegExp.prototype.test can't be used as constructor +es5id: 15.10.6.3_A7 +description: Checking if creating the RegExp.prototype.test object fails +---*/ + +var __FACTORY = RegExp.prototype.test; + +try { + var __instance = new __FACTORY; + throw new Test262Error('#1.1: __FACTORY = RegExp.prototype.test throw TypeError. Actual: ' + (__instance)); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A8.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A8.js new file mode 100644 index 0000000000..e956dacab2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A8.js @@ -0,0 +1,35 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype.test.length property has the attribute DontEnum +es5id: 15.10.6.3_A8 +description: > + Checking if enumerating the RegExp.prototype.test.length property + fails +---*/ +assert.sameValue( + RegExp.prototype.test.hasOwnProperty('length'), + true, + 'RegExp.prototype.test.hasOwnProperty(\'length\') must return true' +); + +assert.sameValue( + RegExp.prototype.test.propertyIsEnumerable('length'), + false, + 'RegExp.prototype.test.propertyIsEnumerable(\'length\') must return false' +); + +var count=0; + +for (var p in RegExp.prototype.test){ + if (p==="length") { + count++; + } +} + +assert.sameValue(count, 0, 'The value of count is expected to be 0'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A9.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A9.js new file mode 100644 index 0000000000..7667d3f3a3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/S15.10.6.3_A9.js @@ -0,0 +1,31 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The RegExp.prototype.test.length property does not have the attribute + DontDelete +es5id: 15.10.6.3_A9 +description: Checking if deleting RegExp.prototype.test.length property fails +---*/ +assert.sameValue( + RegExp.prototype.exec.hasOwnProperty('length'), + true, + 'RegExp.prototype.exec.hasOwnProperty(\'length\') must return true' +); + +assert.sameValue( + delete RegExp.prototype.exec.length, + true, + 'The value of `delete RegExp.prototype.exec.length` is expected to be true' +); + +assert.sameValue( + RegExp.prototype.exec.hasOwnProperty('length'), + false, + 'RegExp.prototype.exec.hasOwnProperty(\'length\') must return false' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/name.js new file mode 100644 index 0000000000..7ee8a9a2e7 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.13 +description: > + RegExp.prototype.test.name is "test". +info: | + RegExp.prototype.test( S ) + + 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] +---*/ + +assert.sameValue(RegExp.prototype.test.name, "test"); + +verifyNotEnumerable(RegExp.prototype.test, "name"); +verifyNotWritable(RegExp.prototype.test, "name"); +verifyConfigurable(RegExp.prototype.test, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/not-a-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/not-a-constructor.js new file mode 100644 index 0000000000..ee6ce0aeaf --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/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.test 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, arrow-function] +---*/ + +assert.sameValue( + isConstructor(RegExp.prototype.test), + false, + 'isConstructor(RegExp.prototype.test) must return false' +); + +assert.throws(TypeError, () => { + let re = new RegExp(''); new re.test(); +}, '`let re = new RegExp(\'\'); new re.test()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/y-fail-lastindex-no-write.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-fail-lastindex-no-write.js new file mode 100644 index 0000000000..0746d299c3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-fail-lastindex-no-write.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. + +/*--- +description: Match failure with non-writable `lastIndex` property +es6id: 21.2.5.13 +info: | + 21.2.5.13 RegExp.prototype.test( S ) + + [...] + 5. Let match be RegExpExec(R, string). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). + 2. ReturnIfAbrupt(setStatus). +---*/ + +var r = /c/y; +Object.defineProperty(r, 'lastIndex', { + writable: false +}); + +assert.throws(TypeError, function() { + r.test('abc'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/y-fail-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-fail-lastindex.js new file mode 100644 index 0000000000..ec9e0a51b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-fail-lastindex.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Resets the `lastIndex` property to zero after a match failure +es6id: 21.2.5.13 +info: | + 21.2.5.13 RegExp.prototype.test( S ) + + [...] + 5. Let match be RegExpExec(R, string). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + 1. Let setStatus be Set(R, "lastIndex", 0, true). +---*/ + +var r = /c/y; +r.lastIndex = 1; + +r.test('abc'); + +assert.sameValue(r.lastIndex, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/y-fail-return.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-fail-return.js new file mode 100644 index 0000000000..17c627c804 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-fail-return.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: Stops match execution after first match failure +es6id: 21.2.5.13 +info: | + 21.2.5.13 RegExp.prototype.test( S ) + + [...] + 5. Let match be RegExpExec(R, string). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 15. Repeat, while matchSucceeded is false + [...] + b. Let r be matcher(S, lastIndex). + c. If r is failure, then + i. If sticky is true, then + [...] + 3. Return null. +---*/ + +assert.sameValue(/b/y.test('ab'), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/y-init-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-init-lastindex.js new file mode 100644 index 0000000000..2d66352dce --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-init-lastindex.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. + +/*--- +description: Honors initial value of the `lastIndex` property +es6id: 21.2.5.13 +info: | + 21.2.5.13 RegExp.prototype.test( S ) + + [...] + 5. Let match be RegExpExec(R, string). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 4. Let lastIndex be ToLength(Get(R,"lastIndex")). + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + 9. ReturnIfAbrupt(sticky). + 10. If global is false and sticky is false, let lastIndex be 0. +---*/ + +var r = /./y; +r.lastIndex = 1; + +assert.sameValue(r.test('a'), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/test/y-set-lastindex.js b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-set-lastindex.js new file mode 100644 index 0000000000..17f01468a5 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/test/y-set-lastindex.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. + +/*--- +description: Sets the `lastIndex` property to the end index of the first match +es6id: 21.2.5.13 +info: | + 21.2.5.13 RegExp.prototype.test( S ) + + [...] + 5. Let match be RegExpExec(R, string). + + 21.2.5.2.2 Runtime Semantics: RegExpBuiltinExec ( R, S ) + + [...] + 8. Let sticky be ToBoolean(Get(R, "sticky")). + [...] + 18. If global is true or sticky is true, + a. Let setStatus be Set(R, "lastIndex", e, true). +---*/ + +var r = /abc/y; + +r.test('abc'); + +assert.sameValue(r.lastIndex, 3); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A10.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A10.js new file mode 100644 index 0000000000..34498afafc --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A10.js @@ -0,0 +1,30 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype.toString.length property has the attribute ReadOnly +es5id: 15.10.6.4_A10 +description: > + Checking if varying the RegExp.prototype.toString.length property + fails +includes: [propertyHelper.js] +---*/ +assert.sameValue( + RegExp.prototype.toString.hasOwnProperty('length'), + true, + 'RegExp.prototype.toString.hasOwnProperty(\'length\') must return true' +); + +var __obj = RegExp.prototype.toString.length; + +verifyNotWritable(RegExp.prototype.toString, "length", null, function(){return "shifted";}); + +assert.sameValue( + RegExp.prototype.toString.length, + __obj, + 'The value of RegExp.prototype.toString.length is expected to equal the value of __obj' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A11.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A11.js new file mode 100644 index 0000000000..ba322bd577 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A11.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The length property of the toString method is 1 +es5id: 15.10.6.4_A11 +description: Checking RegExp.prototype.toString.length +---*/ +assert.sameValue( + RegExp.prototype.toString.hasOwnProperty("length"), + true, + 'RegExp.prototype.toString.hasOwnProperty("length") must return true' +); + +assert.sameValue( + RegExp.prototype.toString.length, + 0, + 'The value of RegExp.prototype.toString.length is expected to be 0' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A6.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A6.js new file mode 100644 index 0000000000..42adb4757d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A6.js @@ -0,0 +1,23 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: RegExp.prototype.toString has not prototype property +es5id: 15.10.6.4_A6 +description: Checking RegExp.prototype.toString.prototype +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ +assert.sameValue( + RegExp.prototype.toString.prototype, + undefined, + 'The value of RegExp.prototype.toString.prototype is expected to equal undefined' +); + +assert.sameValue( + isConstructor(RegExp.prototype.toString), + false, + 'isConstructor(RegExp.prototype.toString) must return false' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A7.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A7.js new file mode 100644 index 0000000000..334fcc1f4d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A7.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: RegExp.prototype.toString can't be used as constructor +es5id: 15.10.6.4_A7 +description: Checking if creating the RegExp.prototype.toString object fails +includes: [isConstructor.js] +features: [Reflect.construct] +---*/ + +var __FACTORY = RegExp.prototype.toString; + +try { + var __instance = new __FACTORY; + throw new Test262Error('#1.1: __FACTORY = RegExp.prototype.toString throw TypeError. Actual: ' + (__instance)); +} catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +assert.sameValue( + isConstructor(RegExp.prototype.toString), + false, + 'isConstructor(RegExp.prototype.toString) must return false' +); + +// TODO: Convert to assert.throws() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A8.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A8.js new file mode 100644 index 0000000000..fe8d29d512 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A8.js @@ -0,0 +1,35 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: The RegExp.prototype.toString.length property has the attribute DontEnum +es5id: 15.10.6.4_A8 +description: > + Checking if enumerating the RegExp.prototype.toString.length + property fails +---*/ +assert.sameValue( + RegExp.prototype.toString.hasOwnProperty('length'), + true, + 'RegExp.prototype.toString.hasOwnProperty(\'length\') must return true' +); + +assert.sameValue( + RegExp.prototype.toString.propertyIsEnumerable('length'), + false, + 'RegExp.prototype.toString.propertyIsEnumerable(\'length\') must return false' +); + +var count=0; + +for (var p in RegExp.prototype.toString){ + if (p==="length") { + count++; + } +} + +assert.sameValue(count, 0, 'The value of count is expected to be 0'); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A9.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A9.js new file mode 100644 index 0000000000..34f1cdffc9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/S15.10.6.4_A9.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The RegExp.prototype.toString.length property does not have the attribute + DontDelete +es5id: 15.10.6.4_A9 +description: > + Checking if deleting the RegExp.prototype.toString.length property + fails +---*/ +assert.sameValue( + RegExp.prototype.toString.hasOwnProperty('length'), + true, + 'RegExp.prototype.toString.hasOwnProperty(\'length\') must return true' +); + +assert.sameValue( + delete RegExp.prototype.toString.length, + true, + 'The value of `delete RegExp.prototype.toString.length` is expected to be true' +); + +assert.sameValue( + RegExp.prototype.toString.hasOwnProperty('length'), + false, + 'RegExp.prototype.toString.hasOwnProperty(\'length\') must return false' +); + +// TODO: Convert to verifyProperty() format. + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/called-as-function.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/called-as-function.js new file mode 100644 index 0000000000..0b64826c37 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/called-as-function.js @@ -0,0 +1,34 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-regexp.prototype.tostring +description: > + `this` value is resolved using strict mode semantics, + throwing TypeError if called as top-level function. +info: | + RegExp.prototype.toString ( ) + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + + ToObject ( argument ) + + Argument Type: Undefined + Result: Throw a TypeError exception. +---*/ + +["source", "flags"].forEach(function(key) { + Object.defineProperty(this, key, { + get: function() { + throw new Test262Error(key + " lookup should not be performed"); + }, + }); +}, this); + +var toString = RegExp.prototype.toString; +assert.throws(TypeError, function() { + toString(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/name.js new file mode 100644 index 0000000000..91fe5a8809 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 21.2.5.14 +description: > + RegExp.prototype.toString.name is "toString". +info: | + RegExp.prototype.toString ( ) + + 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] +---*/ + +assert.sameValue(RegExp.prototype.toString.name, "toString"); + +verifyNotEnumerable(RegExp.prototype.toString, "name"); +verifyNotWritable(RegExp.prototype.toString, "name"); +verifyConfigurable(RegExp.prototype.toString, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/not-a-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/not-a-constructor.js new file mode 100644 index 0000000000..f064aaf64d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/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.toString 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, arrow-function] +---*/ + +assert.sameValue( + isConstructor(RegExp.prototype.toString), + false, + 'isConstructor(RegExp.prototype.toString) must return false' +); + +assert.throws(TypeError, () => { + let re = new RegExp(''); new re.toString(); +}, '`let re = new RegExp(\'\'); new re.toString()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/toString/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/toString/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/toString/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/cross-realm.js new file mode 100644 index 0000000000..dd86e4d5ad --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/cross-realm.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: Invoked on a cross-realm object without an [[OriginalFlags]] internal slot +es6id: 21.2.5.15 +info: | + 21.2.5.15 get RegExp.prototype.unicode + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, throw a TypeError + exception. +features: [cross-realm] +---*/ + +var unicode = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicode').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'unicode').get; + +assert.throws(TypeError, function() { + unicode.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/length.js new file mode 100644 index 0000000000..127e2d0428 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/length.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.15 +description: > + "length" property of `unicode` accessor function +info: | + ES6 section 17: Every built-in Function object, including constructors, has + a length property whose value is an integer. Unless otherwise specified, + this value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. + + [...] + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var getter = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicode').get; + +assert.sameValue(getter.length, 0); + +verifyNotEnumerable(getter, 'length'); +verifyNotWritable(getter, 'length'); +verifyConfigurable(getter, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/name.js new file mode 100644 index 0000000000..1e1858b46d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/name.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.15 +description: > + "name" property of `unicode` accessor function +info: | + The value of the name property of this function is "get ". + + ES6 section 17: + + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. + + [...] + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name 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] +---*/ + +var getter = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicode').get; + +assert.sameValue(getter.name, 'get unicode'); + +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/prop-desc.js new file mode 100644 index 0000000000..c4c89d7e6e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/prop-desc.js @@ -0,0 +1,17 @@ +// 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.15 +description: > + `unicode` property descriptor +info: | + RegExp.prototype.unicode is an accessor property whose set accessor + function is undefined. +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicode'); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, 'function'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-invalid-obj.js new file mode 100644 index 0000000000..1a8bcb012a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-invalid-obj.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. + +/*--- +description: Invoked on an object without an [[OriginalFlags]] internal slot +es6id: 21.2.5.15 +info: | + 21.2.5.15 get RegExp.prototype.unicode + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, throw a TypeError + exception. +---*/ + +var unicode = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicode').get; + +assert.throws(TypeError, function() { + unicode.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + unicode.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + unicode.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + unicode.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-non-obj.js new file mode 100644 index 0000000000..d5a8130c1a --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-non-obj.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. + +/*--- +description: > + `unicode` accessor invoked on a non-object value +es6id: 21.2.5.15 +info: | + 21.2.5.15 get RegExp.prototype.unicode + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol] +---*/ + +var unicode = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicode').get; + +assert.throws(TypeError, function() { + unicode.call(undefined); +}); + +assert.throws(TypeError, function() { + unicode.call(null); +}); + +assert.throws(TypeError, function() { + unicode.call(true); +}); + +assert.throws(TypeError, function() { + unicode.call('string'); +}); + +assert.throws(TypeError, function() { + unicode.call(Symbol('s')); +}); + +assert.throws(TypeError, function() { + unicode.call(4); +}); + +assert.throws(TypeError, function() { + unicode.call(4n); +}, 'bigint'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-regexp-prototype.js new file mode 100644 index 0000000000..4b7d407c00 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-regexp-prototype.js @@ -0,0 +1,19 @@ +// 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-get-regexp.prototype.unicode +description: > + Return value of `undefined` when the "this" value is the RegExp prototype + object +info: | + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicode').get; + +assert.sameValue(get.call(RegExp.prototype), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-regexp.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-regexp.js new file mode 100644 index 0000000000..abc61293f2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicode/this-val-regexp.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + `unicode` accessor function invoked on a RegExp instance +es6id: 21.2.5.15 +info: | + 21.2.5.15 get RegExp.prototype.unicode + + [...] + 4. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 5. If flags contains the code unit "u", return true. + 6. Return false. +---*/ + +assert.sameValue(/./.unicode, false); +assert.sameValue(/./i.unicode, false); +assert.sameValue(/./g.unicode, false); +assert.sameValue(/./gi.unicode, false); + +assert.sameValue(/./u.unicode, true); +assert.sameValue(/./iu.unicode, true); +assert.sameValue(/./ug.unicode, true); +assert.sameValue(/./iug.unicode, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-01.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-01.js new file mode 100644 index 0000000000..f0e4f208f9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-01.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[(]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-02.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-02.js new file mode 100644 index 0000000000..a22587504c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-02.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[)]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-03.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-03.js new file mode 100644 index 0000000000..488a979c3f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-03.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[[]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-04.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-04.js new file mode 100644 index 0000000000..0b1556f050 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-04.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[{]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-05.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-05.js new file mode 100644 index 0000000000..9fd5e7dd22 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-05.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[}]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-06.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-06.js new file mode 100644 index 0000000000..4e1efd8b35 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-06.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[/]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-07.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-07.js new file mode 100644 index 0000000000..18dd730ddc --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-07.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[-]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-08.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-08.js new file mode 100644 index 0000000000..a89f44af32 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-08.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[|]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-09.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-09.js new file mode 100644 index 0000000000..9ed867d9b2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-09.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[&&]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-10.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-10.js new file mode 100644 index 0000000000..866acdd44e --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-10.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[!!]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-11.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-11.js new file mode 100644 index 0000000000..4cad46b6b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-11.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[##]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-12.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-12.js new file mode 100644 index 0000000000..04909cbc0b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-12.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[$$]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-13.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-13.js new file mode 100644 index 0000000000..424f52d063 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-13.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[%%]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-14.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-14.js new file mode 100644 index 0000000000..6694bbee88 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-14.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[**]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-15.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-15.js new file mode 100644 index 0000000000..ec71a8d130 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-15.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[++]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-16.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-16.js new file mode 100644 index 0000000000..7599abcbaa --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-16.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[,,]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-17.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-17.js new file mode 100644 index 0000000000..95c93e4329 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-17.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[..]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-18.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-18.js new file mode 100644 index 0000000000..fe505f4759 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-18.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[::]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-19.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-19.js new file mode 100644 index 0000000000..70fd4c9177 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-19.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[;;]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-20.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-20.js new file mode 100644 index 0000000000..4a07e47ea1 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-20.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[<<]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-21.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-21.js new file mode 100644 index 0000000000..84d944a0b3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-21.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[==]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-22.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-22.js new file mode 100644 index 0000000000..386c331472 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-22.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[>>]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-23.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-23.js new file mode 100644 index 0000000000..2d0935f53b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-23.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[??]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-24.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-24.js new file mode 100644 index 0000000000..9241b85cf9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-24.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[@@]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-25.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-25.js new file mode 100644 index 0000000000..7d16515876 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-25.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[``]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-26.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-26.js new file mode 100644 index 0000000000..7d3c0d49ba --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-26.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[~~]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-27.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-27.js new file mode 100644 index 0000000000..2d2a4b1729 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-27.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[^^^]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-28.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-28.js new file mode 100644 index 0000000000..dc5a0ad292 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/breaking-change-from-u-to-v-28.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright 2023 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Some previously valid patterns with the `u` flag are now expected to + throw an early SyntaxError with the `v` flag. + https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/[_^^]/v; diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/browser.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/browser.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/cross-realm.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/cross-realm.js new file mode 100644 index 0000000000..977e85cfa6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/cross-realm.js @@ -0,0 +1,31 @@ +// Copyright (C) 2022 Mathias Bynens, Ron Buckton, and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.unicodeSets +description: RegExp#unicodeSets invoked on a cross-realm object +info: | + get RegExp.prototype.unicodeSets -> RegExpHasFlag + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +features: [regexp-v-flag, cross-realm] +---*/ + +var unicodeSets = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicodeSets').get; +var other = $262.createRealm().global; +var otherRegExpProto = other.RegExp.prototype; +var otherRegExpGetter = Object.getOwnPropertyDescriptor(otherRegExpProto, 'unicodeSets').get; + +assert.throws(TypeError, function() { + unicodeSets.call(otherRegExpProto); +}, 'cross-realm RegExp.prototype'); + +assert.throws(other.TypeError, function() { + otherRegExpGetter.call(RegExp.prototype); +}, 'cross-realm RegExp.prototype getter method against primary realm RegExp.prototype'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/length.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/length.js new file mode 100644 index 0000000000..47d429c6f6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/length.js @@ -0,0 +1,36 @@ +// Copyright (C) 2022 Mathias Bynens, Ron Buckton, and André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.unicodeSets +description: > + get RegExp.prototype.unicodeSets.length is 0. +info: | + get RegExp.prototype.unicodeSets + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [regexp-v-flag] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "unicodeSets"); + +assert.sameValue(desc.get.length, 0); + +verifyProperty(desc.get, "length", { + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/name.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/name.js new file mode 100644 index 0000000000..b67dbd8bec --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Mathias Bynens, Ron Buckton, and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.unicodeSets +description: > + RegExp.prototype.unicodeSets name +info: | + 17 ECMAScript Standard Built-in Objects + + Functions that are specified as get or set accessor functions of built-in + properties have "get " or "set " prepended to the property name string. +includes: [propertyHelper.js] +features: [regexp-v-flag] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "unicodeSets"); + +assert.sameValue( + desc.get.name, + "get unicodeSets" +); + +verifyProperty(desc.get, "name", { + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/prop-desc.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/prop-desc.js new file mode 100644 index 0000000000..a78ecb36f3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/prop-desc.js @@ -0,0 +1,31 @@ +// Copyright (C) 2022 Mathias Bynens, Ron Buckton, and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-get-regexp.prototype.unicodeSets +description: > + `pending` property descriptor +info: | + RegExp.prototype.unicodeSets is an accessor property whose set accessor + function is undefined. + + 17 ECMAScript Standard Built-in Objects + + Every accessor property described in clauses 18 through 26 and in Annex B.2 has the attributes + { [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. If only a get + accessor function is described, the set accessor function is the default value, undefined. If + only a set accessor is described the get accessor is the default value, undefined. +includes: [propertyHelper.js] +features: [regexp-v-flag] +---*/ + +var desc = Object.getOwnPropertyDescriptor(RegExp.prototype, "unicodeSets"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyProperty(RegExp.prototype, "unicodeSets", { + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/shell.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/shell.js diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-invalid-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-invalid-obj.js new file mode 100644 index 0000000000..def04a6521 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-invalid-obj.js @@ -0,0 +1,36 @@ +// Copyright (C) 2022 Mathias Bynens, Ron Buckton, and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.unicodeSets +description: Invoked on an object without an [[OriginalFlags]] internal slot +info: | + get RegExp.prototype.unicodeSets -> RegExpHasFlag + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. + b. Otherwise, throw a TypeError exception. +features: [regexp-v-flag] +---*/ + +var unicodeSets = Object.getOwnPropertyDescriptor(RegExp.prototype, 'unicodeSets').get; + +assert.throws(TypeError, function() { + unicodeSets.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + unicodeSets.call([]); +}, 'array exotic object'); + +assert.throws(TypeError, function() { + unicodeSets.call(arguments); +}, 'arguments object'); + +assert.throws(TypeError, function() { + unicodeSets.call(() => {}); +}, 'function object'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-non-obj.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-non-obj.js new file mode 100644 index 0000000000..a3b0e4528c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-non-obj.js @@ -0,0 +1,46 @@ +// Copyright (C) 2022 Mathias Bynens, Ron Buckton, and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.unicodeSets +description: > + `unicodeSets` accessor invoked on a non-object value +info: | + get RegExp.prototype.unicodeSets -> RegExpHasFlag + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. +features: [Symbol, regexp-v-flag] +---*/ + +var unicodeSets = Object.getOwnPropertyDescriptor(RegExp.prototype, "unicodeSets").get; + +assert.throws(TypeError, function() { + unicodeSets.call(undefined); +}, "undefined"); + +assert.throws(TypeError, function() { + unicodeSets.call(null); +}, "null"); + +assert.throws(TypeError, function() { + unicodeSets.call(true); +}, "true"); + +assert.throws(TypeError, function() { + unicodeSets.call("string"); +}, "string"); + +assert.throws(TypeError, function() { + unicodeSets.call(Symbol("s")); +}, "symbol"); + +assert.throws(TypeError, function() { + unicodeSets.call(4); +}, "number"); + +assert.throws(TypeError, function() { + unicodeSets.call(4n); +}, "bigint"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-regexp-prototype.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-regexp-prototype.js new file mode 100644 index 0000000000..251cc17eb6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-regexp-prototype.js @@ -0,0 +1,23 @@ +// Copyright (C) 2022 Mathias Bynens, Ron Buckton, and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.unicodeSets +description: > + Return value of `undefined` when the "this" value is the RegExp prototype + object +info: | + get RegExp.prototype.unicodeSets -> RegExpHasFlag + + 1. Let R be the this value. + 2. If Type(R) is not Object, throw a TypeError exception. + 3. If R does not have an [[OriginalFlags]] internal slot, then + a. If SameValue(R, %RegExpPrototype%) is true, return undefined. +features: [regexp-v-flag] +---*/ + +var get = Object.getOwnPropertyDescriptor(RegExp.prototype, "unicodeSets").get; + +assert.sameValue(get.call(RegExp.prototype), undefined); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-regexp.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-regexp.js new file mode 100644 index 0000000000..e2c782d190 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/this-val-regexp.js @@ -0,0 +1,53 @@ +// Copyright (C) 2022 Mathias Bynens, Ron Buckton, and the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-regexp.prototype.unicodeSets +description: > + `unicodeSets` accessor function invoked on a RegExp instance +info: | + get RegExp.prototype.unicodeSets -> RegExpHasFlag + + 4. Let flags be the value of R’s [[OriginalFlags]] internal slot. + 5. If flags contains the code unit "s", return true. + 6. Return false. +features: [regexp-v-flag] +---*/ + +assert.sameValue(/./.unicodeSets, false, "/./.unicodeSets"); +assert.sameValue(/./d.unicodeSets, false, "/./d.unicodeSets"); +assert.sameValue(/./g.unicodeSets, false, "/./g.unicodeSets"); +assert.sameValue(/./i.unicodeSets, false, "/./i.unicodeSets"); +assert.sameValue(/./m.unicodeSets, false, "/./m.unicodeSets"); +assert.sameValue(/./s.unicodeSets, false, "/./s.unicodeSets"); +assert.sameValue(/./u.unicodeSets, false, "/./u.unicodeSets"); +assert.sameValue(/./y.unicodeSets, false, "/./y.unicodeSets"); + +assert.sameValue(/./v.unicodeSets, true, "/./v.unicodeSets"); +assert.sameValue(/./vd.unicodeSets, true, "/./vd.unicodeSets"); +assert.sameValue(/./vg.unicodeSets, true, "/./vg.unicodeSets"); +assert.sameValue(/./vi.unicodeSets, true, "/./vi.unicodeSets"); +assert.sameValue(/./vm.unicodeSets, true, "/./vm.unicodeSets"); +assert.sameValue(/./vs.unicodeSets, true, "/./vs.unicodeSets"); +// Note: `/vu` throws an early parse error and is tested separately. +assert.sameValue(/./vy.unicodeSets, true, "/./vy.unicodeSets"); + +assert.sameValue(new RegExp(".", "").unicodeSets, false, "new RegExp('.', '').unicodeSets"); +assert.sameValue(new RegExp(".", "d").unicodeSets, false, "new RegExp('.', 'd').unicodeSets"); +assert.sameValue(new RegExp(".", "g").unicodeSets, false, "new RegExp('.', 'g').unicodeSets"); +assert.sameValue(new RegExp(".", "i").unicodeSets, false, "new RegExp('.', 'i').unicodeSets"); +assert.sameValue(new RegExp(".", "m").unicodeSets, false, "new RegExp('.', 'm').unicodeSets"); +assert.sameValue(new RegExp(".", "s").unicodeSets, false, "new RegExp('.', 's').unicodeSets"); +assert.sameValue(new RegExp(".", "u").unicodeSets, false, "new RegExp('.', 'u').unicodeSets"); +assert.sameValue(new RegExp(".", "y").unicodeSets, false, "new RegExp('.', 'y').unicodeSets"); + +assert.sameValue(new RegExp(".", "v").unicodeSets, true, "new RegExp('.', 'v').unicodeSets"); +assert.sameValue(new RegExp(".", "vd").unicodeSets, true, "new RegExp('.', 'vd').unicodeSets"); +assert.sameValue(new RegExp(".", "vg").unicodeSets, true, "new RegExp('.', 'vg').unicodeSets"); +assert.sameValue(new RegExp(".", "vi").unicodeSets, true, "new RegExp('.', 'vi').unicodeSets"); +assert.sameValue(new RegExp(".", "vm").unicodeSets, true, "new RegExp('.', 'vm').unicodeSets"); +assert.sameValue(new RegExp(".", "vs").unicodeSets, true, "new RegExp('.', 'vs').unicodeSets"); +// Note: `new RegExp(pattern, 'vu')` throws a runtime error and is tested separately. +assert.sameValue(new RegExp(".", "vy").unicodeSets, true, "new RegExp('.', 'vy').unicodeSets"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/uv-flags-constructor.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/uv-flags-constructor.js new file mode 100644 index 0000000000..1974aaa7c8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/uv-flags-constructor.js @@ -0,0 +1,16 @@ +// Copyright 2022 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Setting the `u` and `v` flag at the same time produces an error. +esid: sec-parsepattern +features: [regexp-v-flag] +---*/ + +assert.throws(SyntaxError, function() { + new RegExp(".", "uv"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/uv-flags.js b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/uv-flags.js new file mode 100644 index 0000000000..9432dda9b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/prototype/unicodeSets/uv-flags.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright 2022 Mathias Bynens. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Mathias Bynens +description: > + Setting the `u` and `v` flag at the same time produces an error. +esid: sec-parsepattern +negative: + phase: parse + type: SyntaxError +features: [regexp-v-flag] +---*/ + +$DONOTEVALUATE(); + +/./uv; |