summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/fn-coerce-replacement.js
blob: 6b09118351a47c7cd51fe48ebe5b54f10ed43a27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);