v8/test/mjsunit/es8/syntactic-tail-call-simple.js
ishell 1350eb3dc9 [es8] More spec compliant syntactic tail calls implementation.
Unlike previous implementation where the 'continue' keyword was a feature of a return statement the keyword is now recognized as a part of expression. Error reporting was significantly improved.

--harmony-explicit-tailcalls option is now orthogonal to --harmony-tailcalls so we can test both modes at the same time.

This CL also adds %GetExceptionDetails(exception) that fetches hidden |start_pos| and |end_pos| values from the exception object.

BUG=v8:4915
LOG=N

Review-Url: https://codereview.chromium.org/1928203002
Cr-Commit-Position: refs/heads/master@{#36024}
2016-05-04 13:44:42 +00:00

122 lines
2.4 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 --harmony-explicit-tailcalls --stack-size=100
//
// Tail call normal functions.
//
(function() {
function f(n) {
if (n <= 0) {
return "foo";
}
return continue f(n - 1);
}
assertEquals("foo", f(1e5));
%OptimizeFunctionOnNextCall(f);
assertEquals("foo", f(1e5));
})();
(function() {
function f(n) {
if (n <= 0) {
return "foo";
}
return continue f(n - 1, 42); // Call with arguments adaptor.
}
assertEquals("foo", f(1e5));
%OptimizeFunctionOnNextCall(f);
assertEquals("foo", f(1e5));
})();
(function() {
function f(n){
if (n <= 0) {
return "foo";
}
return continue g(n - 1);
}
function g(n){
if (n <= 0) {
return "bar";
}
return continue f(n - 1);
}
assertEquals("foo", f(1e5));
assertEquals("bar", f(1e5 + 1));
%OptimizeFunctionOnNextCall(f);
assertEquals("foo", f(1e5));
assertEquals("bar", f(1e5 + 1));
})();
(function() {
function f(n){
if (n <= 0) {
return "foo";
}
return continue g(n - 1, 42); // Call with arguments adaptor.
}
function g(n){
if (n <= 0) {
return "bar";
}
return continue f(n - 1, 42); // Call with arguments adaptor.
}
assertEquals("foo", f(1e5));
assertEquals("bar", f(1e5 + 1));
%OptimizeFunctionOnNextCall(f);
assertEquals("foo", f(1e5));
assertEquals("bar", f(1e5 + 1));
})();
//
// Tail call bound functions.
//
(function() {
function f0(n) {
if (n <= 0) {
return "foo";
}
return continue f_bound(n - 1);
}
var f_bound = f0.bind({});
function f(n) {
return continue f_bound(n);
}
assertEquals("foo", f(1e5));
%OptimizeFunctionOnNextCall(f);
assertEquals("foo", f(1e5));
})();
(function() {
function f0(n){
if (n <= 0) {
return "foo";
}
return continue g_bound(n - 1);
}
function g0(n){
if (n <= 0) {
return "bar";
}
return continue f_bound(n - 1);
}
var f_bound = f0.bind({});
var g_bound = g0.bind({});
function f(n) {
return continue f_bound(n);
}
assertEquals("foo", f(1e5));
assertEquals("bar", f(1e5 + 1));
%OptimizeFunctionOnNextCall(f);
assertEquals("foo", f(1e5));
assertEquals("bar", f(1e5 + 1));
})();