]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/Number/15.7.4.5-1.js
2 * The contents of this file are subject to the Netscape Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/NPL/
7 * Software distributed under the License is distributed on an
8 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed
9 * or implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is mozilla.org code.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation.
17 * All Rights Reserved.
19 * Contributor(s): pschwartau@netscape.com
22 * SUMMARY: Testing Number.prototype.toFixed(fractionDigits)
23 * See EMCA 262 Edition 3 Section 15.7.4.5
25 * Also see http://bugzilla.mozilla.org/show_bug.cgi?id=90551
28 //-----------------------------------------------------------------------------
31 var summary
= 'Testing Number.prototype.toFixed(fractionDigits)';
32 var cnIsRangeError
= 'instanceof RangeError';
33 var cnNotRangeError
= 'NOT instanceof RangeError';
34 var cnNoErrorCaught
= 'NO ERROR CAUGHT...';
38 var actualvalues
= [];
40 var expectedvalues
= [];
41 var testNum
= 234.2040506;
44 status
= 'Section A of test: no error intended!';
45 actual
= testNum
.toFixed(4);
50 /////////////////////////// OOPS.... ///////////////////////////////
51 /*************************************************************************
52 * 15.7.4.5 Number.prototype.toFixed(fractionDigits)
54 * An implementation is permitted to extend the behaviour of toFixed
55 * for values of fractionDigits less than 0 or greater than 20. In this
56 * case toFixed would not necessarily throw RangeError for such values.
58 status = 'Section B of test: expect RangeError because fractionDigits < 0';
59 actual = catchError('testNum.toFixed(-4)');
60 expect = cnIsRangeError;
63 status = 'Section C of test: expect RangeError because fractionDigits > 20 ';
64 actual = catchError('testNum.toFixed(21)');
65 expect = cnIsRangeError;
67 *************************************************************************/
70 status
= 'Section D of test: no error intended!';
71 actual
= 0.00001.toFixed(2);
75 status
= 'Section E of test: no error intended!';
76 actual
= 0.000000000000000000001.toFixed(20);
77 expect
= '0.00000000000000000000';
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
87 function captureThis()
89 statusitems
[UBound
] = status
;
90 actualvalues
[UBound
] = actual
;
91 expectedvalues
[UBound
] = expect
;
100 printStatus (summary
);
102 for (var i
= 0; i
< UBound
; i
++)
104 reportCompare(expectedvalues
[i
], actualvalues
[i
], statusitems
[i
]);
111 function catchError(sEval
)
114 catch(e
) {return isRangeError(e
);}
115 return cnNoErrorCaught
;
119 function isRangeError(obj
)
121 if (obj
instanceof RangeError
)
122 return cnIsRangeError
;
123 return cnNotRangeError
;