2018-01-18 14:53:18 +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.
|
|
|
|
|
2021-03-12 11:18:14 +00:00
|
|
|
// Flags: --allow-natives-syntax --opt --no-lazy-feedback-allocation
|
2018-01-18 14:53:18 +00:00
|
|
|
|
|
|
|
function TestSetPrototypeModified(ctor) {
|
|
|
|
const originalPrototypeAdd = ctor.prototype.add;
|
|
|
|
const k1 = {};
|
|
|
|
const k2 = {};
|
|
|
|
const entries = [k1, k2];
|
|
|
|
let addCount = 0;
|
|
|
|
|
|
|
|
ctor.prototype.add = function(value) {
|
|
|
|
addCount++;
|
|
|
|
originalPrototypeAdd.call(this, value);
|
|
|
|
entries.length = 1;
|
|
|
|
};
|
|
|
|
const set = new ctor(entries);
|
|
|
|
|
|
|
|
assertEquals(1, addCount);
|
|
|
|
assertTrue(set.has(k1));
|
|
|
|
assertFalse(set.has(k2));
|
|
|
|
|
|
|
|
ctor.prototype.add = originalPrototypeAdd;
|
|
|
|
}
|
2019-04-30 13:39:53 +00:00
|
|
|
%PrepareFunctionForOptimization(TestSetPrototypeModified);
|
2018-01-18 14:53:18 +00:00
|
|
|
TestSetPrototypeModified(Set);
|
|
|
|
TestSetPrototypeModified(Set);
|
|
|
|
TestSetPrototypeModified(Set);
|
|
|
|
%OptimizeFunctionOnNextCall(TestSetPrototypeModified);
|
|
|
|
TestSetPrototypeModified(Set);
|
|
|
|
assertOptimized(TestSetPrototypeModified);
|
|
|
|
%DeoptimizeFunction(TestSetPrototypeModified);
|
|
|
|
|
2019-04-30 13:39:53 +00:00
|
|
|
%PrepareFunctionForOptimization(TestSetPrototypeModified);
|
2018-01-18 14:53:18 +00:00
|
|
|
TestSetPrototypeModified(WeakSet);
|
|
|
|
TestSetPrototypeModified(WeakSet);
|
|
|
|
TestSetPrototypeModified(WeakSet);
|
|
|
|
%OptimizeFunctionOnNextCall(TestSetPrototypeModified);
|
|
|
|
TestSetPrototypeModified(WeakSet);
|
|
|
|
assertOptimized(TestSetPrototypeModified);
|
|
|
|
%DeoptimizeFunction(TestSetPrototypeModified);
|
|
|
|
|
|
|
|
function TestMapPrototypeModified(ctor) {
|
|
|
|
const originalPrototypeSet = ctor.prototype.set;
|
|
|
|
const k1 = {};
|
|
|
|
const k2 = {};
|
|
|
|
const entries = [[k1, 1], [k2, 2]];
|
|
|
|
let setCount = 0;
|
|
|
|
|
|
|
|
ctor.prototype.set = function(key, value) {
|
|
|
|
setCount++;
|
|
|
|
originalPrototypeSet.call(this, key, value);
|
|
|
|
entries.length = 1;
|
|
|
|
};
|
|
|
|
const map = new ctor(entries);
|
|
|
|
|
|
|
|
assertEquals(1, setCount);
|
|
|
|
assertTrue(map.has(k1));
|
|
|
|
assertFalse(map.has(k2));
|
|
|
|
|
|
|
|
ctor.prototype.set = originalPrototypeSet;
|
|
|
|
}
|
2019-04-30 13:39:53 +00:00
|
|
|
%PrepareFunctionForOptimization(TestMapPrototypeModified);
|
2018-01-18 14:53:18 +00:00
|
|
|
TestMapPrototypeModified(Map);
|
|
|
|
TestMapPrototypeModified(Map);
|
|
|
|
TestMapPrototypeModified(Map);
|
|
|
|
%OptimizeFunctionOnNextCall(TestMapPrototypeModified);
|
|
|
|
TestMapPrototypeModified(Map);
|
|
|
|
assertOptimized(TestMapPrototypeModified);
|
|
|
|
%DeoptimizeFunction(TestMapPrototypeModified);
|
|
|
|
|
2019-04-30 13:39:53 +00:00
|
|
|
%PrepareFunctionForOptimization(TestMapPrototypeModified);
|
2018-01-18 14:53:18 +00:00
|
|
|
TestMapPrototypeModified(WeakMap);
|
|
|
|
TestMapPrototypeModified(WeakMap);
|
|
|
|
TestMapPrototypeModified(WeakMap);
|
|
|
|
%OptimizeFunctionOnNextCall(TestMapPrototypeModified);
|
|
|
|
TestMapPrototypeModified(WeakMap);
|
|
|
|
assertOptimized(TestMapPrototypeModified);
|