moreSwitches2.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /*
  6. *******************************UNIT TEST FOR SWITCH CASE OPTIMIZATION*******************************
  7. * Test for 3 switch cases bailing out during different times of the execution.
  8. */
  9. function f(x,y,z)
  10. {
  11. switch(x)
  12. {
  13. case 1:
  14. WScript.Echo(1);
  15. break;
  16. case 2:
  17. WScript.Echo(2);
  18. break;
  19. case 3:
  20. WScript.Echo(3);
  21. break;
  22. case 4:
  23. WScript.Echo(4);
  24. break;
  25. default:
  26. WScript.Echo('default-x');
  27. break;
  28. }
  29. switch(y)
  30. {
  31. case 1:
  32. WScript.Echo(1);
  33. break;
  34. case 2:
  35. WScript.Echo(2);
  36. break;
  37. case 3:
  38. WScript.Echo(3);
  39. break;
  40. case 4:
  41. WScript.Echo(4);
  42. break;
  43. default:
  44. WScript.Echo('default-y');
  45. break;
  46. }
  47. switch(z)
  48. {
  49. case 1:
  50. WScript.Echo(1);
  51. break;
  52. default:
  53. WScript.Echo('default-z');
  54. break;
  55. }
  56. }
  57. //making the first switch to get profiled as object during first run in the interpreter
  58. f(1,2,new Object);
  59. f(1,2,3);
  60. f(1,2,3);
  61. f(1,2,3);
  62. f(1,2,3);
  63. //making the second and third to bail out.
  64. for(i=0;i<30;i++)
  65. {
  66. f(1,new Object,3);
  67. f(new Object,new Object,3);
  68. }