arguments1.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. function write(v) { WScript.Echo(v + ""); }
  6. function foo(a, b, c) {
  7. arguments[0] = "arguments[0]";
  8. write("foo a: " + a);
  9. b = "b";
  10. write("args[1] : " + arguments[1]);
  11. write("args[3] : " + arguments[3]);
  12. var g = function(x) {
  13. write("g args[1] : " + arguments[1]);
  14. delete x[1];
  15. x[2] = "x[2]";
  16. a = "g.a";
  17. };
  18. g(arguments, "g[1]");
  19. write("after call to g a : " + a + " b: "+ b + " c: " + c);
  20. var str = "eval.c";
  21. eval("c = str");
  22. write("after eval args[2]: " + arguments[2]);
  23. var arguments = [];
  24. arguments[0] = "new[0]";
  25. write("after variable a : " + a);
  26. };
  27. foo("foo.a", "foo.b", "foo.c", "foo.d");
  28. foo("foo2.a", "foo2.b");
  29. (function()
  30. {
  31. eval("write(arguments[0])");
  32. })("goodbye");
  33. function lenChange() {
  34. write(arguments.length);
  35. arguments.length--;
  36. write(arguments.length);
  37. }
  38. lenChange(10,20,30);
  39. function testDelete(a){
  40. a = 2;
  41. delete arguments[0];
  42. if (arguments[0] === 2) {
  43. write("if0 :" + arguments[0]);
  44. }
  45. if (arguments[0] !== undefined) {
  46. write("if1 :" + arguments[0]);
  47. }
  48. arguments[0] = "A";
  49. if (arguments[0] !== "A") {
  50. write("if2 :" + arguments[0]);
  51. }
  52. eval('delete a;');
  53. return a;
  54. }
  55. write("Value returned : " + testDelete(1));
  56. function stackwithoverwrite() {
  57. for (var i = 0; i < arguments.length; i++) {
  58. write(arguments[i]);
  59. this.stackwithoverwrite.arguments[i] = i;
  60. write(arguments[i]);
  61. }
  62. }
  63. stackwithoverwrite('life', 'is', 'good');
  64. (function()
  65. {
  66. var arguments = ["a"];
  67. (function()
  68. {
  69. WScript.Echo(arguments.length);
  70. eval("");
  71. })()
  72. })();
  73. (function()
  74. {
  75. var arguments;
  76. (function()
  77. {
  78. eval("");
  79. })()
  80. })();
  81. // Dead loop body containing load of arguments property
  82. // interacted badly with stack args optimization.
  83. (function(){
  84. for (var i = 0; i < 0; ++i)
  85. {
  86. var c = arguments.some_property;
  87. }
  88. })();