Debian Codegraph @

js/src/tests/test262/annexB/built-ins/RegExp/legacy-accessors/leftContext/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.leftContext throws a TypeError for non-%RegExp% receiver
7 info: |
8 get RegExp.leftContext
9
10 1. Return ? GetLegacyRegExpStaticProperty(%RegExp%, this value, [[RegExpLeftContext]]).
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 ["leftContext", "$`"].forEach(function (property) {
21 const desc = Object.getOwnPropertyDescriptor(RegExp, property);
22
23 // Similar to the other test verifying the descriptor, but split as properties can be removed or changed
24 assert.sameValue(typeof desc.get, "function", property + " getter");
25
26 // If SameValue(C, thisValue) is false, throw a TypeError exception.
27 assert.throws(
28 TypeError,
29 function () {
30 desc.get();
31 },
32 "RegExp." + property + " getter throws for property descriptor receiver"
33 );
34
35 assert.throws(
36 TypeError,
37 function () {
38 desc.get.call(/ /);
39 },
40 "RegExp." + property + " getter throws for RegExp instance receiver"
41 );
42
43 assert.throws(
44 TypeError,
45 function () {
46 desc.get.call(RegExp.prototype);
47 },
48 "RegExp." + property + " getter throws for %RegExp.prototype% receiver"
49 );
50
51 [undefined, null, {}, true, false, 0, 1, "string"].forEach(function (value) {
52 assert.throws(
53 TypeError,
54 function () {
55 desc.get.call(value);
56 },
57 "RegExp." + property + ' getter throws for primitive "' + value + '" receiver'
58 );
59 });
60 });
61
62 reportCompare(0, 0);