augmentPrimitive.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. // FIXME:
  6. // The diagnostic produced by getters is correct, but the setters
  7. // issue assertion failures and other sorts of odd behavior.
  8. // This problem should be fixed, the commented-out calls to obj[...] = {}
  9. // should be restored, and this test should be rebaselined.
  10. var echo = WScript.Echo;
  11. var diag = function() {
  12. echo(" Type: " + (typeof this));
  13. echo(" Is Object: " + (this instanceof Object));
  14. echo(" Is Number: " + (this instanceof Number));
  15. echo(" Is Boolean: " + (this instanceof Boolean));
  16. echo(" Is String: " + (this instanceof String));
  17. }
  18. var diag_strict = function() {
  19. "use strict";
  20. echo(" Type: " + (typeof this));
  21. echo(" Is Object: " + (this instanceof Object));
  22. echo(" Is Number: " + (this instanceof Number));
  23. echo(" Is Boolean: " + (this instanceof Boolean));
  24. echo(" Is String: " + (this instanceof String));
  25. }
  26. var getDiag = function() {
  27. echo("Executing getter:");
  28. diag.apply(this, arguments);
  29. return true;
  30. }
  31. var getDiag_strict = function() {
  32. "use strict";
  33. echo("Executing getter:");
  34. diag_strict.apply(this, arguments);
  35. return true;
  36. }
  37. var setDiag = function(x) {
  38. echo("Executing setter:");
  39. diag.apply(this, arguments);
  40. }
  41. var setDiag_strict = function(x) {
  42. "use strict";
  43. echo("Executing setter:");
  44. diag_strict.apply(this, arguments);
  45. }
  46. var funcDiag = function(x) {
  47. echo("Executing function:");
  48. diag.apply(this, arguments);
  49. return function () {
  50. echo(" ... returning from function");
  51. }
  52. }
  53. var funcDiag_strict = function(x) {
  54. "use strict";
  55. echo("Executing function:");
  56. diag_strict.apply(this, arguments);
  57. return function () {
  58. echo(" ... returning from function");
  59. }
  60. }
  61. Object.defineProperties(
  62. Number.prototype, {
  63. "foo": {
  64. get: getDiag,
  65. //set: setDiag
  66. },
  67. "foo_strict": {
  68. get: getDiag_strict,
  69. //set: setDiag_strict
  70. },
  71. "bar": {
  72. get: funcDiag
  73. },
  74. "bar_strict": {
  75. get: funcDiag_strict
  76. },
  77. "42": {
  78. get: getDiag,
  79. //set: setDiag
  80. },
  81. "142": {
  82. // 142 means "42_strict"
  83. get: getDiag_strict,
  84. //set: setDiag_strict
  85. },
  86. "43": {
  87. get: funcDiag
  88. },
  89. "143": {
  90. // 143 means "43_strict"
  91. get: funcDiag_strict
  92. },
  93. "-42": {
  94. get: getDiag,
  95. //set: setDiag
  96. },
  97. "-142": {
  98. // -142 means "-42_strict"
  99. get: getDiag_strict,
  100. //set: setDiag_strict
  101. },
  102. "-43": {
  103. get: funcDiag
  104. },
  105. "-143": {
  106. // -143 means "-43_strict"
  107. get: funcDiag_strict
  108. }
  109. });
  110. Object.defineProperties(
  111. Boolean.prototype, {
  112. "foo": {
  113. get: getDiag,
  114. //set: setDiag
  115. },
  116. "foo_strict": {
  117. get: getDiag_strict,
  118. //set: setDiag_strict
  119. },
  120. "bar": {
  121. get: funcDiag
  122. },
  123. "bar_strict": {
  124. get: funcDiag_strict
  125. },
  126. "42": {
  127. get: getDiag,
  128. //set: setDiag
  129. },
  130. "142": {
  131. // 142 means "42_strict"
  132. get: getDiag_strict,
  133. //set: setDiag_strict
  134. },
  135. "43": {
  136. get: funcDiag
  137. },
  138. "143": {
  139. // 143 means "43_strict"
  140. get: funcDiag_strict
  141. },
  142. "-42": {
  143. get: getDiag,
  144. //set: setDiag
  145. },
  146. "-142": {
  147. // -142 means "-42_strict"
  148. get: getDiag_strict,
  149. //set: setDiag_strict
  150. },
  151. "-43": {
  152. get: funcDiag
  153. },
  154. "-143": {
  155. // -143 means "-43_strict"
  156. get: funcDiag_strict
  157. }
  158. });
  159. Object.defineProperties(
  160. String.prototype, {
  161. "foo": {
  162. get: getDiag,
  163. //set: setDiag
  164. },
  165. "foo_strict": {
  166. get: getDiag_strict,
  167. //set: setDiag_strict
  168. },
  169. "bar": {
  170. get: funcDiag
  171. },
  172. "bar_strict": {
  173. get: funcDiag_strict
  174. },
  175. "42": {
  176. get: getDiag,
  177. //set: setDiag
  178. },
  179. "142": {
  180. // 142 means "42_strict"
  181. get: getDiag_strict,
  182. //set: setDiag_strict
  183. },
  184. "43": {
  185. get: funcDiag
  186. },
  187. "143": {
  188. // 143 means "43_strict"
  189. get: funcDiag_strict
  190. },
  191. "-42": {
  192. get: getDiag,
  193. //set: setDiag
  194. },
  195. "-142": {
  196. // -142 means "-42_strict"
  197. get: getDiag_strict,
  198. //set: setDiag_strict
  199. },
  200. "-43": {
  201. get: funcDiag
  202. },
  203. "-143": {
  204. // -143 means "-43_strict"
  205. get: funcDiag_strict
  206. }
  207. });
  208. var runTests = function(obj, objKind) {
  209. var f = "f";
  210. var b = "b";
  211. echo("** Testing " + objKind + ", property 'foo' (value) **");
  212. obj.foo;
  213. obj[f + "oo"];
  214. typeof obj.foo;
  215. obj.foo instanceof Object;
  216. // obj.foo = {};
  217. echo("");
  218. echo("** Testing " + objKind + ", property 'bar' (function) **");
  219. obj.bar();
  220. obj[b + "ar"]();
  221. typeof obj.bar();
  222. obj.bar() instanceof Object;
  223. echo("");
  224. echo("** Testing " + objKind + ", property 42 (value) **");
  225. obj[42];
  226. obj[41 + 1];
  227. typeof obj[42];
  228. obj[42] instanceof Object;
  229. // obj[42] = {};
  230. echo("");
  231. echo("** Testing " + objKind + ", property 43 (function) **");
  232. obj[43]();
  233. obj[45 - 2]();
  234. typeof obj[43]();
  235. obj[43]() instanceof Object;
  236. echo("");
  237. echo("** Testing " + objKind + ", property -42 (value) **");
  238. obj[-42];
  239. obj[-41 - 1];
  240. typeof obj[-42];
  241. obj[-42] instanceof Object;
  242. // obj[-42] = {};
  243. echo("");
  244. echo("** Testing " + objKind + ", property -43 (function) **");
  245. obj[-43]();
  246. obj[-45 + 2]();
  247. typeof obj[-43]();
  248. obj[-43]() instanceof Object;
  249. echo("");
  250. }
  251. var runTests_strict = function(obj, objKind) {
  252. var f = "f";
  253. var b = "b";
  254. echo("** Testing " + objKind + ", property 'foo_strict' (value, strict mode) **");
  255. obj.foo_strict;
  256. obj[f + "oo_strict"];
  257. typeof obj.foo_strict;
  258. obj.foo_strict instanceof Object;
  259. // obj.foo_strict = {};
  260. echo("");
  261. echo("** Testing " + objKind + ", property 'bar_strict' (function, strict mode) **");
  262. obj.bar_strict();
  263. obj[b + "ar_strict"]();
  264. typeof obj.bar_strict();
  265. obj.bar_strict() instanceof Object;
  266. echo("");
  267. echo("** Testing " + objKind + ", property 142 (value, strict mode) **");
  268. obj[142];
  269. obj[141 + 1];
  270. typeof obj[142];
  271. obj[142] instanceof Object;
  272. // obj[142] = {};
  273. echo("");
  274. echo("** Testing " + objKind + ", property 143 (function, strict mode) **");
  275. obj[143]();
  276. obj[145 - 2]();
  277. typeof obj[143]();
  278. obj[143]() instanceof Object;
  279. echo("");
  280. echo("** Testing " + objKind + ", property -142 (value, strict mode) **");
  281. obj[-142];
  282. obj[-141 - 1];
  283. typeof obj[-142];
  284. obj[-142] instanceof Object;
  285. // obj[-142] = {};
  286. echo("");
  287. echo("** Testing " + objKind + ", property -143 (function, strict mode) **");
  288. obj[-143]();
  289. obj[-145 + 2]();
  290. typeof obj[-143]();
  291. obj[-143]() instanceof Object;
  292. echo("");
  293. }
  294. var i = 3;
  295. runTests(i, "int");
  296. runTests_strict(i, "int");
  297. var l = (1 << 30) + 1;
  298. runTests(l, "large int");
  299. runTests_strict(l, "large int");
  300. var d = 3.14;
  301. runTests(d, "float");
  302. runTests_strict(d, "float");
  303. var b = true;
  304. runTests(b, "bool");
  305. runTests_strict(b, "bool");
  306. var s = "Hello";
  307. runTests(s, "string");
  308. runTests_strict(s, "string");