initcachedscope.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // Test behavior of cached scopes.
  6. // For instance, make sure we do the right thing in same-named-formals cases.
  7. // 1. Case where function with a cached scope has "arguments".
  8. function f1(x, x) {
  9. WScript.Echo(x);
  10. eval('arguments[0] = 0');
  11. eval('arguments[1] = 1');
  12. WScript.Echo(x);
  13. }
  14. // Call f from inside a loop to force the scope to be cached.
  15. for (var i = 0; i < 1; i++) {
  16. f1('arg 0', 'arg 1');
  17. }
  18. // 2. Case with no "arguments" in the cached-scope function itself.
  19. function f2(x, x) {
  20. WScript.Echo(x);
  21. function g() {
  22. eval('x = "arg 1"');
  23. }
  24. g();
  25. WScript.Echo(x);
  26. }
  27. // Call f from inside a loop to force the scope to be cached.
  28. for (var i = 0; i < 1; i++) {
  29. f2('arg 0');
  30. }
  31. // 3. Case where nested function is cached and then undeferred (execute with /forcedeferparse).
  32. function f3(i) {
  33. function inner() {
  34. WScript.Echo('inner');
  35. }
  36. if (i % 2 != 0) {
  37. return eval('inner()');
  38. }
  39. f3(i + 1);
  40. }
  41. for (i = 0; i < 2; i++)
  42. f3(i);
  43. try
  44. {
  45. new Function("let ifviki, eval = (z = /x/g );L:switch(z) { case eval(\"z\"): return 503599627370497;break; }")();
  46. }
  47. catch(e)
  48. {
  49. WScript.Echo(e.message);
  50. }