summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/annexB/built-ins/String/prototype/replace/custom-replacer-emulates-undefined.js
blob: 07c5ad606fe0eaedc4e9db152eb43afe60f9ebb9 (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
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-string.prototype.replace
description: >
  [[IsHTMLDDA]] object as @@replace method gets called.
info: |
  String.prototype.replace ( searchValue, replaceValue )

  [...]
  2. If searchValue is neither undefined nor null, then
    a. Let replacer be ? GetMethod(searchValue, @@replace).
    b. If replacer is not undefined, then
      i. Return ? Call(replacer, searchValue, « O, replaceValue »).
features: [Symbol.replace, IsHTMLDDA]
---*/

var searchValue = $262.IsHTMLDDA;
var replacerGets = 0;
Object.defineProperty(searchValue, Symbol.replace, {
  get: function() {
    replacerGets += 1;
    return searchValue;
  },
  configurable: true,
});

assert.sameValue("".replace(searchValue), null);
assert.sameValue(replacerGets, 1);

reportCompare(0, 0);