As per ES6, VMs should perform tail call optimization and prevent growth of call stack. This adds tail call optimization for recursion case (when function has explicit name and calls itself in `return`). Cross-function optimization is not currently performed as it's more complicated and requires value tracking.
23 lines
568 B
JavaScript
23 lines
568 B
JavaScript
"use strict";
|
|
|
|
(function f() {
|
|
var _arguments = arguments,
|
|
_this = this,
|
|
_shouldContinue,
|
|
_result;
|
|
do {
|
|
_shouldContinue = false;
|
|
_result = (function (n, /* should be undefined after first pass */m) {
|
|
if (n <= 0) {
|
|
return "foo";
|
|
}
|
|
// Should be clean (undefined) on each pass
|
|
var local;
|
|
_arguments = [n - 1];
|
|
_this = undefined;
|
|
return _shouldContinue = true;
|
|
}).apply(_this, _arguments);
|
|
} while (_shouldContinue);
|
|
return _result;
|
|
})(1000000, true) === "foo";
|