This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
http://heycam.github.io/webidl/#ArrayClass [[ [ArrayClass] ]] It seems currently the JSON serialization of DOMRectList is a bit ugly: http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3315 Blink {"0":{"height":16,"width":1645,"left":8,"bottom":24,"right":1653,"top":8},"length":1} WebKit {"0":{},"length":1} Gecko {"0":{}} Assuming DOMRectList stays for Web compat, it would be nice to have it serialize as an array. Would it make sense for WebIDL to serialize [ArrayClass] interfaces as an array by default? (Or whatever replaces [ArrayClass].)
[ArrayClass] just puts Array on the prototype chain. That's it. If you want Blink's behavior you'd have to define that in the specification.
I don't want Blink's behavior (for this bug, anyway). If we assume that DOMRect should serialize as {} then I want: [{}]
This could be done fairly easily by just having a toJSON method on the object that returns an array with the DOMRects, right? Assuming we want to do it, that is...
JSON.stringify is indeed the easy way to fix this. The alternate fix is to make DOMRectList a proper Array subclass. Browsers don't support subclassing arrays yet though, except the IE 12 preview.
Fixed in https://github.com/heycam/webidl/commit/a505f33
It is? I don't see any ArrayClass provisions in there... am I just missing them?
My understanding from the above was that interfaces with the LegacyArrayClass extended attribute could just define their own JSONification strategy, e.g. by defining a toJSON operation which returns a sequence.
That's fine with me, but it sounds more like a wontfix than a fixed. ;)
(In reply to Boris Zbarsky from comment #8) > That's fine with me, but it sounds more like a wontfix than a fixed. ;) That's a good point.