2
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10
* SUMMARY: Testing Number.prototype.toExponential(fractionDigits)
11
* See EMCA 262 Edition 3 Section 15.7.4.6
13
* Also see http://bugzilla.mozilla.org/show_bug.cgi?id=90551
16
//-----------------------------------------------------------------------------
18
var BUGNUMBER = '(none)';
19
var summary = 'Testing Number.prototype.toExponential(fractionDigits)';
20
var cnIsRangeError = 'instanceof RangeError';
21
var cnNotRangeError = 'NOT instanceof RangeError';
22
var cnNoErrorCaught = 'NO ERROR CAUGHT...';
26
var actualvalues = [];
28
var expectedvalues = [];
29
var testNum = 77.1234;
32
status = 'Section A of test: no error intended!';
33
actual = testNum.toExponential(4);
37
status = 'Section B of test: Infinity.toExponential() with out-of-range fractionDigits';
38
actual = Number.POSITIVE_INFINITY.toExponential(-3);
42
status = 'Section C of test: -Infinity.toExponential() with out-of-range fractionDigits';
43
actual = Number.NEGATIVE_INFINITY.toExponential(-3);
47
status = 'Section D of test: NaN.toExponential() with out-of-range fractionDigits';
48
actual = Number.NaN.toExponential(-3);
53
/////////////////////////// OOPS.... ///////////////////////////////
54
/*************************************************************************
55
* 15.7.4.6 Number.prototype.toExponential(fractionDigits)
57
* An implementation is permitted to extend the behaviour of toExponential
58
* for values of fractionDigits less than 0 or greater than 20. In this
59
* case toExponential would not necessarily throw RangeError for such values.
61
status = 'Section B of test: expect RangeError because fractionDigits < 0';
62
actual = catchError('testNum.toExponential(-4)');
63
expect = cnIsRangeError;
66
status = 'Section C of test: expect RangeError because fractionDigits > 20 ';
67
actual = catchError('testNum.toExponential(21)');
68
expect = cnIsRangeError;
70
*************************************************************************/
74
//-----------------------------------------------------------------------------
76
//-----------------------------------------------------------------------------
79
function captureThis()
81
statusitems[UBound] = status;
82
actualvalues[UBound] = actual;
83
expectedvalues[UBound] = expect;
91
printBugNumber(BUGNUMBER);
92
printStatus (summary);
94
for (var i = 0; i < UBound; i++)
96
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
103
function catchError(sEval)
106
catch(e) {return isRangeError(e);}
107
return cnNoErrorCaught;
111
function isRangeError(obj)
113
if (obj instanceof RangeError)
114
return cnIsRangeError;
115
return cnNotRangeError;