Bug 6601 - valueOf confuses JSC when run through KDE shouldThrow test
Summary: valueOf confuses JSC when run through KDE shouldThrow test
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-16 18:34 PST by Geoffrey Garen
Modified: 2011-09-06 23:07 PDT (History)
3 users (show)

See Also:


Attachments
Reduction. (3.01 KB, text/html)
2006-01-16 18:35 PST, Geoffrey Garen
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Geoffrey Garen 2006-01-16 18:34:16 PST
The attached reduction.html fails in Safari but passes in Firefox. This line:

testPassed(_a + " threw exception " + exception + ".");

ends up throwing an exception somehow.

Using the function name "valueOf" in the test code is the key to triggering this bug.
Comment 1 Geoffrey Garen 2006-01-16 18:35:11 PST
Created attachment 5729 [details]
Reduction.
Comment 2 Cameron Zwarich (cpst) 2008-06-07 02:03:07 PDT
This doesn't pass in either Firefox or Opera, for the same reason as WebKit. Are you sure this is a bug?
Comment 3 Gavin Barraclough 2011-09-06 23:07:51 PDT
This test case is invalid, and correctly fails (it fails in firefox, too).

The problem is that the test adds a valueOf method to the Object prototype.  The test (that an error is thrown) then passes (an error is thrown when Date.prototype.valueOf is applied to a vanilla object).

The test harness then tries to format up an error message indicating the test passed, using the following line:
    testPassed(_a + " threw exception " + exception + ".");
This will call ToPrimitive with the numeric hint on exception, which will favor calling the valueOf operator on the object.  Since TypeError derive from object, and the object prototype still has the date prototypes valueOf, the ToPrimitive conversion will correctly throw an error.