19.function_sm.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 PrintDescriptor(name, propDesc) {
  7. write(name + ":configurable : " + propDesc.configurable);
  8. write(name + ":enumerable : " + propDesc.enumerable);
  9. write(name + ":writable : " + propDesc.writable);
  10. write(name + ":getter : " + propDesc.get);
  11. write(name + ":setter : " + propDesc.set);
  12. write(name + ":value : " + propDesc.value);
  13. }
  14. function exceptToString(ee) {
  15. if (ee instanceof TypeError) return "TypeError";
  16. if (ee instanceof ReferenceError) return "ReferenceError";
  17. if (ee instanceof EvalError) return "EvalError";
  18. if (ee instanceof SyntaxError) return "SyntaxError";
  19. return "Unknown Error";
  20. }
  21. (function Test1() {
  22. "use strict";
  23. var str = "function.caller get";
  24. try {
  25. Test1.caller;
  26. } catch (e) {
  27. write("Exception: " + str + " " + exceptToString(e));
  28. return;
  29. }
  30. write("Return: " + str);
  31. })();
  32. (function Test2() {
  33. "use strict";
  34. var str = "function.caller set";
  35. try {
  36. Test2.caller = 10;
  37. } catch (e) {
  38. write("Exception: " + str + " " + exceptToString(e));
  39. return;
  40. }
  41. write("Return: " + str);
  42. })();
  43. (function Test3() {
  44. "use strict";
  45. var str = "function.arguments get";
  46. try {
  47. Test3.arguments;
  48. } catch (e) {
  49. write("Exception: " + str + " " + exceptToString(e));
  50. return;
  51. }
  52. write("Return: " + str);
  53. })();
  54. (function Test4() {
  55. "use strict";
  56. var str = "function.arguments set";
  57. try {
  58. Test4.arguments = 10;
  59. } catch (e) {
  60. write("Exception: " + str + " " + exceptToString(e));
  61. return;
  62. }
  63. write("Return: " + str);
  64. })();
  65. (function Test5() {
  66. "use strict";
  67. var str = "function.arguments and function.caller descriptors are undefined";
  68. // Properties on the function object.
  69. var callerDescriptor = Object.getOwnPropertyDescriptor(function() {}, 'caller');
  70. var argumentsDescriptor = Object.getOwnPropertyDescriptor(function() {}, 'arguments');
  71. write("Return: " +
  72. (callerDescriptor === undefined) + " " +
  73. (argumentsDescriptor === undefined) + ": " +
  74. str);
  75. })();
  76. (function Test5() {
  77. "use strict";
  78. var str = "arguments.caller is not defined and arguments.callee getter and setter are equal/strictEqual to each other";
  79. // Properties on the arguments object.
  80. var argumentsCallerDescriptor = Object.getOwnPropertyDescriptor(arguments, 'caller');
  81. var argumentsCalleeGet = Object.getOwnPropertyDescriptor(arguments, 'callee').get;
  82. var argumentsCalleeSet = Object.getOwnPropertyDescriptor(arguments, 'callee').set;
  83. write("Return: " +
  84. (argumentsCallerDescriptor === undefined).toString() + " " +
  85. (argumentsCalleeGet === argumentsCalleeSet).toString() + ": " +
  86. str);
  87. })();
  88. (function Test6() {
  89. var str = "function.caller's value is a strict mode function";
  90. function foo() {
  91. "use strict";
  92. return goo();
  93. }
  94. function goo() {
  95. return goo.caller; // Expected: TypeError, as the caller (foo) is a strict mode function -- ES5.15.3.5.4.
  96. }
  97. try {
  98. foo();
  99. } catch (e) {
  100. write("Exception: " + str + " " + exceptToString(e));
  101. return;
  102. }
  103. write("Return: " + str);
  104. })();
  105. /* TODO
  106. (function Test5() {
  107. "use strict";
  108. var str = "function.caller get";
  109. try {
  110. PrintDescriptor("Test5.caller", Object.getOwnPropertyDescriptor(Test5, "caller"));
  111. } catch (e) {
  112. write("Exception: " + str + " " + exceptToString(e));
  113. return;
  114. }
  115. write("Return: " + str);
  116. })();
  117. (function Test6() {
  118. "use strict";
  119. var str = "function.arguments get";
  120. try {
  121. PrintDescriptor("Test6.arguments", Object.getOwnPropertyDescriptor(Test6, "arguments"));
  122. } catch (e) {
  123. write("Exception: " + str + " " + exceptToString(e));
  124. return;
  125. }
  126. write("Return: " + str);
  127. })();
  128. */