Skip to content
Snippets Groups Projects
Commit 4dc81d37 authored by Mike Pennisi's avatar Mike Pennisi
Browse files

Add tests for tail-call optimization

ECMAScript 2015 introduced tail call optimization for function calls
occuring in a number of positions in the grammar. Assert expected
behavior by triggering a large (but configurable) number of recursive
function calls in these positions. Compliant runtimes will execute such
programs without error; non-compliant runtimes are expected to fail
these tests by throwing an error or crashing when system resources are
exhausted.
parent fbad3495
No related branches found
No related tags found
No related merge requests found
// 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;
}
test262: 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 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;
}
switch(0) { case 0: return f(n - 1); default: }
}($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;
}
switch(0) { case 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;
}
switch(0) { default: 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;
}
try { } catch (err) { } finally {
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;
}
try {
throw null;
} catch (err) {
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;
}
try { } finally {
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;
}
while (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