Bug 14325

Summary: Using built-in type Constructor objects as keys fails
Product: WebKit Reporter: Adam Winer <awiner>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED INVALID    
Severity: Major    
Priority: P2    
Version: 523.x (Safari 3)   
Hardware: All   
OS: All   

Adam Winer
Reported 2007-06-22 17:47:57 PDT
Run the following page. In FF 2.0 and IE 7.0, you see "n b s d a m". In Safari, you just see "m"! Somehow, all of these constructors are considered the same key within an Object - this despite String == Object being false. Repros on both MacOS 419.3 and Windows 522.13.1. <html> <head> <script> var typeMap = new Object(); typeMap[Number] = "n"; typeMap[Boolean] = "b"; typeMap[String] = "s"; typeMap[Date] = "d"; typeMap[Array] = "a"; typeMap[Object] = "m"; var str = ""; for (var i in typeMap) { str += typeMap[i] + " "; } </script> </head> <body> <div id ='someId' onclick="testHtml()">Hi</div> </body> </html>
Attachments
Geoffrey Garen
Comment 1 2007-06-22 18:27:49 PDT
This is a coincidental side-effect of the fact that Firefox and IE convert these objects to unique strings. Generally, JavaScript does not support using an object as a key. It uses strings as keys. The following fails in the same way in Firefox, even though each key is a distinct object: typeMap[new Object] = "n"; typeMap[new Object] = "b"; typeMap[new Object] = "s"; typeMap[new Object] = "d"; typeMap[new Object] = "a"; typeMap[new Object] = "m";
Note You need to log in before you can comment on or make changes to this bug.