Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/WeakMap/iterable.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 es6id: 23.3.1.1
5 esid: sec-weakmap-iterable
6 description: >
7 Returns the new WeakMap adding the objects from the iterable parameter.
8 info: |
9 WeakMap ( [ iterable ] )
10
11 ...
12 9. Repeat
13 k. Let status be Call(adder, map, «k.[[value]], v.[[value]]»).
14 l. If status is an abrupt completion, return IteratorClose(iter, status).
15 includes: [compareArray.js]
16 ---*/
17
18 var first = {};
19 var second = {};
20 var results = [];
21 var set = WeakMap.prototype.set;
22 WeakMap.prototype.set = function(key, value) {
23 results.push({
24 _this: this,
25 key: key,
26 value: value
27 });
28 return set.call(this, key, value);
29 };
30 var map = new WeakMap([
31 [first, 42],
32 [second, 43]
33 ]);
34
35 assert.sameValue(results.length, 2, 'Called WeakMap#set for each object');
36 assert.sameValue(results[0].key, first, 'Adds object in order - first key');
37 assert.sameValue(results[0].value, 42, 'Adds object in order - first value');
38 assert.sameValue(results[0]._this, map, 'Adds object in order - this');
39 assert.sameValue(results[1].key, second, 'Adds object in order - second key');
40 assert.sameValue(results[1].value, 43, 'Adds object in order - second value');
41 assert.sameValue(results[1]._this, map, 'Adds object in order - this');