Skip to content

Commit

Permalink
[geometry] Define serialize/deserialize steps
Browse files Browse the repository at this point in the history
Fixes #121.
  • Loading branch information
zcorpan authored May 15, 2017
1 parent f5eadb4 commit 582844c
Showing 1 changed file with 171 additions and 18 deletions.
189 changes: 171 additions & 18 deletions geometry/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Transforms. [[SVG11]] [[2DCONTEXT]] [[CSS3-TRANSFORMS]]
<pre class=idl>
[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double z = 0, optional unrestricted double w = 1),
Exposed=(Window,Worker)]
Exposed=(Window,Worker),
Serializable]
interface DOMPointReadOnly {
[NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit other);

Expand All @@ -83,7 +84,8 @@ interface DOMPointReadOnly {

[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double z = 0, optional unrestricted double w = 1),
Exposed=(Window,Worker)]
Exposed=(Window,Worker),
Serializable]
interface DOMPoint : DOMPointReadOnly {
[NewObject] static DOMPoint fromPoint(optional DOMPointInit other);

Expand Down Expand Up @@ -245,7 +247,8 @@ object.
<pre class=idl>
[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double width = 0, optional unrestricted double height = 0),
Exposed=(Window,Worker)]
Exposed=(Window,Worker),
Serializable]
interface DOMRectReadOnly {
[NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other);

Expand All @@ -263,7 +266,8 @@ interface DOMRectReadOnly {

[Constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double width = 0, optional unrestricted double height = 0),
Exposed=(Window,Worker)]
Exposed=(Window,Worker),
Serializable]
interface DOMRect : DOMRectReadOnly {
[NewObject] static DOMRect fromRect(optional DOMRectInit other);

Expand Down Expand Up @@ -377,7 +381,8 @@ non-enumerable property named <dfn dfn-type=interface><code>SVGRect</code></dfn>
<pre class=idl>
[Constructor(optional DOMPointInit p1, optional DOMPointInit p2,
optional DOMPointInit p3, optional DOMPointInit p4),
Exposed=(Window,Worker)]
Exposed=(Window,Worker),
Serializable]
interface DOMQuad {
[NewObject] static DOMQuad fromRect(optional DOMRectInit other);
[NewObject] static DOMQuad fromQuad(optional DOMQuadInit other);
Expand Down Expand Up @@ -614,7 +619,8 @@ context. The following sections describe the details of the interface.

<pre class=idl>
[Constructor(optional (DOMString or sequence&lt;unrestricted double>) init),
Exposed=(Window,Worker)]
Exposed=(Window,Worker),
Serializable]
interface DOMMatrixReadOnly {
[NewObject] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other);
[NewObject] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32);
Expand Down Expand Up @@ -687,7 +693,8 @@ interface DOMMatrixReadOnly {
};

