mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 16:04:36 +02:00
Merge pull request #487 from jugglinmike/tco
Add tests for tail-call optimization
This commit is contained in:
commit
ea89b2ea18
4
harness/tco-helper.js
Normal file
4
harness/tco-helper.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// 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;
|
20
test/language/expressions/call/tco-call-args.js
Normal file
20
test/language/expressions/call/tco-call-args.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// 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);
|
19
test/language/expressions/call/tco-member-args.js
Normal file
19
test/language/expressions/call/tco-member-args.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/expressions/comma/tco-final.js
Normal file
19
test/language/expressions/comma/tco-final.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/expressions/conditional/tco-cond.js
Normal file
19
test/language/expressions/conditional/tco-cond.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/expressions/conditional/tco-pos.js
Normal file
19
test/language/expressions/conditional/tco-pos.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/expressions/logical-and/tco-right.js
Normal file
19
test/language/expressions/logical-and/tco-right.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/expressions/logical-or/tco-right.js
Normal file
19
test/language/expressions/logical-or/tco-right.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
25
test/language/expressions/tagged-template/tco-call.js
Normal file
25
test/language/expressions/tagged-template/tco-call.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// 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;
|
||||||
|
}());
|
22
test/language/expressions/tagged-template/tco-member.js
Normal file
22
test/language/expressions/tagged-template/tco-member.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// 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;
|
||||||
|
}());
|
19
test/language/expressions/tco-pos.js
Normal file
19
test/language/expressions/tco-pos.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/statements/block/tco-stmt-list.js
Normal file
19
test/language/statements/block/tco-stmt-list.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/statements/block/tco-stmt.js
Normal file
19
test/language/statements/block/tco-stmt.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
21
test/language/statements/do-while/tco-body.js
Normal file
21
test/language/statements/do-while/tco-body.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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);
|
21
test/language/statements/for/tco-const-body.js
Normal file
21
test/language/statements/for/tco-const-body.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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);
|
21
test/language/statements/for/tco-let-body.js
Normal file
21
test/language/statements/for/tco-let-body.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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);
|
22
test/language/statements/for/tco-lhs-body.js
Normal file
22
test/language/statements/for/tco-lhs-body.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// 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);
|
21
test/language/statements/for/tco-var-body.js
Normal file
21
test/language/statements/for/tco-var-body.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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);
|
19
test/language/statements/if/tco-else-body.js
Normal file
19
test/language/statements/if/tco-else-body.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/statements/if/tco-if-body.js
Normal file
19
test/language/statements/if/tco-if-body.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/statements/labeled/tco.js
Normal file
19
test/language/statements/labeled/tco.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/statements/return/tco.js
Normal file
19
test/language/statements/return/tco.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/statements/switch/tco-case-body-dflt.js
Normal file
19
test/language/statements/switch/tco-case-body-dflt.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/statements/switch/tco-case-body.js
Normal file
19
test/language/statements/switch/tco-case-body.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
19
test/language/statements/switch/tco-dftl-body.js
Normal file
19
test/language/statements/switch/tco-dftl-body.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// 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);
|
21
test/language/statements/try/tco-catch-finally.js
Normal file
21
test/language/statements/try/tco-catch-finally.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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);
|
23
test/language/statements/try/tco-catch.js
Normal file
23
test/language/statements/try/tco-catch.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// 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);
|
21
test/language/statements/try/tco-finally.js
Normal file
21
test/language/statements/try/tco-finally.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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);
|
21
test/language/statements/while/tco-body.js
Normal file
21
test/language/statements/while/tco-body.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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);
|
Loading…
x
Reference in New Issue
Block a user