summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/input/this-not-regexp-constructor.js
blob: 4a8a7ff3c6bf4bde81842f04cf5974d9beb0302b (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// |reftest| skip -- legacy-regexp is not supported
// Copyright (C) 2020 ExE Boss. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: pending
description: RegExp.input throws a TypeError for non-%RegExp% receiver
info: |
  get RegExp.input

  1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]]).

  set RegExp.input = val

  1. Return ? SetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpInput]], val).

  GetLegacyRegExpStaticProperty( C, thisValue, internalSlotName ).

  1. Assert C is an object that has an internal slot named internalSlotName.
  2. If SameValue(C, thisValue) is false, throw a TypeError exception.
  3. ...

  SetLegacyRegExpStaticProperty( C, thisValue, internalSlotName, val ).

  1. Assert C is an object that has an internal slot named internalSlotName.
  2. If SameValue(C, thisValue) is false, throw a TypeError exception.
  3. ...
features: [legacy-regexp]
---*/

["input", "$_"].forEach(function (property) {
  const desc = Object.getOwnPropertyDescriptor(RegExp, property);

  ["get", "set"].forEach(function (accessor) {
    const messagePrefix = "RegExp." + property + " " + accessor + "ter";

    // Similar to the other test verifying the descriptor, but split as properties can be removed or changed
    assert.sameValue(typeof desc[accessor], "function", messagePrefix);

    // If SameValue(C, thisValue) is false, throw a TypeError exception.
    assert.throws(
      TypeError,
      function () {
        desc[accessor]();
      },
      messagePrefix + " throws for property descriptor receiver"
    );

    assert.throws(
      TypeError,
      function () {
        desc[accessor].call(/ /);
      },
      messagePrefix + " throws for RegExp instance receiver"
    );

    assert.throws(
      TypeError,
      function () {
        desc[accessor].call(RegExp.prototype);
      },
      messagePrefix + " throws for %RegExp.prototype% receiver"
    );

    [undefined, null, {}, true, false, 0, 1, "string"].forEach(function (value) {
      assert.throws(
        TypeError,
        function () {
          desc[accessor].call(value);
        },
        messagePrefix + ' throws for primitive "' + value + '" receiver'
      );
    });
  });
});

reportCompare(0, 0);