PageRenderTime 51ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/external/webkit/Source/JavaScriptCore/tests/mozilla/js1_5/Regress/regress-104077.js

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk
JavaScript | 635 lines | 484 code | 84 blank | 67 comment | 24 complexity | 83114ed3768689e566392bab117ddb27 MD5 | raw file
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Netscape Public License
  5. * Version 1.1 (the "License"); you may not use this file except in
  6. * compliance with the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/NPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is JavaScript Engine testing utilities.
  15. *
  16. * The Initial Developer of the Original Code is Netscape Communications Corp.
  17. * Portions created by the Initial Developer are Copyright (C) 2001
  18. * the Initial Developer. All Rights Reserved.
  19. *
  20. * Contributor(s): chwu@nortelnetworks.com, timeless@mac.com,
  21. * brendan@mozilla.org, pschwartau@netscape.com
  22. *
  23. * Alternatively, the contents of this file may be used under the terms of
  24. * either the GNU General Public License Version 2 or later (the "GPL"), or
  25. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26. * in which case the provisions of the GPL or the LGPL are applicable instead
  27. * of those above. If you wish to allow use of your version of this file only
  28. * under the terms of either the GPL or the LGPL, and not to allow others to
  29. * use your version of this file under the terms of the NPL, indicate your
  30. * decision by deleting the provisions above and replace them with the notice
  31. * and other provisions required by the GPL or the LGPL. If you do not delete
  32. * the provisions above, a recipient may use your version of this file under
  33. * the terms of any one of the NPL, the GPL or the LGPL.
  34. *
  35. * ***** END LICENSE BLOCK *****
  36. *
  37. *
  38. * Date: 10 October 2001
  39. * SUMMARY: Regression test for Bugzilla bug 104077
  40. * See http://bugzilla.mozilla.org/show_bug.cgi?id=104077
  41. * "JS crash: with/finally/return"
  42. *
  43. * Also http://bugzilla.mozilla.org/show_bug.cgi?id=120571
  44. * "JS crash: try/catch/continue."
  45. *
  46. * SpiderMonkey crashed on this code - it shouldn't.
  47. *
  48. * NOTE: the finally-blocks below should execute even if their try-blocks
  49. * have return or throw statements in them:
  50. *
  51. * ------- Additional Comment #76 From Mike Shaver 2001-12-07 01:21 -------
  52. * finally trumps return, and all other control-flow constructs that cause
  53. * program execution to jump out of the try block: throw, break, etc. Once you
  54. * enter a try block, you will execute the finally block after leaving the try,
  55. * regardless of what happens to make you leave the try.
  56. *
  57. */
  58. //-----------------------------------------------------------------------------
  59. var UBound = 0;
  60. var bug = 104077;
  61. var summary = "Just testing that we don't crash on with/finally/return -";
  62. var status = '';
  63. var statusitems = [];
  64. var actual = '';
  65. var actualvalues = [];
  66. var expect= '';
  67. var expectedvalues = [];
  68. function addValues(obj)
  69. {
  70. var sum;
  71. with (obj)
  72. {
  73. try
  74. {
  75. sum = arg1 + arg2;
  76. }
  77. finally
  78. {
  79. return sum;
  80. }
  81. }
  82. }
  83. status = inSection(1);
  84. var obj = new Object();
  85. obj.arg1 = 1;
  86. obj.arg2 = 2;
  87. actual = addValues(obj);
  88. expect = 3;
  89. captureThis();
  90. function tryThis()
  91. {
  92. var sum = 4 ;
  93. var i = 0;
  94. while (sum < 10)
  95. {
  96. try
  97. {
  98. sum += 1;
  99. i += 1;
  100. }
  101. finally
  102. {
  103. print("In finally case of tryThis() function");
  104. }
  105. }
  106. return i;
  107. }
  108. status = inSection(2);
  109. actual = tryThis();
  110. expect = 6;
  111. captureThis();
  112. function myTest(x)
  113. {
  114. var obj = new Object();
  115. var msg;
  116. with (obj)
  117. {
  118. msg = (x != null) ? "NO" : "YES";
  119. print("Is the provided argument to myTest() null? : " + msg);
  120. try
  121. {
  122. throw "ZZZ";
  123. }
  124. catch(e)
  125. {
  126. print("Caught thrown exception = " + e);
  127. }
  128. }
  129. return 1;
  130. }
  131. status = inSection(3);
  132. actual = myTest(null);
  133. expect = 1;
  134. captureThis();
  135. function addValues_2(obj)
  136. {
  137. var sum = 0;
  138. with (obj)
  139. {
  140. try
  141. {
  142. sum = arg1 + arg2;
  143. with (arg3)
  144. {
  145. while (sum < 10)
  146. {
  147. try
  148. {
  149. if (sum > 5)
  150. return sum;
  151. sum += 1;
  152. }
  153. catch(e)
  154. {
  155. print('Caught an exception in addValues_2() function: ' + e);
  156. }
  157. }
  158. }
  159. }
  160. finally
  161. {
  162. return sum;
  163. }
  164. }
  165. }
  166. status = inSection(4);
  167. obj = new Object();
  168. obj.arg1 = 1;
  169. obj.arg2 = 2;
  170. obj.arg3 = new Object();
  171. obj.arg3.a = 10;
  172. obj.arg3.b = 20;
  173. actual = addValues_2(obj);
  174. expect = 6;
  175. captureThis();
  176. status = inSection(5);
  177. try
  178. {
  179. throw new A();
  180. }
  181. catch(e)
  182. {
  183. }
  184. finally
  185. {
  186. try
  187. {
  188. throw new A();
  189. }
  190. catch(e)
  191. {
  192. }
  193. finally
  194. {
  195. actual = 'a';
  196. }
  197. actual = 'b';
  198. }
  199. expect = 'b';
  200. captureThis();
  201. function testfunc(mode)
  202. {
  203. var obj = new Object();
  204. with (obj)
  205. {
  206. var num = 100;
  207. var str = "abc" ;
  208. if (str == null)
  209. {
  210. try
  211. {
  212. throw "authentication.0";
  213. }
  214. catch(e)
  215. {
  216. }
  217. finally
  218. {
  219. }
  220. return num;
  221. }
  222. else
  223. {
  224. try
  225. {
  226. if (mode == 0)
  227. throw "authentication.0";
  228. else
  229. mytest();
  230. }
  231. catch(e)
  232. {
  233. }
  234. finally
  235. {
  236. }
  237. return num;
  238. }
  239. }
  240. }
  241. status = inSection(6);
  242. actual = testfunc(0);
  243. expect = 100;
  244. captureThis();
  245. status = inSection(7);
  246. actual = testfunc();
  247. expect = 100;
  248. captureThis();
  249. function entry_menu()
  250. {
  251. var document = new Object();
  252. var dialog = new Object();
  253. var num = 100;
  254. with (document)
  255. {
  256. with (dialog)
  257. {
  258. try
  259. {
  260. while (true)
  261. {
  262. return num;
  263. }
  264. }
  265. finally
  266. {
  267. }
  268. }
  269. }
  270. }
  271. status = inSection(8);
  272. actual = entry_menu();
  273. expect = 100;
  274. captureThis();
  275. function addValues_3(obj)
  276. {
  277. var sum = 0;
  278. with (obj)
  279. {
  280. try
  281. {
  282. sum = arg1 + arg2;
  283. with (arg3)
  284. {
  285. while (sum < 10)
  286. {
  287. try
  288. {
  289. if (sum > 5)
  290. return sum;
  291. sum += 1;
  292. }
  293. catch (e)
  294. {
  295. sum += 1;
  296. print(e);
  297. }
  298. }
  299. }
  300. }
  301. finally
  302. {
  303. try
  304. {
  305. sum +=1;
  306. print("In finally block of addValues_3() function: sum = " + sum);
  307. }
  308. catch (e if e == 42)
  309. {
  310. sum +=1;
  311. print('In finally catch block of addValues_3() function: sum = ' + sum + ', e = ' + e);
  312. }
  313. finally
  314. {
  315. sum +=1;
  316. print("In finally finally block of addValues_3() function: sum = " + sum);
  317. return sum;
  318. }
  319. }
  320. }
  321. }
  322. status = inSection(9);
  323. obj = new Object();
  324. obj.arg1 = 1;
  325. obj.arg2 = 2;
  326. obj.arg3 = new Object();
  327. obj.arg3.a = 10;
  328. obj.arg3.b = 20;
  329. actual = addValues_3(obj);
  330. expect = 8;
  331. captureThis();
  332. function addValues_4(obj)
  333. {
  334. var sum = 0;
  335. with (obj)
  336. {
  337. try
  338. {
  339. sum = arg1 + arg2;
  340. with (arg3)
  341. {
  342. while (sum < 10)
  343. {
  344. try
  345. {
  346. if (sum > 5)
  347. return sum;
  348. sum += 1;
  349. }
  350. catch (e)
  351. {
  352. sum += 1;
  353. print(e);
  354. }
  355. }
  356. }
  357. }
  358. finally
  359. {
  360. try
  361. {
  362. sum += 1;
  363. print("In finally block of addValues_4() function: sum = " + sum);
  364. }
  365. catch (e if e == 42)
  366. {
  367. sum += 1;
  368. print("In 1st finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
  369. }
  370. catch (e if e == 43)
  371. {
  372. sum += 1;
  373. print("In 2nd finally catch block of addValues_4() function: sum = " + sum + ", e = " + e);
  374. }
  375. finally
  376. {
  377. sum += 1;
  378. print("In finally finally block of addValues_4() function: sum = " + sum);
  379. return sum;
  380. }
  381. }
  382. }
  383. }
  384. status = inSection(10);
  385. obj = new Object();
  386. obj.arg1 = 1;
  387. obj.arg2 = 2;
  388. obj.arg3 = new Object();
  389. obj.arg3.a = 10;
  390. obj.arg3.b = 20;
  391. actual = addValues_4(obj);
  392. expect = 8;
  393. captureThis();
  394. function addValues_5(obj)
  395. {
  396. var sum = 0;
  397. with (obj)
  398. {
  399. try
  400. {
  401. sum = arg1 + arg2;
  402. with (arg3)
  403. {
  404. while (sum < 10)
  405. {
  406. try
  407. {
  408. if (sum > 5)
  409. return sum;
  410. sum += 1;
  411. }
  412. catch (e)
  413. {
  414. sum += 1;
  415. print(e);
  416. }
  417. }
  418. }
  419. }
  420. finally
  421. {
  422. try
  423. {
  424. sum += 1;
  425. print("In finally block of addValues_5() function: sum = " + sum);
  426. }
  427. catch (e)
  428. {
  429. sum += 1;
  430. print("In finally catch block of addValues_5() function: sum = " + sum + ", e = " + e);
  431. }
  432. finally
  433. {
  434. sum += 1;
  435. print("In finally finally block of addValues_5() function: sum = " + sum);
  436. return sum;
  437. }
  438. }
  439. }
  440. }
  441. status = inSection(11);
  442. obj = new Object();
  443. obj.arg1 = 1;
  444. obj.arg2 = 2;
  445. obj.arg3 = new Object();
  446. obj.arg3.a = 10;
  447. obj.arg3.b = 20;
  448. actual = addValues_5(obj);
  449. expect = 8;
  450. captureThis();
  451. function testObj(obj)
  452. {
  453. var x = 42;
  454. try
  455. {
  456. with (obj)
  457. {
  458. if (obj.p)
  459. throw obj.p;
  460. x = obj.q;
  461. }
  462. }
  463. finally
  464. {
  465. print("in finally block of testObj() function");
  466. return 999;
  467. }
  468. }
  469. status = inSection(12);
  470. obj = {p:43};
  471. actual = testObj(obj);
  472. expect = 999;
  473. captureThis();
  474. /*
  475. * Next two cases are from http://bugzilla.mozilla.org/show_bug.cgi?id=120571
  476. */
  477. function a120571()
  478. {
  479. while(0)
  480. {
  481. try
  482. {
  483. }
  484. catch(e)
  485. {
  486. continue;
  487. }
  488. }
  489. }
  490. // this caused a crash! Test to see that it doesn't now.
  491. print(a120571);
  492. // Now test that we have a non-null value for a120571.toString()
  493. status = inSection(13);
  494. try
  495. {
  496. actual = a120571.toString().match(/continue/)[0];
  497. }
  498. catch(e)
  499. {
  500. actual = 'FAILED! Did not find "continue" in function body';
  501. }
  502. expect = 'continue';
  503. captureThis();
  504. function b()
  505. {
  506. for(;;)
  507. {
  508. try
  509. {
  510. }
  511. catch(e)
  512. {
  513. continue;
  514. }
  515. }
  516. }
  517. // this caused a crash!!! Test to see that it doesn't now.
  518. print(b);
  519. // Now test that we have a non-null value for b.toString()
  520. status = inSection(14);
  521. try
  522. {
  523. actual = b.toString().match(/continue/)[0];
  524. }
  525. catch(e)
  526. {
  527. actual = 'FAILED! Did not find "continue" in function body';
  528. }
  529. expect = 'continue';
  530. captureThis();
  531. //-----------------------------------------------------------------------------
  532. test();
  533. //-----------------------------------------------------------------------------
  534. function captureThis()
  535. {
  536. statusitems[UBound] = status;
  537. actualvalues[UBound] = actual;
  538. expectedvalues[UBound] = expect;
  539. UBound++;
  540. }
  541. function test()
  542. {
  543. enterFunc ('test');
  544. printBugNumber (bug);
  545. printStatus (summary);
  546. for (var i=0; i<UBound; i++)
  547. {
  548. reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
  549. }
  550. exitFunc ('test');
  551. }