deferredParsing.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 ()
  6. {
  7. function foo() { writeLine("easy, cancel defer"); }
  8. foo();
  9. })();
  10. (function ()
  11. {
  12. function foo() { writeLine("easy"); }
  13. foo();
  14. }).call();
  15. (function ()
  16. {
  17. var goo = function (str) { writeLine(str); };
  18. function foo() { goo("medium"); }
  19. (function () { foo(); }).call();
  20. }).call();
  21. (function ()
  22. {
  23. writeLine((function ()
  24. {
  25. var goo = function () { return "hard"; };
  26. function foo() { return goo(); }
  27. return { callFoo: function () { return foo(); } };
  28. }).call().callFoo());
  29. }).apply(this);
  30. var x = { data: "OK" };
  31. with (x)
  32. {
  33. (function outer()
  34. {
  35. writeLine("outer function: " + data);
  36. (function inner()
  37. {
  38. writeLine("inner function: " + data);
  39. })();
  40. })();
  41. }
  42. var err = 'global';
  43. try {
  44. var f1 = function() { writeLine(err) };
  45. throw 'catch';
  46. }
  47. catch(err) {
  48. var f2 = function() { writeLine(err) };
  49. try {
  50. throw 'catch2';
  51. }
  52. catch(err) {
  53. var f3 = function() { writeLine(err) };
  54. }
  55. }
  56. f1();
  57. f2();
  58. f3();
  59. var str = '' +
  60. 'x = { get func() { return 1; } };' +
  61. 'x = { get "func"() { return 1; } };' +
  62. 'x = { get 57() { return 1;} };' +
  63. 'x = { get 1e5() { return 1;} };' +
  64. 'x = { get func() { return 1;} };';
  65. (function() {
  66. // The getters will only be declared in IE9 mode, since
  67. // in compat mode the nested eval will pick up the local (empty) string.
  68. var str = '';
  69. (0,eval)('eval(str)');
  70. })();
  71. (function (param) {
  72. return function() {
  73. writeLine(param);
  74. };
  75. })('hi there')();
  76. (function()
  77. {
  78. // Test named function expression with deferred child where the func name is not visible.
  79. new function x(x)
  80. {
  81. function __tmp__()
  82. {
  83. }
  84. eval("\r\n writeLine(x)")
  85. }
  86. })();
  87. var newfunction = new Function('writeLine("puppies!");');
  88. newfunction();
  89. // Test function with duplicate parameters
  90. function dupes(a,b,c,a) {return a}
  91. WScript.Echo(dupes(0));
  92. // Helpers
  93. function writeLine(str)
  94. {
  95. WScript.Echo("" + str);
  96. }