v8/test/mjsunit/regress/regress-4715.js
Ross McIlroy d7a8170d2d [cleanup] Add missing %PrepareFunctionForOptimize in mjsunit tests
Bug: v8:8801,v8:8394,v8:9183
Change-Id: If482c6a14f389d54c6ca3891aa7b8475f7a1fce1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1660617
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Mythri Alle <mythria@chromium.org>
Auto-Submit: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62192}
2019-06-14 17:03:41 +00:00

50 lines
1.1 KiB
JavaScript

// Copyright 2016 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 --expose-gc
var training = {};
training.a = "nop";
training.slow = "nop";
delete training.slow; // Dictionary-mode properties => slow-mode for-in.
var keepalive = {};
keepalive.a = "nop"; // Keep a map early in the transition chain alive.
function GetReal() {
var r = {};
r.a = "nop";
r.b = "nop";
r.c = "dictionarize",
r.d = "gc";
r.e = "result";
return r;
};
function SideEffect(object, action) {
if (action === "dictionarize") {
delete object.a;
} else if (action === "gc") {
gc();
}
}
function foo(object) {
for (var key in object) {
SideEffect(object, object[key]);
}
return key;
}
%PrepareFunctionForOptimization(foo);
// Collect type feedback for slow-mode for-in.
foo(training);
SideEffect({a: 0}, "dictionarize");
SideEffect({}, "gc");
// Compile for slow-mode objects...
%OptimizeFunctionOnNextCall(foo);
// ...and pass in a fast-mode object.
assertEquals("e", foo(GetReal()));