2015-04-16 17:32:05 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
// Test non-JSObject receiver.
|
|
|
|
function f(o) {
|
|
|
|
var result = [];
|
|
|
|
for (var i in o) {
|
|
|
|
result.push(i);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(["0"], f("a"));
|
|
|
|
assertEquals(["0"], f("a"));
|
2015-12-11 14:55:20 +00:00
|
|
|
|
2015-04-16 17:32:05 +00:00
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertEquals(["0","1","2"], f("bla"));
|
|
|
|
|
|
|
|
// Test the lazy deopt points.
|
|
|
|
var keys = ["a", "b", "c", "d"];
|
2016-03-23 08:26:35 +00:00
|
|
|
var property_descriptor_keys = [];
|
2015-04-16 17:32:05 +00:00
|
|
|
var deopt_enum = false;
|
2016-03-23 08:26:35 +00:00
|
|
|
var deopt_property_descriptor = false;
|
2015-04-16 17:32:05 +00:00
|
|
|
|
|
|
|
var handler = {
|
2016-02-22 21:09:49 +00:00
|
|
|
ownKeys() {
|
2015-04-16 17:32:05 +00:00
|
|
|
if (deopt_enum) {
|
|
|
|
%DeoptimizeFunction(f2);
|
|
|
|
deopt_enum = false;
|
|
|
|
}
|
2016-02-22 21:09:49 +00:00
|
|
|
return keys;
|
2015-04-16 17:32:05 +00:00
|
|
|
},
|
2016-03-23 08:26:35 +00:00
|
|
|
getOwnPropertyDescriptor(target, k) {
|
|
|
|
if (deopt_property_descriptor) {
|
2015-04-16 17:32:05 +00:00
|
|
|
%DeoptimizeFunction(f2);
|
2016-03-23 08:26:35 +00:00
|
|
|
deopt_property_descriptor = false;
|
2015-04-16 17:32:05 +00:00
|
|
|
}
|
2016-03-23 08:26:35 +00:00
|
|
|
property_descriptor_keys.push(k);
|
|
|
|
return { enumerable: true, configurable: true }
|
|
|
|
},
|
2015-04-16 17:32:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-13 14:13:50 +00:00
|
|
|
var proxy = new Proxy({}, handler);
|
2015-04-16 17:32:05 +00:00
|
|
|
var o = {__proto__: proxy};
|
|
|
|
|
|
|
|
function f2(o) {
|
|
|
|
var result = [];
|
|
|
|
for (var i in o) {
|
|
|
|
result.push(i);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_f2() {
|
|
|
|
assertEquals(keys, f2(o));
|
2016-03-23 08:26:35 +00:00
|
|
|
assertEquals(keys, property_descriptor_keys);
|
|
|
|
property_descriptor_keys.length = 0;
|
2015-04-16 17:32:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_f2();
|
|
|
|
check_f2();
|
2015-12-11 14:55:20 +00:00
|
|
|
|
2016-01-25 10:29:31 +00:00
|
|
|
// Test lazy deopt after ForInEnumerate
|
2015-04-16 17:32:05 +00:00
|
|
|
%OptimizeFunctionOnNextCall(f2);
|
|
|
|
deopt_enum = true;
|
|
|
|
check_f2();
|
2015-12-11 14:55:20 +00:00
|
|
|
|
2015-04-16 17:32:05 +00:00
|
|
|
// Test lazy deopt after FILTER_KEY
|
|
|
|
%OptimizeFunctionOnNextCall(f2);
|
2016-03-23 08:26:35 +00:00
|
|
|
deopt_property_descriptor = true;
|
2015-04-16 17:32:05 +00:00
|
|
|
check_f2();
|
|
|
|
|
2016-03-23 08:26:35 +00:00
|
|
|
|
2015-04-16 17:32:05 +00:00
|
|
|
function f3(o) {
|
|
|
|
for (var i in o) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f3({__proto__:{x:1}});
|
|
|
|
f3({__proto__:{x:1}});
|
2015-12-11 14:55:20 +00:00
|
|
|
|
2015-04-16 17:32:05 +00:00
|
|
|
%OptimizeFunctionOnNextCall(f3);
|
|
|
|
f3(undefined);
|
|
|
|
f3(null);
|
2015-10-27 15:17:02 +00:00
|
|
|
|
|
|
|
// Reliable repro for an issue previously flushed out by GC stress.
|
|
|
|
var p = {x: "x"}
|
|
|
|
|
|
|
|
function f4(o, p) {
|
|
|
|
var result = [];
|
|
|
|
for (var i in o) {
|
|
|
|
var j = p.x + "str";
|
|
|
|
result.push(i);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2015-12-11 14:55:20 +00:00
|
|
|
|
2015-10-27 15:17:02 +00:00
|
|
|
function check_f4() {
|
|
|
|
assertEquals(keys, f4(o, p));
|
2016-03-23 08:26:35 +00:00
|
|
|
assertEquals(keys, property_descriptor_keys);
|
|
|
|
property_descriptor_keys.length = 0;
|
2015-10-27 15:17:02 +00:00
|
|
|
}
|
2015-12-11 14:55:20 +00:00
|
|
|
|
2015-10-27 15:17:02 +00:00
|
|
|
check_f4();
|
|
|
|
check_f4();
|
2015-12-11 14:55:20 +00:00
|
|
|
|
2015-10-27 15:17:02 +00:00
|
|
|
%OptimizeFunctionOnNextCall(f4);
|
2015-12-11 14:55:20 +00:00
|
|
|
|
2015-10-27 15:17:02 +00:00
|
|
|
p.y = "y"; // Change map, cause eager deopt.
|
|
|
|
check_f4();
|
|
|
|
|
|
|
|
// Repro for Turbofan equivalent.
|
|
|
|
var x;
|
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
var Debug = debug.Debug;
|
|
|
|
|
|
|
|
function listener(event, exec_state, event_data, data) {
|
|
|
|
if (event == Debug.DebugEvent.Break) {
|
|
|
|
%DeoptimizeFunction(f5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var handler3 = {
|
2016-02-22 21:09:49 +00:00
|
|
|
ownKeys() { return ["a", "b"] },
|
2016-03-23 08:26:35 +00:00
|
|
|
getOwnPropertyDescriptor(target, k) {
|
2015-10-27 15:17:02 +00:00
|
|
|
if (k == "a") count++;
|
2016-03-23 08:26:35 +00:00
|
|
|
if (x) %ScheduleBreak()
|
|
|
|
return { enumerable: true, configurable: true }
|
2015-10-27 15:17:02 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-13 14:13:50 +00:00
|
|
|
var proxy3 = new Proxy({}, handler3);
|
2015-10-27 15:17:02 +00:00
|
|
|
var o3 = {__proto__: proxy3};
|
|
|
|
|
|
|
|
function f5() {
|
|
|
|
for (var p in o3) {
|
|
|
|
print(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x = false;
|
|
|
|
|
|
|
|
f5(); f5(); f5();
|
|
|
|
%OptimizeFunctionOnNextCall(f5);
|
|
|
|
x = true;
|
|
|
|
count = 0;
|
|
|
|
Debug.setListener(listener);
|
|
|
|
f5();
|
|
|
|
Debug.setListener(null);
|
|
|
|
assertEquals(1, count);
|