[Constructor(optional (DOMString or sequence&lt;unrestricted double>) init),
Exposed=(Window,Worker)]
Exposed=(Window,Worker),
Serializable]
interface DOMMatrix : DOMMatrixReadOnly {
[NewObject] static DOMMatrix fromMatrix(optional DOMMatrixInit other);
[NewObject] static DOMMatrix fromFloat32Array(Float32Array array32);
Expand Down Expand Up @@ -1693,23 +1700,169 @@ user agents.
</dl>


<h2 id="cloning">Cloning</h2>
<h2 id="structured-serialization" oldids="cloning">Structured serialization</h2>

<p>When a user agent is asked to <b>clone</b> an {{DOMPointReadOnly}}, {{DOMPoint}},
{{DOMRectReadOnly}}, {{DOMRect}}, {{DOMQuad}}, {{DOMMatrixReadOnly}} or {{DOMMatrix}} object
<var>old</var>, it must run the following steps, which return a new object of same type. These steps
must be run atomically.
<p>{{DOMPointReadOnly}}, {{DOMPoint}}, {{DOMRectReadOnly}}, {{DOMRect}}, {{DOMQuad}},
{{DOMMatrixReadOnly}}, and {{DOMMatrix}} objects are <a>serializable objects</a>. [[!HTML]]

<p>The <a>serialization steps</a> for {{DOMPointReadOnly}} and {{DOMPoint}}, given |value| and
|serialized|, are:

<ol>
<li><p>Set |serialized|.\[[X]] to |value|'s <a for=point>x coordinate</a>.

<li><p>Set |serialized|.\[[Y]] to |value|'s <a for=point>y coordinate</a>.

<li><p>Set |serialized|.\[[Z]] to |value|'s <a for=point>z coordinate</a>.

<li><p>Set |serialized|.\[[W]] to |value|'s <a for=point>w perspective</a>.
</ol>

<p>Their <a>deserialization steps</a>, given |serialized| and |value|, are:

<ol>
<li>Set |value|'s <a for=point>x coordinate</a> to |serialized|.\[[X]].

<li>Set |value|'s <a for=point>y coordinate</a> to |serialized|.\[[Y]].

<li>Set |value|'s <a for=point>z coordinate</a> to |serialized|.\[[Z]].

<li>Set |value|'s <a for=point>w perspective</a> to |serialized|.\[[W]].
</ol>

<p>The <a>serialization steps</a> for {{DOMRectReadOnly}} and {{DOMRect}}, given |value| and
|serialized|, are:

<ol>
<li><p>Create a new object <var>new</var> of the same type as <var>old</var>. Copy all member
variable values from <var>old</var> to <var>new</var>.
<li><p>Set |serialized|.\[[X]] to |value|'s <a for=rectangle>x coordinate</a>.

<li><p>Return <var>new</var>. It is the clone.
<li><p>Set |serialized|.\[[Y]] to |value|'s <a for=rectangle>y coordinate</a>.

<li><p>Set |serialized|.\[[Width]] to |value|'s <a for=rectangle>width dimension</a>.

<li><p>Set |serialized|.\[[Height]] to |value|'s <a for=rectangle>height dimension</a>.
</ol>

<p>The above algorithm follows the <a
href="https://www.w3.org/TR/html5/infrastructure.html#safe-passing-of-structured-data">“safe passing
of structured data”</a> definitions. [[!HTML5]]
<p>Their <a>deserialization steps</a>, given |serialized| and |value|, are:

<ol>
<li>Set |value|'s <a for=rectangle>x coordinate</a> to |serialized|.\[[X]].

<li>Set |value|'s <a for=rectangle>y coordinate</a> to |serialized|.\[[Y]].

<li>Set |value|'s <a for=rectangle>width dimension</a> to |serialized|.\[[Width]].

<li>Set |value|'s <a for=rectangle>height dimension</a> to |serialized|.\[[Height]].
</ol>

<p>The <a>serialization steps</a> for {{DOMQuad}}, given |value| and |serialized|, are:

<ol>
<li><p>Set |serialized|.\[[P1]] to the <a>sub-serialization</a> of |value|'s <a
for=quadrilateral>point 1</a>.

<li><p>Set |serialized|.\[[P2]] to the <a>sub-serialization</a> of |value|'s <a
for=quadrilateral>point 2</a>.

<li><p>Set |serialized|.\[[P3]] to the <a>sub-serialization</a> of |value|'s <a
for=quadrilateral>point 3</a>.

<li><p>Set |serialized|.\[[P4]] to the <a>sub-serialization</a> of |value|'s <a
for=quadrilateral>point 4</a>.
</ol>

<p>Their <a>deserialization steps</a>, given |serialized| and |value|, are:

<ol>
<li><p>Set |value|'s <a for=quadrilateral>point 1</a> to the <a>sub-deserialization</a> of
|serialized|.\[[P1]].

<li><p>Set |value|'s <a for=quadrilateral>point 2</a> to the <a>sub-deserialization</a> of
|serialized|.\[[P2]].

<li><p>Set |value|'s <a for=quadrilateral>point 3</a> to the <a>sub-deserialization</a> of
|serialized|.\[[P3]].

<li><p>Set |value|'s <a for=quadrilateral>point 4</a> to the <a>sub-deserialization</a> of
|serialized|.\[[P4]].
</ol>

<p>The <a>serialization steps</a> for {{DOMMatrixReadOnly}} and {{DOMMatrix}}, given |value| and
|serialized|, are:

<ol>
<li><p>Set |serialized|.\[[M11]] to |value|'s <a for=matrix>m11 element</a>.

<li><p>Set |serialized|.\[[M12]] to |value|'s <a for=matrix>m12 element</a>.

<li><p>Set |serialized|.\[[M13]] to |value|'s <a for=matrix>m13 element</a>.

<li><p>Set |serialized|.\[[M14]] to |value|'s <a for=matrix>m14 element</a>.

<li><p>Set |serialized|.\[[M21]] to |value|'s <a for=matrix>m21 element</a>.

<li><p>Set |serialized|.\[[M22]] to |value|'s <a for=matrix>m22 element</a>.

<li><p>Set |serialized|.\[[M23]] to |value|'s <a for=matrix>m23 element</a>.

<li><p>Set |serialized|.\[[M24]] to |value|'s <a for=matrix>m24 element</a>.

<li><p>Set |serialized|.\[[M31]] to |value|'s <a for=matrix>m31 element</a>.

<li><p>Set |serialized|.\[[M32]] to |value|'s <a for=matrix>m32 element</a>.

<li><p>Set |serialized|.\[[M33]] to |value|'s <a for=matrix>m33 element</a>.

<li><p>Set |serialized|.\[[M34]] to |value|'s <a for=matrix>m34 element</a>.

<li><p>Set |serialized|.\[[M41]] to |value|'s <a for=matrix>m41 element</a>.

<li><p>Set |serialized|.\[[M42]] to |value|'s <a for=matrix>m42 element</a>.

<li><p>Set |serialized|.\[[M43]] to |value|'s <a for=matrix>m43 element</a>.

<li><p>Set |serialized|.\[[M44]] to |value|'s <a for=matrix>m44 element</a>.

<li><p>Set |serialized|.\[[Is2D]] to |value|'s <a for=matrix>is 2D</a>.
</ol>

<p>Their <a>deserialization steps</a>, given |serialized| and |value|, are:

<ol>
<li><p>Set |value|'s <a for=matrix>m11 element</a> to |serialized|.\[[M11]].

<li><p>Set |value|'s <a for=matrix>m12 element</a> to |serialized|.\[[M12]].

<li><p>Set |value|'s <a for=matrix>m13 element</a> to |serialized|.\[[M13]].

<li><p>Set |value|'s <a for=matrix>m14 element</a> to |serialized|.\[[M14]].

<li><p>Set |value|'s <a for=matrix>m21 element</a> to |serialized|.\[[M21]].

<li><p>Set |value|'s <a for=matrix>m22 element</a> to |serialized|.\[[M22]].

<li><p>Set |value|'s <a for=matrix>m23 element</a> to |serialized|.\[[M23]].

<li><p>Set |value|'s <a for=matrix>m24 element</a> to |serialized|.\[[M24]].

<li><p>Set |value|'s <a for=matrix>m31 element</a> to |serialized|.\[[M31]].

<li><p>Set |value|'s <a for=matrix>m32 element</a> to |serialized|.\[[M32]].

<li><p>Set |value|'s <a for=matrix>m33 element</a> to |serialized|.\[[M33]].

<li><p>Set |value|'s <a for=matrix>m34 element</a> to |serialized|.\[[M34]].

<li><p>Set |value|'s <a for=matrix>m41 element</a> to |serialized|.\[[M41]].

<li><p>Set |value|'s <a for=matrix>m42 element</a> to |serialized|.\[[M42]].

<li><p>Set |value|'s <a for=matrix>m43 element</a> to |serialized|.\[[M43]].

<li><p>Set |value|'s <a for=matrix>m44 element</a> to |serialized|.\[[M44]].

<li><p>Set |value|'s <a for=matrix>is 2D</a> to |serialized|.\[[Is2D]].
</ol>


<h2 id="priv-sec">Privacy and Security Considerations</h2>
Expand Down

0 comments on commit 582844c

Please sign in to comment.