bug_OS_2299723.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // let and const variables should exhibit redeclaration and assignment to const errors
  6. // even when they are located in an ActivationObjectEx cached scope.
  7. // Test them independently
  8. //
  9. function f0() {
  10. let x = 0;
  11. try {
  12. eval("var x = 5");
  13. } catch (e) {
  14. WScript.Echo("eval('var x = 5') threw '" + e.message + "'");
  15. }
  16. try {
  17. eval("x = 5");
  18. } catch (e) {
  19. WScript.Echo("unexpected error thrown: '" + e.message + "'");
  20. }
  21. WScript.Echo("x: " + x);
  22. }
  23. // Called-in-loop is no longer the heuristic we want to use to enable scope caching.
  24. // Instead rely on -force:cachedscope and call the test function only once here.
  25. f0();
  26. function f1() {
  27. const y = 1;
  28. try {
  29. eval("var y = 5");
  30. } catch (e) {
  31. WScript.Echo("eval('var y = 5') threw '" + e.message + "'");
  32. }
  33. try {
  34. eval("y = 5");
  35. } catch (e) {
  36. WScript.Echo("eval('y = 5') threw '" + e.message + "'");
  37. }
  38. WScript.Echo("y: " + y);
  39. }
  40. // Called-in-loop is no longer the heuristic we want to use to enable scope caching.
  41. // Instead rely on -force:cachedscope and call the test function only once here.
  42. f1();