applyArgs.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. var res = []
  6. function test1()
  7. {
  8. [].push.apply(this, arguments);
  9. res.push(1);
  10. }
  11. test1();
  12. function test2()
  13. {
  14. ({}).toString.apply(this, arguments);
  15. res.push(2);
  16. }
  17. test2();
  18. var count3 = 0;
  19. function test3()
  20. {
  21. var args = arguments;
  22. function test3_inner() {
  23. (count3 == 1 ? args : arguments).callee.apply(this, arguments);
  24. }
  25. if (++count3 == 1)
  26. {
  27. return test3_inner();
  28. }
  29. res.push(3);
  30. }
  31. test3();
  32. function test4()
  33. {
  34. return function() {
  35. try {
  36. throw 4;
  37. } catch(ex) {
  38. res.push(4);
  39. var f = arguments[0];
  40. }
  41. f.apply(this, arguments);
  42. }
  43. }
  44. test4()(function(){ res.push(5); });
  45. for (var i = 0; i < 5; ++i) {
  46. if (res[i] !== i + 1) {
  47. throw "fail";
  48. }
  49. }
  50. print("pass");