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

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk · JavaScript · 215 lines · 129 code · 26 blank · 60 comment · 1 complexity · 6cd52b6f68a6a1a154e5a127b82eb24c 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) 2002
  18. * the Initial Developer. All Rights Reserved.
  19. *
  20. * Contributor(s): desale@netscape.com, pschwartau@netscape.com
  21. *
  22. * Alternatively, the contents of this file may be used under the terms of
  23. * either the GNU General Public License Version 2 or later (the "GPL"), or
  24. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  25. * in which case the provisions of the GPL or the LGPL are applicable instead
  26. * of those above. If you wish to allow use of your version of this file only
  27. * under the terms of either the GPL or the LGPL, and not to allow others to
  28. * use your version of this file under the terms of the NPL, indicate your
  29. * decision by deleting the provisions above and replace them with the notice
  30. * and other provisions required by the GPL or the LGPL. If you do not delete
  31. * the provisions above, a recipient may use your version of this file under
  32. * the terms of any one of the NPL, the GPL or the LGPL.
  33. *
  34. * ***** END LICENSE BLOCK *****
  35. *
  36. *
  37. * Date: 13 Sep 2002
  38. * SUMMARY: Testing F.toString()
  39. * See http://bugzilla.mozilla.org/show_bug.cgi?id=168347
  40. *
  41. */
  42. //-----------------------------------------------------------------------------
  43. var UBound = 0;
  44. var bug = 168347;
  45. var summary = "Testing F.toString()";
  46. var status = '';
  47. var statusitems = [];
  48. var actual = '';
  49. var actualvalues = [];
  50. var expect= '';
  51. var expectedvalues = [];
  52. var FtoString = '';
  53. var sFunc = '';
  54. sFunc += 'function F()';
  55. sFunc += '{';
  56. sFunc += ' var f = arguments.callee;';
  57. sFunc += ' f.i = 0;';
  58. sFunc += '';
  59. sFunc += ' try';
  60. sFunc += ' {';
  61. sFunc += ' f.i = f.i + 1;';
  62. sFunc += ' print("i = i+1 succeeded \ti = " + f.i);';
  63. sFunc += ' }';
  64. sFunc += ' catch(e)';
  65. sFunc += ' {';
  66. sFunc += ' print("i = i+1 failed with " + e + "\ti = " + f.i);';
  67. sFunc += ' }';
  68. sFunc += '';
  69. sFunc += ' try';
  70. sFunc += ' {';
  71. sFunc += ' ++f.i;';
  72. sFunc += ' print("++i succeeded \t\ti = " + f.i);';
  73. sFunc += ' }';
  74. sFunc += ' catch(e)';
  75. sFunc += ' {';
  76. sFunc += ' print("++i failed with " + e + "\ti = " + f.i);';
  77. sFunc += ' }';
  78. sFunc += '';
  79. sFunc += ' try';
  80. sFunc += ' {';
  81. sFunc += ' f.i++;';
  82. sFunc += ' print("i++ succeeded \t\ti = " + f.i);';
  83. sFunc += ' }';
  84. sFunc += ' catch(e)';
  85. sFunc += ' {';
  86. sFunc += ' print("i++ failed with " + e + "\ti = " + f.i);';
  87. sFunc += ' }';
  88. sFunc += '';
  89. sFunc += ' try';
  90. sFunc += ' {';
  91. sFunc += ' --f.i;';
  92. sFunc += ' print("--i succeeded \t\ti = " + f.i);';
  93. sFunc += ' }';
  94. sFunc += ' catch(e)';
  95. sFunc += ' {';
  96. sFunc += ' print("--i failed with " + e + "\ti = " + f.i);';
  97. sFunc += ' }';
  98. sFunc += '';
  99. sFunc += ' try';
  100. sFunc += ' {';
  101. sFunc += ' f.i--;';
  102. sFunc += ' print("i-- succeeded \t\ti = " + f.i);';
  103. sFunc += ' }';
  104. sFunc += ' catch(e)';
  105. sFunc += ' {';
  106. sFunc += ' print("i-- failed with " + e + "\ti = " + f.i);';
  107. sFunc += ' }';
  108. sFunc += '}';
  109. /*
  110. * Use sFunc to define the function F. The test
  111. * then rests on comparing F.toString() to sFunc.
  112. */
  113. eval(sFunc);
  114. /*
  115. * There are trivial whitespace differences between F.toString()
  116. * and sFunc. So strip out whitespace before comparing them -
  117. */
  118. sFunc = stripWhite(sFunc);
  119. FtoString = stripWhite(F.toString());
  120. /*
  121. * Break comparison into sections to make any failures
  122. * easier for the developer to track down -
  123. */
  124. status = inSection(1);
  125. actual = FtoString.substring(0,100);
  126. expect = sFunc.substring(0,100);
  127. addThis();
  128. status = inSection(2);
  129. actual = FtoString.substring(100,200);
  130. expect = sFunc.substring(100,200);
  131. addThis();
  132. status = inSection(3);
  133. actual = FtoString.substring(200,300);
  134. expect = sFunc.substring(200,300);
  135. addThis();
  136. status = inSection(4);
  137. actual = FtoString.substring(300,400);
  138. expect = sFunc.substring(300,400);
  139. addThis();
  140. status = inSection(5);
  141. actual = FtoString.substring(400,500);
  142. expect = sFunc.substring(400,500);
  143. addThis();
  144. status = inSection(6);
  145. actual = FtoString.substring(500,600);
  146. expect = sFunc.substring(500,600);
  147. addThis();
  148. status = inSection(7);
  149. actual = FtoString.substring(600,700);
  150. expect = sFunc.substring(600,700);
  151. addThis();
  152. status = inSection(8);
  153. actual = FtoString.substring(700,800);
  154. expect = sFunc.substring(700,800);
  155. addThis();
  156. status = inSection(9);
  157. actual = FtoString.substring(800,900);
  158. expect = sFunc.substring(800,900);
  159. addThis();
  160. //-----------------------------------------------------------------------------
  161. test();
  162. //-----------------------------------------------------------------------------
  163. function addThis()
  164. {
  165. statusitems[UBound] = status;
  166. actualvalues[UBound] = actual;
  167. expectedvalues[UBound] = expect;
  168. UBound++;
  169. }
  170. /*
  171. * Remove any whitespace characters; also
  172. * any escaped tabs or escaped newlines.
  173. */
  174. function stripWhite(str)
  175. {
  176. var re = /\s|\\t|\\n/g;
  177. return str.replace(re, '');
  178. }
  179. function test()
  180. {
  181. enterFunc('test');
  182. printBugNumber(bug);
  183. printStatus(summary);
  184. for (var i=0; i<UBound; i++)
  185. {
  186. reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
  187. }
  188. exitFunc ('test');
  189. }