Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Map/iterable-calls-set.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.1.1.1
5 description: >
6 new Map calls `set` for each item on the iterable argument in order.
7 info: |
8 Map ( [ iterable ] )
9
10 ...
11 9. Repeat
12 ...
13 k. Let status be Call(adder, map, «k.[[value]], v.[[value]]»).
14 ...
15 includes: [compareArray.js]
16 ---*/
17
18 var mapSet = Map.prototype.set;
19 var counter = 0;
20
21 var iterable = [
22 ["foo", 1],
23 ["bar", 2]
24 ];
25 var results = [];
26 var _this = [];
27
28 Map.prototype.set = function(k, v) {
29 counter++;
30 results.push([k, v]);
31 _this.push(this);
32 mapSet.call(this, k, v);
33 };
34
35 var map = new Map(iterable);
36
37 assert.sameValue(counter, 2, "`Map.prototype.set` called twice.");
38
39 assert(compareArray(results[0], iterable[0]));
40 assert(compareArray(results[1], iterable[1]));
41 assert.sameValue(_this[0], map);
42 assert.sameValue(_this[1], map);