Debian Codegraph @

js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/index/this-not-regexp-constructor.js

raw
1 // |reftest| skip -- legacy-regexp is not supported
2 // Copyright (C) 2020 ExE Boss. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 esid: pending
6 description: RegExp.$1-$9 throw a TypeError for non-%RegExp% receiver
7 info: |
8 get RegExp.$1-$9
9
10 1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpParen1-9]]).
11
12 GetLegacyRegExpStaticProperty( C, thisValue, internalSlotName ).
13
14 1. Assert C is an object that has an internal slot named internalSlotName.
15 2. If SameValue(C, thisValue) is false, throw a TypeError exception.
16 3. ...
17 features: [legacy-regexp]
18 ---*/
19
20 for (let i = 1; i <= 9; i++) {
21 const property = "$" + i;
22 const desc = Object.getOwnPropertyDescriptor(RegExp, property);
23
24 // Similar to the other test verifying the descriptor, but split as properties can be removed or changed
25 assert.sameValue(typeof desc.get, "function", property + " getter");
26
27 // If SameValue(C, thisValue) is false, throw a TypeError exception.
28 assert.throws(
29 TypeError,
30 function () {
31 desc.get();
32 },
33 "RegExp." + property + " getter throws for property descriptor receiver"
34 );
35
36 assert.throws(
37 TypeError,
38 function () {
39 desc.get.call(/ /);
40 },
41 "RegExp." + property + " getter throws for RegExp instance receiver"
42 );
43
44 assert.throws(
45 TypeError,
46 function () {
47 desc.get.call(RegExp.prototype);
48 },
49 "RegExp." + property + " getter throws for %RegExp.prototype% receiver"
50 );
51
52 [undefined, null, {}, true, false, 0, 1, "string"].forEach(function (value) {
53 assert.throws(
54 TypeError,
55 function () {
56 desc.get.call(value);
57 },
58 "RegExp." + property + ' getter throws for primitive "' + value + '" receiver'
59 );
60 });
61 }
62
63 reportCompare(0, 0);