2018-01-25 10:27:45 +00:00
|
|
|
// 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
|
|
|
|
|
2018-11-30 17:24:26 +00:00
|
|
|
var global;
|
|
|
|
|
2018-01-25 10:27:45 +00:00
|
|
|
function TestSetWithCustomIterator(ctor) {
|
|
|
|
const k1 = {};
|
|
|
|
const k2 = {};
|
|
|
|
const entries = [k1];
|
|
|
|
let callCount = 0;
|
|
|
|
entries[Symbol.iterator] = () => ({
|
|
|
|
next: () =>
|
|
|
|
callCount++ === 0
|
|
|
|
? { value: k2, done: false }
|
|
|
|
: { done: true }
|
|
|
|
});
|
|
|
|
const set = new ctor(entries);
|
|
|
|
assertFalse(set.has(k1));
|
|
|
|
assertTrue(set.has(k2));
|
|
|
|
assertEquals(2, callCount);
|
2018-11-30 17:24:26 +00:00
|
|
|
// Keep entries alive to avoid collection of the weakly held map in optimized
|
|
|
|
// code which causes the code to deopt.
|
|
|
|
global = entries;
|
2018-01-25 10:27:45 +00:00
|
|
|
}
|
2019-05-01 16:49:49 +00:00
|
|
|
%PrepareFunctionForOptimization(TestSetWithCustomIterator);
|
2018-01-25 10:27:45 +00:00
|
|
|
TestSetWithCustomIterator(Set);
|
|
|
|
TestSetWithCustomIterator(Set);
|
|
|
|
TestSetWithCustomIterator(Set);
|
|
|
|
%OptimizeFunctionOnNextCall(TestSetWithCustomIterator);
|
|
|
|
TestSetWithCustomIterator(Set);
|
|
|
|
assertOptimized(TestSetWithCustomIterator);
|
|
|
|
|
|
|
|
TestSetWithCustomIterator(WeakSet);
|
2019-05-01 16:49:49 +00:00
|
|
|
%PrepareFunctionForOptimization(TestSetWithCustomIterator);
|
2018-01-25 10:27:45 +00:00
|
|
|
TestSetWithCustomIterator(WeakSet);
|
|
|
|
TestSetWithCustomIterator(WeakSet);
|
|
|
|
%OptimizeFunctionOnNextCall(TestSetWithCustomIterator);
|
|
|
|
TestSetWithCustomIterator(WeakSet);
|
|
|
|
assertOptimized(TestSetWithCustomIterator);
|
|
|
|
|
|
|
|
function TestMapWithCustomIterator(ctor) {
|
|
|
|
const k1 = {};
|
|
|
|
const k2 = {};
|
|
|
|
const entries = [[k1, 1]];
|
|
|
|
let callCount = 0;
|
|
|
|
entries[Symbol.iterator] = () => ({
|
|
|
|
next: () =>
|
|
|
|
callCount++ === 0
|
|
|
|
? { value: [k2, 2], done: false }
|
|
|
|
: { done: true }
|
|
|
|
});
|
|
|
|
const map = new ctor(entries);
|
|
|
|
assertFalse(map.has(k1));
|
|
|
|
assertEquals(2, map.get(k2));
|
|
|
|
assertEquals(2, callCount);
|
2018-11-30 17:24:26 +00:00
|
|
|
// Keep entries alive to avoid collection of the weakly held map in optimized
|
|
|
|
// code which causes the code to deopt.
|
|
|
|
global = entries;
|
2018-01-25 10:27:45 +00:00
|
|
|
}
|
2019-05-01 16:49:49 +00:00
|
|
|
%PrepareFunctionForOptimization(TestMapWithCustomIterator);
|
2018-01-25 10:27:45 +00:00
|
|
|
TestMapWithCustomIterator(Map);
|
|
|
|
TestMapWithCustomIterator(Map);
|
|
|
|
TestMapWithCustomIterator(Map);
|
|
|
|
%OptimizeFunctionOnNextCall(TestMapWithCustomIterator);
|
|
|
|
TestMapWithCustomIterator(Map);
|
|
|
|
assertOptimized(TestMapWithCustomIterator);
|
|
|
|
|
|
|
|
TestMapWithCustomIterator(WeakMap);
|
2019-05-01 16:49:49 +00:00
|
|
|
%PrepareFunctionForOptimization(TestMapWithCustomIterator);
|
2018-01-25 10:27:45 +00:00
|
|
|
TestMapWithCustomIterator(WeakMap);
|
|
|
|
TestMapWithCustomIterator(WeakMap);
|
|
|
|
%OptimizeFunctionOnNextCall(TestMapWithCustomIterator);
|
|
|
|
TestMapWithCustomIterator(WeakMap);
|
|
|
|
assertOptimized(TestMapWithCustomIterator);
|