eval-optional-call.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2020 Toru Nagashima. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. esid: sec-optional-chaining-chain-evaluation
  5. description: optional call invoked on eval function should be indirect eval.
  6. info: |
  7. Runtime Semantics: ChainEvaluation
  8. OptionalChain: ?. Arguments
  9. 1. Let thisChain be this OptionalChain.
  10. 2. Let tailCall be IsInTailPosition(thisChain).
  11. 3. Return ? EvaluateCall(baseValue, baseReference, Arguments, tailCall).
  12. Runtime Semantics: EvaluateCall ( func, ref, arguments, tailPosition )
  13. ...
  14. 7. Let result be Call(func, thisValue, argList).
  15. ...
  16. eval ( x )
  17. ...
  18. 4. Return ? PerformEval(x, callerRealm, false, false).
  19. Runtime Semantics: PerformEval ( x, callerRealm, strictCaller, direct )
  20. features: [optional-chaining]
  21. ---*/
  22. const a = 'global';
  23. function fn() {
  24. const a = 'local';
  25. return eval?.('a');
  26. }
  27. assert.sameValue(fn(), 'global', 'fn() returns "global" value from indirect eval');
  28. const b = (a => eval?.('a'))('local');
  29. assert.sameValue(b, 'global', 'b is "global", from indirect eval not observing parameter');