Closed
Bug 1100611
Opened 11 years ago
Closed 11 years ago
json.stringify for [object DOMRect] evaluates to "{}"
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: ganna.khabibullina, Unassigned, NeedInfo)
References
()
Details
(Keywords: reproducible, testcase)
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36
Steps to reproduce:
Open Firefox browser
Go to any page. Example: https://www.mozilla.org
Activate the Web Dev Tool by pressing F12
Run the following command in console:
JSON.stringify(document.querySelector('body').getBoundingClientRect())
Actual results:
"{}"
Expected results:
"{"height":3462,"width":1263,"left":0,"bottom":3462,"right":1263,"top":0}"
| Reporter | ||
Updated•11 years ago
|
Comment 1•11 years ago
|
||
IE11 does the same as us, Chrome doesn't. Chrome breaks if you pass it a DOM node, we output "{}" just like in this case.
Not sure what the spec says about things like this. Reading http://www.ecma-international.org/ecma-262/5.1/#sec-15.12.3 it seems that this depends on whether the properties of DOMRect are enumerable or not. This is backed up by the behaviour of Object.keys:
Object.keys(document.body.getBoundingClientRect())
gives an empty array on Gecko, and a list of the properties on Blink.
Comment 2•11 years ago
|
||
> Not sure what the spec says about things like this.
The spec says our behavior is correct.
> it seems that this depends on whether the properties of DOMRect are enumerable or not.
No, it depends on whether they're own properties or not. And per spec they're not; Blink gets this wrong.
It may be worth adding a jsonifier to DOMRect, though. That's a spec issue for http://dev.w3.org/fxtf/geometry/
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Component: JavaScript Engine → DOM
Resolution: --- → INVALID
Comment 3•11 years ago
|
||
> No, it depends on whether they're own properties or not.
Well, more precisely it depends on both:
Let K be an internal List of Strings consisting of the names of all the own properties
of value whose [[Enumerable]] attribute is true. The ordering of the Strings should be
the same as that used by the Object.keys standard built-in function.
(in step 6a of the abstract operation JO).
Comment 4•11 years ago
|
||
http://lists.w3.org/Archives/Public/public-fx/2014OctDec/0075.html sent to the standards list responsible for DOMRect.
Comment 5•11 years ago
|
||
The spec discussion is trying to figure out what the exact use cases are here, so we can figure out the right serializer behavior. So what _was_ the use case for JSON-stringifying the DOMRect?
Flags: needinfo?(ganna.khabibullina)
| Assignee | ||
Updated•7 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•