applyArgs.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 test1()
  7. {
  8. [].push.apply(this, arguments);
  9. write("passed");
  10. }
  11. test1();
  12. function test2()
  13. {
  14. ({}).toString.apply(this, arguments);
  15. write("passed");
  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. write("passed");
  30. }
  31. test3();
  32. function test4()
  33. {
  34. return function() {
  35. try {
  36. throw 'zap';
  37. } catch(ex) {
  38. WScript.Echo(ex);
  39. var f = arguments[0];
  40. }
  41. f.apply(this, arguments);
  42. }
  43. }
  44. test4()(function(){ WScript.Echo('mama'); });