tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

tco-non-eval-function-dynamic.js (1248B)


      1 // |reftest| skip -- tail-call-optimization is not supported
      2 // Copyright (C) 2017 André Bargull. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: sec-function-calls-runtime-semantics-evaluation
      7 description: >
      8  Tail-call with identifier named "eval" in function environment, local "eval" binding dynamically added.
      9 info: |
     10  12.3.4.1 Runtime Semantics: Evaluation
     11    ...
     12    6. If Type(ref) is Reference and IsPropertyReference(ref) is false and
     13       GetReferencedName(ref) is "eval", then
     14      a. If SameValue(func, %eval%) is true, then
     15        ...
     16    ...
     17    9. Return ? EvaluateCall(func, ref, arguments, tailCall).
     18 
     19  12.3.4.2 Runtime Semantics: EvaluateCall( func, ref, arguments, tailPosition )
     20    ...
     21    7. If tailPosition is true, perform PrepareForTailCall().
     22    8. Let result be Call(func, thisValue, argList).
     23    ...
     24 
     25 flags: [noStrict]
     26 features: [tail-call-optimization]
     27 includes: [tcoHelper.js]
     28 ---*/
     29 
     30 var callCount = 0;
     31 
     32 (function() {
     33  function f(n) {
     34    "use strict";
     35    if (n === 0) {
     36      callCount += 1
     37      return;
     38    }
     39    return eval(n - 1);
     40  }
     41  eval("var eval = f;");
     42  f($MAX_ITERATIONS);
     43 })();
     44 
     45 assert.sameValue(callCount, 1);
     46 
     47 reportCompare(0, 0);