exceptions.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. //Note: some of the tests make use of host objects which are not available in jc mode.
  6. // Keeping the tests for easy pick and verify on IE
  7. // VB code to create a VB array
  8. //Dim cache
  9. //cache = 0
  10. //Function CreateVBArray()
  11. // Dim i, j, k
  12. // Dim a(2, 2)
  13. // k = 1
  14. // For i = 0 To 2
  15. // For j = 0 To 2
  16. // a(j, i) = k
  17. // k = k + 1
  18. // Next
  19. // Next
  20. // CreateVBArray = a
  21. //End Function
  22. function write(a) {
  23. if (this.WScript == undefined) {
  24. document.write(a);
  25. document.write("</br>");
  26. }
  27. else
  28. WScript.Echo(a)
  29. }
  30. // --- ReferenceError-----------
  31. try
  32. {
  33. Array.prototype.sort.call(document);
  34. write(" Array.prototype.sort.slice(document); ends without error;- expected ES5 ")
  35. }
  36. catch(o)
  37. {
  38. write(" Array.prototype.sort.call(document);; throws;; -expected: es3 TypeError ::: " + o)
  39. }
  40. try
  41. {
  42. Array.prototype.slice.call(document);
  43. write(" Array.prototype.shift.slice(document); ends without error;- expected ES5 ")
  44. }
  45. catch(o)
  46. {
  47. write(" Array.prototype.slice.call(document);; throws;; -expected: es3 TypeError ::: " + o)
  48. }
  49. try
  50. {
  51. Array.prototype.shift.call(document);
  52. write(" Array.prototype.shift.call(document); ends without error;- expected ES5 ")
  53. }
  54. catch(o)
  55. {
  56. write(" Array.prototype.shift.call(document);; throws;; -expected: es3 TypeError ::: " + o)
  57. }
  58. try
  59. {
  60. Array.prototype.reverse.call(document);
  61. write(" Array.prototype.reverse.call(document); ends without error;- expected ES5 ")
  62. }
  63. catch(o)
  64. {
  65. write(" Array.prototype.reverse.call(document);; throws;; -expected: es3 TypeError ::: " + o)
  66. }
  67. try
  68. {
  69. Array.prototype.push.call(document);
  70. write(" Array.prototype.push.call(document); ends without error;- expected ES5 ")
  71. }
  72. catch(o)
  73. {
  74. write(" Array.prototype.push.call(document);; throws;; -expected: es3 TypeError ::: " + o)
  75. }
  76. try
  77. {
  78. Array.prototype.pop.call(document);
  79. write(" Array.prototype.pop.call(document); ends without error;- expected ES5 ")
  80. }
  81. catch(o)
  82. {
  83. write(" Array.prototype.pop.call(document);; throws;; -expected: es3 TypeError ::: " + o)
  84. }
  85. try
  86. {
  87. Array.prototype.join.call(document);
  88. write(" Array.prototype.join.call(document); ends without error;- expected ES5 ")
  89. }
  90. catch(o)
  91. {
  92. write(" Array.prototype.join.call(document);; throws;; -expected: es3 TypeError ::: " + o)
  93. }
  94. try
  95. {
  96. Object.prototype.propertyIsEnumerable.call(document);
  97. write(" Object.prototype.propertyIsEnumerable.call(document); ends without error;- expected ES5 ")
  98. }
  99. catch(o)
  100. {
  101. write(" Object.prototype.propertyIsEnumerable.call(document);; throws;; -expected: es3 TypeError ::: " + o)
  102. }
  103. try
  104. {
  105. delete this;
  106. write(" delete this; ends without error; ")
  107. }
  108. catch(o)
  109. {
  110. write(" delete this; throws;; -expected: es3, es5 TypeError ::: " + o)
  111. }
  112. try
  113. {
  114. var xnew = new Object();
  115. var y = new xnew();
  116. write(" var xnew = new Object(); var y = new xnew(); ends without error; ")
  117. }
  118. catch(o)
  119. {
  120. write(" var xnew = new Object(); var y = new xnew(); throws;; -expected: es3, es5 TypeError ::: " + o)
  121. }
  122. try
  123. {
  124. var x = new Object();
  125. var y = x.ffm;
  126. write(" var x = new Object(); var y = x.ffm; ends without error; ")
  127. }
  128. catch(o)
  129. {
  130. write(" var x = new Object(); var y = x.ffm; throws;; -expected: es3, es5 TypeError ::: " + o)
  131. }
  132. try
  133. {
  134. var x = new Object();
  135. x.ff();
  136. write(" var x = new Object(); x.ff() ends without error; ")
  137. }
  138. catch(o)
  139. {
  140. write("var x = new Object(); x.ff() throws;; -expected: es3, es5 TypeError ::: " + o)
  141. }
  142. //inner call
  143. try
  144. {
  145. var x = function ff(){return "inner";}();
  146. //write("var x = function f(){return \"inner\";}(); done , no exception: x = " + x)
  147. ff();
  148. write("var x = function f(){return \"inner\";}() ends without error; ")
  149. }
  150. catch(o)
  151. {
  152. write("var x = function f(){return \"inner\";}(); -expected: es3, es5 R3eferenceError ::: " + o)
  153. }
  154. try
  155. {
  156. fg();
  157. write("call to undefined fg() ends without error; ")
  158. }
  159. catch(o)
  160. {
  161. write("call to undefined fg() throws; -expected: es3 - TypeError, es5-ReferenceError ::: " + o)
  162. }
  163. try
  164. {
  165. var ooj= new Object();
  166. ooj();
  167. }
  168. catch(o)
  169. {
  170. write(" call to an non function object ooj();;; -expected: es3, es5 TypeError ::: " + o)
  171. }
  172. try
  173. {
  174. var o_undef= undefined;
  175. o_undef();
  176. }
  177. catch(o)
  178. {
  179. write(" o_undef();;; -expected: es3, es5 TypeError ::: " + o)
  180. }
  181. try
  182. {
  183. var o_null= null;
  184. o_null();
  185. }
  186. catch(o)
  187. {
  188. write(" o_null();;; -expected: es3, es5 TypeError ::: " + o)
  189. }
  190. //calls on undefined , null, NaN
  191. try
  192. {
  193. undefined.toString();}
  194. catch(o)
  195. {
  196. write("undefined.toString(); -expected: es3, es5 TypeError ::: " + o)
  197. }
  198. try
  199. {
  200. null.anchor();
  201. }
  202. catch(o)
  203. {
  204. write(" null.anchor();; -expected: es3, es5 TypeError ::: " + o)
  205. }
  206. try
  207. {
  208. NaN.anchor();
  209. }
  210. catch(o)
  211. {
  212. write(" NaN.anchor();; -expected: es3, es5 TypeError ::: " + o)
  213. }
  214. try
  215. {
  216. true.anchor();
  217. }
  218. catch(o)
  219. {
  220. write(" true.anchor();; -expected: es3, es5 TypeError ::: " + o)
  221. }
  222. // --- RangeError-----------
  223. //15.4.2.2
  224. try
  225. {
  226. var x = new Array(12.4);
  227. write("new Array(12.4) - no exception: not expected es3, es5")
  228. }
  229. catch(o)
  230. {
  231. write("new Array(12.4) - RangeError exception: expected in es3 and es5::: " + o)
  232. }
  233. //15.4.5.1
  234. try
  235. {
  236. var x = new Array(); x.length = 12.5;
  237. write("new Array(12.4); x.length = 12.5; - no exception: es3-expected, ES5-not expected :")
  238. }
  239. catch(o)
  240. {
  241. write("new Array(12.4); x.length = 12.5; - RangeError exception: es5-expected, ES3-not expected ::: " + o)
  242. }
  243. //17.7.4.5
  244. try
  245. {
  246. var x = (123.45).toFixed(25);
  247. write("(123.45).toFixed(25); - no exception: not expected es3, es5")
  248. }
  249. catch(o)
  250. {
  251. write("(123.45).toFixed(25); - RangeError exception : expected es3, es5::: " + o)
  252. }
  253. //17.7.4.6
  254. try
  255. {
  256. var x = (123.45).toExponential(-25);
  257. write("(123.45).toExponential(-25); - no exception: not expected es3, es5")
  258. }
  259. catch(o)
  260. {
  261. write("(123.45).toExponential(-25); - RangeError exception : expected es3, es5 ::: " + o)
  262. }
  263. // --- EvalError-----------
  264. //15.11.6.1
  265. try
  266. {
  267. eval("blah.")
  268. write("eval(\"blah.\"); - no exception: not expected es3, es5")
  269. }
  270. catch(o)
  271. {
  272. write("eval(\"blah.\"); -expected es3-EvalError exception : expected es5-SyntaxException ::: " + o)
  273. }
  274. // --- SyntaxError-----------
  275. //15.3.2.1
  276. try
  277. {
  278. var f = new Function("a", "b", "return a+b.");
  279. write("f = new Function(\"a\", \"b\", \"return a+b.\"); - no exception: not expected es3, es5")
  280. }
  281. catch(o)
  282. {
  283. write("f = new Function(\"a\", \"b\", \"return a+b.\"); -expected es3 and es5-SyntaxError exception ::: " + o)
  284. }
  285. // num.tofixed deviation
  286. //15.7.4.5
  287. try
  288. {
  289. var num = 0.0009;
  290. var x = num.toFixed(3);
  291. write("var num = 0.0009;var x = num.toFixed(3); - no exception: not expected es3, es5 ::: value = " + x )
  292. }
  293. catch(o)
  294. {
  295. write("f = new Function(\"a\", \"b\", \"return a+b.\"); -expected es3 and es5-SyntaxError exception ::: " + o)
  296. }
  297. // regex
  298. // 15.10.2.5
  299. try
  300. {
  301. var re = new RegExp("a{5,4}");
  302. write("var re = new RegExp(\"a{5,4}\"); - no exception: not expected es3, es5 ::: value = ")
  303. }
  304. catch(o)
  305. {
  306. write("var re = \/a{5,4}\/; -expected: es3 -RegexExpError, es5-SyntaxError exception ::: " + o)
  307. }
  308. try
  309. {
  310. var re = new RegExp("[^\\0a]");
  311. write("var re = new RegExp(\"\\\\0a\"); - no exception: not expected es3, es5 ::: value = ")
  312. }
  313. catch(o)
  314. {
  315. write("var re = new RegExp(\"\\0a\"); -expected: es3 -RegexExpError, es5-SyntaxError exception ::: " + o)
  316. }