Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadowing a Window property on the global object yields undefined #956

Closed
kmcallister opened this issue Sep 19, 2013 · 4 comments
Closed

Shadowing a Window property on the global object yields undefined #956

kmcallister opened this issue Sep 19, 2013 · 4 comments

Comments

@kmcallister
Copy link
Contributor

@kmcallister kmcallister commented Sep 19, 2013

$ ./servo ../src/test/html/test_bindings.html
ALERT: [object Window]
ALERT: ==1==
~"Error at file:/home/keegan/proj/servo/servo/build/../src/test/html/test_bindings.js:6u32: TypeError: document is undefined\n"
@jdm
Copy link
Member

@jdm jdm commented Sep 19, 2013

I suspect that's actually bareword document, not window.document. Still, both should work...

@kmcallister
Copy link
Contributor Author

@kmcallister kmcallister commented Sep 19, 2013

The offending code is

var document = window.document;
window.alert(document.documentElement);

If I alert(window.document) I get undefined.

@jdm
Copy link
Member

@jdm jdm commented Sep 25, 2013

[00:22:53] <jdm> what's supposed to happen if I use |var document = window.document; alert(document);|?
[00:23:10] <jdm> this has come up in servo and document and window.document seem to be undefined for some reason
[00:23:24] <Waldo> if document is a getter/setter own property on window, then that should be an early TypeError
[00:23:46] <jdm> it's an own property on window's prototype
[00:23:53] <Waldo> if it's a getter/setter on Window.prototype, or some other prototypal thing, then it should do alert(undefined)
[00:24:05] <jdm> huh
[00:24:08] <Waldo> which I think might alert the empty string because ha, ha, ha
[00:24:14] <jdm> that sounds like it's working, I guess
@jdm jdm closed this Sep 25, 2013
@bzbarsky
Copy link
Contributor

@bzbarsky bzbarsky commented Sep 25, 2013

Two things:

  1. Per spec, window.document is unforgeable, so an own property of the window.
  2. Per spec proposals, all of the global's stuff lives directly on the global, not on the proto chain.

#2, precisely because of this shadowing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.