aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/es6/collections-constructor-with-modified-array-prototype.js
blob: 0353be32050bbab306f6c535949515b72f1cbe27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax --opt

function TestSetWithCustomIterator(ctor) {
  const k1 = {};
  const k2 = {};
  let callCount = 0;
  Array.prototype[Symbol.iterator] = () => ({
    next: () =>
      callCount++ === 0
        ? { value: k2, done: false }
        : { done: true }
  });
  const entries = [k1];
  const set = new ctor(entries);
  assertFalse(set.has(k1));
  assertTrue(set.has(k2));
  assertEquals(2, callCount);
}
%PrepareFunctionForOptimization(TestSetWithCustomIterator);
TestSetWithCustomIterator(Set);
TestSetWithCustomIterator(Set);
TestSetWithCustomIterator(Set);
%OptimizeFunctionOnNextCall(TestSetWithCustomIterator);
TestSetWithCustomIterator(Set);
assertOptimized(TestSetWithCustomIterator);

TestSetWithCustomIterator(WeakSet);
%PrepareFunctionForOptimization(TestSetWithCustomIterator);
TestSetWithCustomIterator(WeakSet);
TestSetWithCustomIterator(WeakSet);
%OptimizeFunctionOnNextCall(TestSetWithCustomIterator);
TestSetWithCustomIterator(WeakSet);
assertOptimized(TestSetWithCustomIterator);

function TestMapWithCustomIterator(ctor) {
  const k1 = {};
  const k2 = {};
  let callCount = 0;
  Array.prototype[Symbol.iterator] = () => ({
    next: () =>
      callCount++ === 0
        ? { value: [k2, 2], done: false }
        : { done: true }
  });
  const entries = [[k1, 1]];
  const map = new ctor(entries);
  assertFalse(map.has(k1));
  assertEquals(2, map.get(k2));
  assertEquals(2, callCount);
}
%PrepareFunctionForOptimization(TestMapWithCustomIterator);
TestMapWithCustomIterator(Map);
TestMapWithCustomIterator(Map);
TestMapWithCustomIterator(Map);
%OptimizeFunctionOnNextCall(TestMapWithCustomIterator);
TestMapWithCustomIterator(Map);
assertOptimized(TestMapWithCustomIterator);

TestMapWithCustomIterator(WeakMap);
%PrepareFunctionForOptimization(TestMapWithCustomIterator);
TestMapWithCustomIterator(WeakMap);
TestMapWithCustomIterator(WeakMap);
%OptimizeFunctionOnNextCall(TestMapWithCustomIterator);
TestMapWithCustomIterator(WeakMap);
assertOptimized(TestMapWithCustomIterator);