Skip to content
Snippets Groups Projects
Commit ea89b2ea authored by Gorkem Yakin's avatar Gorkem Yakin
Browse files

Merge pull request #487 from jugglinmike/tco

Add tests for tail-call optimization
parents d549225f 4dc81d37
No related branches found
No related tags found
No related merge requests found
Showing
with 386 additions and 0 deletions
// This defines the number of consecutive recursive function calls that must be
// made in order to prove that stack frames are properly destroyed according to
// ES2015 tail call optimization semantics.
var $MAX_ITERATIONS = 100000;
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
function getF() { return f; }
return getF()(n - 1);
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
return f(n - 1);
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
return 0, f(n - 1);
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
return true ? f(n - 1) : 0;
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
return false ? 0 : f(n - 1);
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
return true && f(n - 1);
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
return false || f(n - 1);
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
(function() {
var finished = false;
function getF() {
return f;
}
function f(_, n) {
if (n === 0) {
finished = true;
return;
}
return getF()`${n-1}`;
}
f(null, $MAX_ITERATIONS);
return finished;
}());
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
(function() {
var finished = false;
function f(_, n) {
if (n === 0) {
finished = true;
return;
}
return f`${n-1}`;
}
f(null, $MAX_ITERATIONS);
return finished;
}());
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Expression is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
return (f(n - 1));
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement within statement is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
{ void 0; return f(n - 1); }
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement within statement is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
{ return f(n - 1); }
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement within statement is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
do {
return f(n - 1);
} while (false)
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement within statement is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
for (const x = 0; ;) {
return f(n - 1);
}
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement within statement is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
for (let x = 0; ;) {
return f(n - 1);
}
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement within statement is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
var x;
for (x = 0; x < 1; ++x) {
return f(n - 1);
}
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement within statement is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
for (var x = 0; ;) {
return f(n - 1);
}
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement within statement is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
if (false) { } else { return f(n - 1); }
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Statement within statement is a candidate for tail-call optimization.
id: static-semantics-hasproductionintailposition
flags: [onlyStrict]
features: [tail-call-optimization]
includes: [tco-helper.js]
---*/
var callCount = 0;
(function f(n) {
if (n === 0) {
callCount += 1
return;
}
if (true) { return f(n - 1); }
}($MAX_ITERATIONS));
assert.sameValue(callCount, 1);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment