v8/test/mjsunit/compiler/promise-capability-default-closures.js
Benedikt Meurer e465a4f3be [turbofan] Support inlining of builtins based on SharedFunctionInfo.
This makes the inlining of the default resolve/reject closures generated
by the Promise constructor effective. To be really useful we still need
to have the Promise constructor inlined (work-in-progress) and eventually
track SharedFunctionInfo feedback in the CALL_IC.

Bug: v8:2206, v8:7253
Change-Id: I08fa8ca72754f459ae36027a55377ef57d411cdc
Reviewed-on: https://chromium-review.googlesource.com/926103
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51390}
2018-02-20 11:09:42 +00:00

48 lines
1.1 KiB
JavaScript

// 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
(function() {
var resolve, value;
(new Promise(r => resolve = r)).then(v => value = v);
function foo() { resolve(1); }
foo();
foo();
%OptimizeFunctionOnNextCall(foo);
foo();
setTimeout(_ => assertEquals(1, value));
})();
(function() {
var reject, value;
(new Promise((_, r) => reject = r)).catch(v => value = v);
function foo() { reject(1); }
foo();
foo();
%OptimizeFunctionOnNextCall(foo);
foo();
setTimeout(_ => assertEquals(1, value));
})();
(function() {
var value;
function foo(x) { return new Promise((resolve, reject) => resolve(x)); }
foo(1);
foo(1);
%OptimizeFunctionOnNextCall(foo);
foo(1).then(v => value = v);
setTimeout(_ => assertEquals(1, value));
})();
(function() {
var value;
function foo(x) { return new Promise((resolve, reject) => reject(x)); }
foo(1);
foo(1);
%OptimizeFunctionOnNextCall(foo);
foo(1).catch(v => value = v);
setTimeout(_ => assertEquals(1, value));
})();