callmissingtgt.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 echo = WScript.Echo;
  6. var globalObject = this;
  7. var o = {};
  8. function foo() {
  9. echo(" ", "Evaluate arg list");
  10. }
  11. function test(title, f) {
  12. echo(title);
  13. try {
  14. f();
  15. } catch (e) {
  16. echo(" ", e.name);
  17. }
  18. echo();
  19. }
  20. test("Global member missing", function () {
  21. bar(foo());
  22. });
  23. test("Global member undefined", function () {
  24. bar = undefined;
  25. bar(foo());
  26. });
  27. test("Global member null", function () {
  28. bar = null;
  29. bar(foo());
  30. });
  31. test("Global member is not callable", function () {
  32. bar = 23;
  33. bar(foo());
  34. });
  35. if (Object.defineProperties) {
  36. test("Global member getter returns undefined", function () {
  37. Object.defineProperty(this, "bar", {
  38. get: function () { },
  39. configurable: true
  40. });
  41. bar(foo());
  42. });
  43. test("Global member getter returns null", function () {
  44. Object.defineProperty(this, "bar", {
  45. get: function () { return null; },
  46. configurable: true
  47. });
  48. bar(foo());
  49. });
  50. }
  51. echo();
  52. test("Global member missing via property reference via dot syntax", function () {
  53. globalObject.baz(foo());
  54. });
  55. test("Global member undefined via property reference via dot syntax", function () {
  56. globalObject.baz = undefined;
  57. globalObject.baz(foo());
  58. });
  59. test("Global member null via property reference via dot syntax", function () {
  60. globalObject.baz = null;
  61. globalObject.baz(foo());
  62. });
  63. test("Global member is not callable via property reference via dot syntax", function () {
  64. globalObject.baz = 23;
  65. globalObject.baz(foo());
  66. });
  67. if (Object.defineProperties) {
  68. test("Global member getter returns undefined via property reference via dot syntax", function () {
  69. Object.defineProperty(this, "baz", {
  70. get: function () { },
  71. configurable: true
  72. });
  73. globalObject.baz(foo());
  74. });
  75. test("Global member getter returns null via property reference via dot syntax", function () {
  76. Object.defineProperty(this, "baz", {
  77. get: function () { return null; },
  78. configurable: true
  79. });
  80. globalObject.baz(foo());
  81. });
  82. }
  83. echo();
  84. function elementname() { return "buz"; }
  85. test("Global member missing via property reference via element access syntax", function () {
  86. globalObject[elementname()](foo());
  87. });
  88. test("Global member undefined via property reference via element access syntax", function () {
  89. globalObject[elementname()] = undefined;
  90. globalObject[elementname()](foo());
  91. });
  92. test("Global member null via property reference via element access syntax", function () {
  93. globalObject[elementname()] = null;
  94. globalObject[elementname()](foo());
  95. });
  96. test("Global member is not callable via property reference via element access syntax", function () {
  97. globalObject[elementname()] = 23;
  98. globalObject[elementname()](foo());
  99. });
  100. if (Object.defineProperties) {
  101. test("Global member getter returns undefined via property reference via element access syntax", function () {
  102. Object.defineProperty(this, elementname(), {
  103. get: function () { },
  104. configurable: true
  105. });
  106. globalObject[elementname()](foo());
  107. });
  108. test("Global member getter returns null via property reference via element access syntax", function () {
  109. Object.defineProperty(this, elementname(), {
  110. get: function () { return null; },
  111. configurable: true
  112. });
  113. globalObject[elementname()](foo());
  114. });
  115. }
  116. echo();
  117. test("Object member missing", function () {
  118. o.bar(foo());
  119. });
  120. test("Object member undefined", function () {
  121. o.bar = undefined;
  122. o.bar(foo());
  123. });
  124. test("Object member null", function () {
  125. o.bar = null;
  126. o.bar(foo());
  127. });
  128. test("Object member is not callable", function () {
  129. o.bar = 23;
  130. o.bar(foo());
  131. });
  132. if (Object.defineProperties) {
  133. test("Object member getter returns undefined", function () {
  134. Object.defineProperty(o, "bar", {
  135. get: function () { },
  136. configurable: true
  137. });
  138. o.bar(foo());
  139. });
  140. test("Object member getter returns null", function () {
  141. Object.defineProperty(o, "bar", {
  142. get: function () { return null; },
  143. configurable: true
  144. });
  145. o.bar(foo());
  146. });
  147. }
  148. echo();
  149. test("Object element missing", function () {
  150. o[3](foo());
  151. });
  152. test("Object element undefined", function () {
  153. o[3] = undefined;
  154. o[3](foo());
  155. });
  156. test("Object element null", function () {
  157. o[3] = null;
  158. o[3](foo());
  159. });
  160. test("Object element is not callable", function () {
  161. o[3] = 23;
  162. o[3](foo());
  163. });
  164. if (Object.defineProperties) {
  165. test("Object element getter returns undefined", function () {
  166. Object.defineProperty(o, 3, {
  167. get: function () { },
  168. configurable: true
  169. });
  170. o[3](foo());
  171. });
  172. test("Object element getter returns null", function () {
  173. Object.defineProperty(o, 3, {
  174. get: function () { return null; },
  175. configurable: true
  176. });
  177. o[3](foo());
  178. });
  179. }