Asen said:
The interesting here is, how IE form Scope Chain when entering in
global execution context. I think IE when entering in global execution
context, Scope Chain contains:
Window Host <-- Global Object
Bingo!
By quoting myself from 2006:
http://groups.google.com/group/comp.lang.javascript/msg/02528de788828b39
"IE and Opera have two separate scopes: Global and enclosing Window.
Firefox has (or pretending to have) only one: Global which is Window
(or Window which is Global - I'm really lost here). If both allowed by
specs so the better. If one of them is not allowed by specs - it
doesn't make it disappear."
Back in March 2006 "the public" was not ready yet to such things so
the hysteria was like with an ugly rat thrown into lady's room
In fact any browser has Global scope first and window scope above it:
so first Global lookup, if not found then window lookup. That is the
only way to make JavaScript usable without some fantastic "global
naming agreement" between browser producers and JavaScript programmers
mentioned in my previous post. The rest of the story is caused by a
set of events:
1) 1999 ECMA 262 sh** crap about host == Global or whatever (I'm still
doubting very much that they knew themselves was what written that day
in that particular section).
2) "religious war" of 2005-2008 when anyone in anti-IE camp tried to
be as holly as it gets so implemented or at least tried to implement
even the most sick parts of specs either by ECMA or by W3C
3) the last but maybe the most influential one: the anti-popup
campaign 2005-2006. Who remembers that time, at some moment a lot of
resources became nearly unusable as on each visit 3-5-10 window pop-
ups and pop-unders have been thrown. So "kill these pupups!" was a
global demand so all browser manufactures jumped on it as an
opportunity to be cooler than the competitor. That was the time of
actively shadowing window native methods like "open" with bogus one
and actively looking and fixing possibilities to get to the shadowed
methods. That was the time of "bugs" like "prevent user from getting
fresh method references from the runtime created iframe object" and
similar.
Any way, the real scope schema, being patched, fixed, locked, emulated
etc. everywhere 10 years in the row is the reason of the rather sorry
- but definitely not catastrophic - state we are having right now.
In the relevance to eval() escaping DontDelete on IE: it's just an
oops of the original "delete" functionality fix made back then for the
reason (3). The "hanging out ends" can be seen in this test code back
from the spring of 2006:
<script type="text/javascript">
window['foo'] = 1;
eval('var foo = 2');
window.alert(this.window.foo); // 2
delete foo; // OK
try {
window.alert(this.window.foo);
// Error # 438 Not supported
}
catch(e) {
window.alert(
'window.alert(this.window.foo)\n' +
(e.number & 0xFFFF) + ' ' +
e.message);
}
try {
window.alert(this.foo);
// Error # 438 Not supported
}
catch(e) {
window.alert(
'window.alert(this.foo)\n' +
(e.number & 0xFFFF) + ' ' +
e.message);
}
try {
window.alert(window.foo);
// Error # 438 Not supported
}
catch(e) {
window.alert(
'window.alert(window.foo)\n' +
(e.number & 0xFFFF) + ' ' +
e.message);
}
try {
window.alert(foo);
// Error # 7 Out of memory
}
catch(e) {
window.alert(
'window.alert(foo)\n' +
(e.number & 0xFFFF) + ' ' +
e.message);
}
</script>