If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

Object.keys method returns different results when using on global window object

RESOLVED FIXED in mozilla27

Status

()

Core
DOM: Core & HTML
RESOLVED FIXED
4 years ago
3 years ago

People

(Reporter: duongna, Assigned: peterv)

Tracking

27 Branch
mozilla27
x86_64
Windows 8
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

4 years ago
User Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36

Steps to reproduce:

Run the following script:
<script>
    console.log(Object.keys(window));
    if(top == window){}
    console.log(Object.keys(window));
</script>


Actual results:

Returned value of the 2 calls are different:
["window", "document", "InstallTrigger", "console", "process", "global", "Mocha", "mocha", "sinon", "expect", "location", "mouseEvents", "msPointerEvents", "keyEvents", "uiEvents", "bubbleEvents", "touchEvents", "gestureEvents", "before", "after", "beforeEach", "afterEach", "context", "describe", "xcontext", "xdescribe", "specify", "it", "xspecify", "xit", "getInterface"]
["window", "document", "InstallTrigger", "console", "process", "global", "Mocha", "mocha", "sinon", "expect", "location", "mouseEvents", "msPointerEvents", "keyEvents", "uiEvents", "bubbleEvents", "touchEvents", "gestureEvents", "before", "after", "beforeEach", "afterEach", "context", "describe", "xcontext", "xdescribe", "specify", "it", "xspecify", "xit", "getInterface", "top"]


Expected results:

They should definitely be the same
Unless I'm mistaken, this is the expected behavior, per specifications of JS/DOM:
  |if (top == window) {}|
implicitly declares global value |top|, i.e. |window.top|.

Am I missing something?
(Reporter)

Comment 2

4 years ago
I thought that |top| is a built in property of the |window| and should be available from beginning. Is it lazy loaded in Firefox?
top is an unforgeable property, so it should exist directly on |window|.  That it doesn't, initially, is probably a side effect of window not being WebIDL yet.  This is a DOM bug, really, not a JS bug.
Component: JavaScript Engine → DOM: Core & HTML

Updated

4 years ago
Depends on: 789261

Comment 4

4 years ago
(In reply to Jeff Walden [:Waldo] (remove +bmo to email) from comment #3)
> top is an unforgeable property, so it should exist directly on |window|. 
> That it doesn't, initially, is probably a side effect of window not being
> WebIDL yet.  This is a DOM bug, really, not a JS bug.
yes. @duongna, this bug should be fixed as a side-effect of fixing of bug 789261.
There are other ways in which using the window object doesn't comply to ECMAScript reflection methods. That should all be fixed when bug 789261 is fixed.
Component: DOM: Core & HTML → JavaScript Engine
Component: JavaScript Engine → DOM: Core & HTML
This was fixed by bug 918345.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 3 years ago
Depends on: 918345
Resolution: --- → FIXED
Assignee: nobody → peterv
Target Milestone: --- → mozilla27
You need to log in before you can comment on or make changes to this bug.