summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/RegExp/prototype/Symbol.replace/result-coerce-index-undefined.js
blob: 506b4837038131ebd04e7a27aff1d0736584933a (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
35
36
37
38
39
40
41
42
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);