IE7 Object Overwrite Bug

Jon Sykes has found an interesting bug in IE7. In his post found a bizarre bug in IE7, he demonstrated the bug with some simple test scripts. Quite frankly, it should be a rare case to happen, but surely I’ve experienced the same bug before. I was so frustrated by it and had to rewrite portion of my code to work around it (not that hard)

There is a bug in IE7 where by a line of code inside a conditional statement that NEVER runs, can cause an object that is set with a fairly standard object declaration to be whipped. Even weirder is that it will have whipped the code even if you put a debug alert of the object before the code that does the whipping. Confused? I know I am.

Thankfully it does look fairly simple to work _around_ and avoid. But it’s probably a debug nightmare, and it’s a bug I couldn’t find referenced anywhere, so I figured it was worth sharing.

<script type=”text/javascript”>
this[‘test’] = {};
alert(this[‘test’]);
// will spit out [Object object]
</script>

<script type=”text/javascript”>
alert(this[‘test’]);
// will spit out Undefined in IE7
// this next chunk of code should never run.
if (true == false){
alert(”This never fires”);
// THIS SHOULD NOT IMPACT ON ANYTHING !!!!
var test; // take this line out and it works fine
alert(”This never fires”);
}
</script>

As you can see from the above example, the line “var test;” should never be executed since it is within “true==false” condition. But somehow it gets fired.



1 Response to “IE7 Object Overwrite Bug”


  1. 1 Kenny Lai Dec 6th, 2007 at 5:04 pm

    Hey Simon,

    We met through Chris Lee. Just wanted to say hey and let you know I enjoy reading your blog. Keep it up!

Leave a Reply




Close
E-mail It