Debian Codegraph @

js/src/tests/test262/built-ins/WeakMap/iterator-items-keys-cannot-be-held-weakly.js

raw
1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-weakmap-iterable
5 description: >
6 Throws a TypeError if keys in iterable items cannot be held weakly.
7 info: |
8 WeakMap ( [ _iterable_ ] )
9 5. Let _adder_ be ? Get(_map_, *"set"*).
10 6. Return ? AddEntriesFromIterable(_map_, _iterable_, _adder_).
11
12 AddEntriesFromIterable:
13 3. Repeat,
14 i. Let _status_ be Completion(Call(_adder_, _target_, « _k_, _v_ »)).
15 j. IfAbruptCloseIterator(_status_, _iteratorRecord_).
16
17 WeakMap.prototype.set( _key_, _value_ ):
18 4. If CanBeHeldWeakly(_key_) is *false*, throw a *TypeError* exception.
19 features: [Symbol, WeakMap]
20 ---*/
21
22 assert.throws(TypeError, function() {
23 new WeakMap([1, 1]);
24 });
25
26 assert.throws(TypeError, function() {
27 new WeakMap(['', 1]);
28 });
29
30 assert.throws(TypeError, function() {
31 new WeakMap([true, 1]);
32 });
33
34 assert.throws(TypeError, function() {
35 new WeakMap([null, 1]);
36 });
37
38 assert.throws(TypeError, function() {
39 new WeakMap([Symbol.for('registered symbol'), 1]);
40 }, 'Registered symbol not allowed as a WeakMap key');
41
42 assert.throws(TypeError, function() {
43 new WeakMap([undefined, 1]);
44 });
45
46 assert.throws(TypeError, function() {
47 new WeakMap([
48 ['a', 1], 2
49 ]);
50 });
51
52 reportCompare(0, 0);