summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.js')
-rw-r--r--js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-capture.js46
1 files changed, 46 insertions, 0 deletions
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);