Debian Codegraph @

js/src/tests/non262/WeakMap/getOrInsert/not-a-constructor.js

raw
1 // |reftest| shell-option(--enable-upsert) skip-if(!WeakMap.prototype.getOrInsert)
2 // Copyright (C) 2020 Rick Waldron. All rights reserved.
3 // Copyright (C) 2025 Jonas Haukenes. All rights reserved.
4 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: proposal-upsert
7 description: >
8 WeakMap.prototype.getOrInsert does not implement [[Construct]], is not new-able
9 info: |
10 ECMAScript Function Objects
11
12 Built-in function objects that are not identified as constructors do not
13 implement the [[Construct]] internal method unless otherwise specified in
14 the description of a particular function.
15
16 sec-evaluatenew
17
18 ...
19 7. If IsConstructor(constructor) is false, throw a TypeError exception.
20 ...
21 includes: [isConstructor.js]
22 features: [Reflect.construct, WeakMap, arrow-function]
23 ---*/
24
25 assertEq(
26 isConstructor(WeakMap.prototype.getOrInsert),
27 false,
28 'isConstructor(WeakMap.prototype.getOrInsert) must return false'
29 );
30
31 assertThrowsInstanceOf(() => {
32 let wm = new WeakMap(); new wm.getOrInsert({}, 1);
33 }, TypeError);
34
35 reportCompare(0, 0);