tor-browser

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

tco-non-eval-global.js (1154B)


      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 global environment.
      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 f(n) {
     33  "use strict";
     34  if (n === 0) {
     35    callCount += 1
     36    return;
     37  }
     38  return eval(n - 1);
     39 }
     40 eval = f;
     41 
     42 f($MAX_ITERATIONS);
     43 
     44 assert.sameValue(callCount, 1);
     45 
     46 reportCompare(0, 0);