Closed Bug 90551 Opened 23 years ago Closed 23 years ago

toFixed, toExponential and toPrecision not throwing range errors

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

VERIFIED WONTFIX

People

(Reporter: pbwiz, Assigned: khanson)

References

Details

Running the following code should throw range errors:

var num = 1234;
var msg =	"Before: " +
			"    fixed:  " + num.toFixed(50) + "\n" +
			"    exp:    " + num.toExponential(50)  + "\n" +
			"    prec:   " + num.toPrecision(50)
alert( msg );



toFixed and toExponential should throw a range error if the argument is less 
than 0 or greater than 20 and toPrecision should throw a range error if the 
argument is less than 1 or greater than 21 as per ECMA262v3.

I do not know if you are just expanding upon the standard, but it is clear in 
the standard that an error should be thrown.

See: 15.7.4.5 to 7 of the ECMAScript v3 documentation.


Jeff
http://www.pbwizard.com
Jeff is absolutely correct. Added testcases to JS test suite: 

           mozilla/js/tests/ecma_3/Number/15.7.4.5-1.js
           mozilla/js/tests/ecma_3/Number/15.7.4.6-1.js
           mozilla/js/tests/ecma_3/Number/15.7.4.7-1.js


Each test currently fails in SpiderMonkey -
OS: Windows 2000 → All
Hardware: PC → All
Reassigning to Kenton - 
Assignee: rogerl → khanson
"An implementation is permitted to extend the behaviour of toFixed for values of 
fractionDigits less than 0 or greater than 20.  In this case toFixed would not 
necessarily throw TangeError for such values"
See: 15.7.4.5 of the ECMAScript v3 documentation.

"An implementation is permitted to extend the behaviour of toExponential for 
values of fractionDigits less than 0 or greater than 20.  In this case 
toExponential would not necessarily throw TangeError for such values"
See: 15.7.4.6 of the ECMAScript v3 documentation.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → WONTFIX
Similarly for toPrecision:


15.7.4.7 Number.prototype.toPrecision (precision) 

An implementation is permitted to extend the behaviour of toPrecision 
for values of precision less than 1 or greater than 21. In this case 
toPrecision would not necessarily throw RangeError for such values. 
Status: RESOLVED → VERIFIED
Marking Verified Wontfix. Will remove or modify the above tests accordingly -
Jeff, thank you for this report - 
*** Bug 186562 has been marked as a duplicate of this bug. ***
But what is the range for these methods then?  Jeff's tests use range up to 50
and still no RangeError!  Don't tell me they're supposed to work for up to 100 !?

How about range for negative values?
Although the spec permits this variability, other browsers do not take advantage of it. V8, JSC and ChakraCore all use the bounds [0, 21] as in the spec; it seems to be only SpiderMonkey that uses different bounds [-20, 100]. Would it make sense to harmonize with the other browsers here? This would also allow the ECMAScript spec to remove a point of variability among conforming implementations.
See Also: → 1068612
You need to log in before you can comment on or make changes to this bug.