« Bugzilla Issues Index

#1123 — Error behaviour for non-generic functions should be described in more detail

Certain functions are labelled as non-generic, e.g. Number.prototype.toFixed, and should raise TypeError exception if called with the wrong type of object. But the specification is not entirely precise when to raise the TypeError: Does it happen on function entry or when actually trying to access the value?

For Example Number.prototype.toFixed []:
1. Let f be ToInteger(fractionDigits). (If fractionDigits is undefined, this step produces the value 0).
2. ReturnIfAbrupt(f).
3. If f < 0 or f > 20, throw a RangeError exception.
4. Let x be this Number value.
5. ReturnIfAbrupt(x).

Let's recall [15.7.4] to get the explanation for the phrase “this Number value”:
Also, the phrase “this Number value” refers to either the Number value represented by this Number object, that is, the value of the [[NumberData]] internal data property of this Number object or the `this` value if its type is Number. A TypeError exception is thrown if the `this` value is neither an object that has a [[NumberData]] internal data property or a value whose type is Number.

I'd say calling toFixed with an incompatible object should nevertheless execute the steps 1-3, and then finally in step 4 raise a TypeError, because at that point “this Number value” is retrieved. All engines tested (IE10, Opera, JSC, Spidermonkey [1]) raise the TypeError on function entry, that means steps 1-3 are _not_ executed. I've used the following test case:
---{}, {valueOf: function(){throw "value-of"}})

[1] V8 is not included in this list because of

fixed in rev 14 editor's draft

as far as I can tell, toFixed was the only method with this issue. Let me know if you find others.

in Rev 14 draft