diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/RegExp/prototype/Symbol.search')
25 files changed, 763 insertions, 0 deletions
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); |