Re: [geometry] Should DOMRect have a serializer

On Tue, 18 Nov 2014 17:18:06 +0100, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> Specifically, should JSON.stringify on a DOMRect produce "{}" as it does  
> not per spec or something more like  
> '{"height":3462,"width":1263,"left":0,"bottom":3462,"right":1263,"top":0}'?

What are the use cases for JSON stringifying geometry objects?

It seems to me the returned object should have the same shape as the *Init  
dictionaries, so you can use it in the constructors that accept them.

For DOMRect, the first-class properties are x, y, width, height, so { x,  
y, width, height }.

For DOMPoint, we could either always serialize { x, y, w, z } or only  
serialize { x, y } when w = 0 and z = 1.

For DOMQuad I guess it would just serialize as { p1, p2, p3, p4 } (without  
bounds).

For DOMMatrix, I guess it makes sense to serialize an array with the  
elements. We could either always serialize all of them or only serialize 6  
elements when is2D returns true.

-- 
Simon Pieters
Opera Software

Received on Tuesday, 25 November 2014 10:09:27 UTC