archives

« Bugzilla Issues Index

#92 — tests should never depend upon predicting the result of toStringing a function


Some tests define a function and then compare the result returned by toString applied to that function to some expected result. Presumably this is done to ensure that a function value is in fact the expected function value.

However, such a test can produce false negatives because 15.3.3.3 says that Function.prototype.toString produces an implementation defined result.

All tests that use toString on a function value need to be reviewed for this problem.


Searched through all IE Test Center tests for "toString()" and the only thing left that looked suspicious was 13.2-18-1.js:
var fun = function () { };
verifyValue = (fun.prototype !== 100 && fun.prototype.toString() === "[object Object]");

As toString is being called on the prototype itself, this seems OK...


(In reply to comment #1)
> Searched through all IE Test Center tests for "toString()" and the only thing
> left that looked suspicious was 13.2-18-1.js:
> var fun = function () { };
> verifyValue = (fun.prototype !== 100 && fun.prototype.toString() ===
> "[object Object]");
>
> As toString is being called on the prototype itself, this seems OK...

The default value that is creates for the prototype property is not a function so, so this shouldn't be an issue here. I'm not sure what the the test against 100 is all about.

I would think that this test should really be something like:
typeof fun.prototype === 'object' && {}.prototype.toString.call(fun.prototype) === "[object Object]"