This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27428 - [ArrayClass] should serialize as an array by default
Summary: [ArrayClass] should serialize as an array by default
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
Depends on:
Reported: 2014-11-25 10:58 UTC by Simon Pieters
Modified: 2017-06-21 21:23 UTC (History)
6 users (show)

See Also:


Description Simon Pieters 2014-11-25 10:58:42 UTC


It seems currently the JSON serialization of DOMRectList is a bit ugly:




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].)
Comment 1 Anne 2014-11-25 11:05:59 UTC
[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.
Comment 2 Simon Pieters 2014-11-25 11:08:22 UTC
I don't want Blink's behavior (for this bug, anyway). If we assume that DOMRect should serialize as {} then I want:

Comment 3 Boris Zbarsky 2014-11-25 14:06:02 UTC
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...
Comment 4 Domenic Denicola 2014-11-25 15:58:26 UTC
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.
Comment 5 Tobie Langel 2017-06-21 20:47:13 UTC
Fixed in
Comment 6 Boris Zbarsky 2017-06-21 20:55:53 UTC
It is?  I don't see any ArrayClass provisions in there... am I just missing them?
Comment 7 Tobie Langel 2017-06-21 21:02:06 UTC
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.
Comment 8 Boris Zbarsky 2017-06-21 21:21:56 UTC
That's fine with me, but it sounds more like a wontfix than a fixed.  ;)
Comment 9 Tobie Langel 2017-06-21 21:23:13 UTC
(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.