stackargs.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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()
  6. {
  7. WScript.Echo(arguments[0]);
  8. }
  9. write("Test case #1");
  10. function TestCase1()
  11. {
  12. function foo()
  13. {
  14. write(arguments.caller);
  15. write(arguments.callee);
  16. }
  17. foo();
  18. }
  19. TestCase1();
  20. write("Test case #2");
  21. function TestCase2()
  22. {
  23. function foo()
  24. {
  25. var a = arguments;
  26. return a[0];
  27. }
  28. var j=0;
  29. for(var i=0;i<10;i++)
  30. {
  31. j +=foo(10);
  32. }
  33. write(j);
  34. }
  35. TestCase2();
  36. write("Test case #3");
  37. function TestCase3()
  38. {
  39. function foo()
  40. {
  41. return arguments[1];
  42. }
  43. write(""+foo(10));
  44. }
  45. TestCase3();
  46. write("Test case #4");
  47. function TestCase4()
  48. {
  49. function foo()
  50. {
  51. var a = arguments;
  52. eval("arguments[1] = 10");
  53. return a[1];
  54. }
  55. write(foo());
  56. }
  57. TestCase4();
  58. write("Test case #5");
  59. function TestCase5()
  60. {
  61. function foo()
  62. {
  63. for (var a = 1; a < arguments.length; ++a)
  64. {
  65. write(arguments[a]);
  66. }
  67. }
  68. foo(10,20,30,40);
  69. }
  70. TestCase5();
  71. write("Test case #6");
  72. function TestCase6()
  73. {
  74. (function()
  75. {
  76. eval("write(arguments[0])");
  77. })("goodbye");
  78. }
  79. TestCase6();
  80. write("Test case #7");
  81. function TestCase7()
  82. {
  83. function lenChange()
  84. {
  85. write(arguments.length);
  86. arguments.length--;
  87. write(arguments.length);
  88. }
  89. lenChange(10,20,30);
  90. }
  91. TestCase7();
  92. write("Test case #8");
  93. function TestCase8()
  94. {
  95. function foo()
  96. {
  97. try {
  98. arguments[1] = 26;
  99. } catch(e)
  100. {
  101. }
  102. write(arguments[1]);
  103. }
  104. foo();
  105. }
  106. TestCase8();
  107. write("Test case #9");
  108. function TestCase9()
  109. {
  110. function foo()
  111. {
  112. arguments.caller = 0;
  113. }
  114. foo();
  115. }
  116. TestCase9();
  117. write("Test case #10");
  118. function TestCase10()
  119. {
  120. function foo()
  121. {
  122. write(typeof(arguments));
  123. }
  124. foo();
  125. }
  126. TestCase10();
  127. write("Test case #11");
  128. function TestCase11()
  129. {
  130. function foo()
  131. {
  132. write(arguments.callee);
  133. write(arguments.caller);
  134. }
  135. function bar()
  136. {
  137. foo();
  138. }
  139. bar();
  140. }
  141. TestCase11();
  142. write("Test case #12");
  143. function TestCase12()
  144. {
  145. function foo()
  146. {
  147. function bar()
  148. {
  149. return arguments[0];
  150. }
  151. return bar(arguments[0]);
  152. }
  153. write(foo(10));
  154. }
  155. TestCase12();
  156. write("Test case #13");
  157. function TestCase13()
  158. {
  159. (function ()
  160. {
  161. write(arguments.callee);
  162. })();
  163. }
  164. TestCase13();
  165. write("Test case #14");
  166. function TestCase14()
  167. {
  168. var escape;
  169. function foo()
  170. {
  171. escape = arguments.caller;
  172. }
  173. foo();
  174. write(escape);
  175. }
  176. TestCase14();
  177. write("Test case #15");
  178. function TestCase15()
  179. {
  180. function foo()
  181. {
  182. var i = "abc";
  183. write(arguments[i]);
  184. }
  185. foo();
  186. }
  187. TestCase15();
  188. write("Test case #16");
  189. function TestCase16()
  190. {
  191. function foo()
  192. {
  193. var a = []
  194. write(a[arguments]);
  195. }
  196. foo();
  197. }
  198. TestCase16();
  199. write("Test case #17");
  200. function TestCase17()
  201. {
  202. (function () {
  203. write(arguments ^= 1);
  204. })();
  205. (function () {
  206. write(arguments *= 1.7);
  207. })();
  208. }
  209. TestCase17();
  210. var print = function(){return this};
  211. (function(){/*sStart*/;while(("u143C".x) && 0){print(functional >> arguments); };;/*sEnd*/})();
  212. write("Test case #18");
  213. // Check negative index
  214. (function(){
  215. var i = -0x1000;
  216. (function(){
  217. write(arguments[i]);
  218. })();
  219. })();
  220. write("Test case #19");
  221. (function(){
  222. function test0(){
  223. //Code Snippet: NegativeArgumentBug.ecs (Blue15423)
  224. for (var _i in arguments[1073741823]) {
  225. };
  226. };
  227. test0();
  228. })();
  229. write("Test case #20");
  230. (function(){
  231. var shouldBailout = false;
  232. function test() {
  233. var requif = function () {};
  234. var XPCSafeJSObjectWrapper = function () { };
  235. for (var e = (Math.atan(arguments) / new XPCSafeJSObjectWrapper(''))in requif.x) {
  236. };
  237. };
  238. test();
  239. test();
  240. })();
  241. write("Test case #21");
  242. (function(){
  243. function foo(){
  244. foo.arguments[0] = 10;
  245. write(Math.max.apply(null, arguments));
  246. }
  247. foo(1);
  248. foo(1);
  249. })();
  250. write("Test case #22");
  251. (function(){
  252. function test0(){
  253. var obj0 = {};
  254. // Snippets:caller2.ecs
  255. function v26969(){
  256. v26969.caller.arguments.length = 2;
  257. v26969.caller.arguments[1] = 40;
  258. }
  259. function v26970(v26971, v26972){
  260. write(v26971);
  261. write(v26972);
  262. }
  263. function v26976(){
  264. v26969();
  265. v26970.apply(obj0, arguments);
  266. }
  267. v26976(10);
  268. v26976(20);
  269. v26976(30);
  270. };
  271. // generate profile
  272. test0();
  273. // run JITted code
  274. test0();
  275. // run code with bailouts enabled
  276. shouldBailout = true;
  277. test0();
  278. })()
  279. // Various ways of calling/loading function with used/unused result.
  280. write("Test case #23");
  281. var bailout = false;
  282. function test23()
  283. {
  284. var a = [1,2,3];
  285. if (bailout)
  286. {
  287. a = arguments;
  288. }
  289. return a[0];
  290. }
  291. write(test23([10,20,30]));
  292. bailout = true;
  293. write(test23([10,20,30]));
  294. write("Test case #24");
  295. bailout = false;
  296. function test24()
  297. {
  298. var a = arguments;
  299. if (bailout)
  300. {
  301. a = [1,2,3];
  302. }
  303. return a[0];
  304. }
  305. write(test24([10,20,30]));
  306. bailout = true;
  307. write(test24([10,20,30]));
  308. write("Test case #25");
  309. bailout = false;
  310. function test25()
  311. {
  312. var a;
  313. if (bailout)
  314. {
  315. a = arguments;
  316. }
  317. else
  318. {
  319. a = [1,2,3];
  320. }
  321. return a[0];
  322. }
  323. write(test25([10,20,30]));
  324. bailout = true;
  325. write(test25([10,20,30]));
  326. write("Test case #26");
  327. function test26()
  328. {
  329. var args = arguments;
  330. if (args[1])
  331. args = [3,args[0], args[1]];
  332. else
  333. args = [this, args[0]];
  334. return args[0];
  335. }
  336. write(test26(10,false));
  337. write(test26(10,20,30));
  338. write("Test case #27");
  339. (function ()
  340. {
  341. for(var x = arguments in "u6701")
  342. {
  343. }
  344. write(x);
  345. })();
  346. write("Test case #28");
  347. (function () {
  348. var XPCSafeJSObjectWrapper = function () {
  349. };
  350. (function () {
  351. if (!new XPCSafeJSObjectWrapper()) {
  352. var y, z = arguments, ksjxzy, w;
  353. throw -35184372088832;
  354. }
  355. write(z);
  356. }());
  357. })();