invalcachedscope.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // "outer" is called in a loop but can't re-use its scope because "inner" escapes.
  6. // The escape isn't detected with /forcedeferparse, because inner2 isn't visible to the
  7. // byte code gen.
  8. // So executing inner2 must invalidate the cache.
  9. // If the cache is not invalidated, the call to escaped[1] will get the value of "x"
  10. // from the scope cached when we executed escaped[0].
  11. function outer() {
  12. var x = "yes!";
  13. function inner() {
  14. eval('WScript.Echo(x); x = "no!"');
  15. }
  16. function inner2() {
  17. return inner;
  18. }
  19. return inner2();
  20. }
  21. var escaped = [2];
  22. for (var i = 0; i < 2; i++) {
  23. escaped[i] = outer();
  24. }
  25. for (i = 0; i < escaped.length; i++) {
  26. escaped[i]();
  27. }
  28. // As above, but the escape of "inner" is hidden by eval.
  29. // Cache must be invalidated by the runtime when it does GetPropertyScoped.
  30. function outer2() {
  31. var x = "yes!";
  32. function inner() {
  33. eval('WScript.Echo(x); x = "no!"');
  34. }
  35. function inner2() {
  36. return eval('inner');
  37. }
  38. return inner2();
  39. }
  40. for (i = 0; i < 2; i++) {
  41. escaped[i] = outer2();
  42. }
  43. for (i = 0; i < escaped.length; i++) {
  44. escaped[i]();
  45. }