Skip to content

Commit

Permalink
[giow] (1) Update postMessage() to do the transfers after the cloning…
Browse files Browse the repository at this point in the history
… so that if cloning fails, the transferables don't get killed.

Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=13799

git-svn-id: http://svn.whatwg.org/webapps@6697 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Oct 19, 2011
1 parent 6c268ba commit c0aa35c
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 149 deletions.
127 changes: 79 additions & 48 deletions complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -8938,9 +8938,8 @@ <h4 id=safe-passing-of-structured-data><span class=secno>2.8.6 </span>Safe passi
clone</dfn> of a value, optionally with a <i>transfer map</i>, it
must run the following algorithm, which either returns a separate
value, or throws an exception. If a <i>transfer map</i> is provided,
it consists of a association list of pairs of
<code><a href=#transferable>Transferable</a></code> objects; in each pair, one is the
<em>old</em> object and one is the <em>new</em> object.</p>
it consists of a association list of <code><a href=#transferable>Transferable</a></code>
objects to placeholder objects.</p>

<ol><li><p>Let <var title="">input</var> be the value being
cloned.</li>
Expand All @@ -8955,9 +8954,9 @@ <h4 id=safe-passing-of-structured-data><span class=secno>2.8.6 </span>Safe passi
<em>source</em> object and the other the <em>destination</em>
object.</li>

<li><p>For each pair of objects in <var title="">transfer
map</var>, add a mapping from the old object (the source object) to
the new object (the destination object) to <var title="">memory</var>.</li>
<li><p>For each mapping in <var title="">transfer map</var>, add a
mapping from the <code><a href=#transferable>Transferable</a></code> object (the source
object) to the placeholder object (the destination object) to <var title="">memory</var>.</li>

<li><p>Let <var title="">output</var> be the value resulting from
calling the <a href=#internal-structured-cloning-algorithm>internal structured cloning algorithm</a> with
Expand Down Expand Up @@ -81718,7 +81717,8 @@ <h4 id=posting-messages><span class=secno>11.4.3 </span>Posting messages</h4>
<li>

<p>Let <var title="">transfer map</var> be an empty association
list of pairs of <code><a href=#transferable>Transferable</a></code> objects.</p>
list of <code><a href=#transferable>Transferable</a></code> objects to placeholder
objects.</p>

</li>

Expand All @@ -81738,34 +81738,49 @@ <h4 id=posting-messages><span class=secno>11.4.3 </span>Posting messages</h4>

<li>

<p>If the <var title="">transfer</var> argument is present, then
for each object in <var title="">transfer</var> in turn, obtain
a new object by <a href=#transfer-a-transferable-object title="transfer a Transferable
object">transferring</a> the object to the
<code><a href=#window>Window</a></code> object on which the method was invoked, and
add a mapping from the old object to the new transferred object
to <var title="">transfer map</var>. For each new
<code><a href=#messageport>MessagePort</a></code> object obtained in this manner, append
the new transferred object to the <var title="">new ports</var>
array.</p>
<p>For each object <var title="">x</var> in <var title="">transfer</var> in turn, add a mapping from <var title="">x</var> to a new unique placeholder object created for
<var title="">x</var> to <var title="">transfer map</var>, and
if <var title="">x</var> is a <code><a href=#messageport>MessagePort</a></code> object,
also append the placeholder object to the <var title="">new
ports</var> array.</p>

</li>

</ol></li>

<li>

<p>Make <var title="">new ports</var> into a <a href=#dfn-read-only-array title=dfn-read-only-array>read only</a> array.</p>

</li>

<li>

<p>Let <var title="">message clone</var> be the result of
obtaining a <a href=#structured-clone>structured clone</a> of the <var title="">message</var> argument, with <var title="">transfer
map</var> as the <i>transfer map</i>. If this throws an exception,
then throw that exception and abort these steps.</p>

</li>

<p>If the method was invoked with a third argument <var title="">transfer</var>, run these substeps:</p>

<ol><li>

<p>Let <var title="">new owner</var> be the <code><a href=#window>Window</a></code>
object on which the method was invoked.</p>

</li>

<li>

<p>For each object <var title="">x</var> in <var title="">transfer</var> in turn, obtain a new object <var title="">y</var> by <a href=#transfer-a-transferable-object title="transfer a Transferable
object">transferring</a> the object <var title="">x</var> to
<var title="">new owner</var>, and replace the placeholder
object that was created for the object <var title="">x</var> by
the new object <var title="">y</var> wherever the placeholder
exists (i.e. in <var title="">message clone</var> and in <var title="">new ports</var>).</p>

</li>

</ol><li>

<p>Make <var title="">new ports</var> into a <a href=#dfn-read-only-array title=dfn-read-only-array>read only</a> array.</p>

</li>

<li>
Expand Down Expand Up @@ -82170,14 +82185,6 @@ <h4 id=message-ports><span class=secno>11.5.3 </span>Message ports</h4>
<ol><!-- a lot of this is similar or identical to window.postMessage --><li><p>Let <var title="">target port</var> be the port with which
<var title="">source port</var> is entangled, if any.</li>

<li><p>Let <var title="">new owner</var> be the owner of <var title="">target port</var>, if there is a <var title="">target
port</var>, or else some arbitrary owner. (This <var title="">new
owner</var> is used when transfering objects below. If there is no
<var title="">target port</var>, the <code><a href=#transferable>Transferable</a></code>
objects given in the second argument, if any, are still <a href=#transfer-a-transferable-object title="transfer a Transferable object">transfered</a>, but since
they are then discarded, it doesn't matter where they are
transfered to.)</li>

<li>

<p>Let <var title="">new ports</var> be an empty array.</p>
Expand All @@ -82187,7 +82194,8 @@ <h4 id=message-ports><span class=secno>11.5.3 </span>Message ports</h4>
<li>

<p>Let <var title="">transfer map</var> be an empty association
list of pairs of <code><a href=#transferable>Transferable</a></code> objects.</p>
list of <code><a href=#transferable>Transferable</a></code> objects to placeholder
objects.</p>

</li>

Expand Down Expand Up @@ -82216,35 +82224,58 @@ <h4 id=message-ports><span class=secno>11.5.3 </span>Message ports</h4>

<li>

<p>If the <var title="">transfer</var> argument is present, then
for each object in <var title="">transfer</var> in turn, obtain
a new object by <a href=#transfer-a-transferable-object title="transfer a Transferable
object">transferring</a> the object to <var title="">new
owner</var>, and add a mapping from the old object to the new
transferred object to <var title="">transfer map</var>. If the
objects are <code><a href=#messageport>MessagePort</a></code> objects, also append the
new transferred object to the <var title="">new ports</var>
array.</p>
<p>For each object <var title="">x</var> in <var title="">transfer</var> in turn, add a mapping from <var title="">x</var> to a new unique placeholder object created for
<var title="">x</var> to <var title="">transfer map</var>, and
if <var title="">x</var> is a <code><a href=#messageport>MessagePort</a></code> object,
also append the placeholder object to the <var title="">new
ports</var> array.</p>

</li>

</ol></li>

<li>

<p>Make <var title="">new ports</var> into a <a href=#dfn-read-only-array title=dfn-read-only-array>read only</a> array.</p>
<p>Let <var title="">message clone</var> be the result of
obtaining a <a href=#structured-clone>structured clone</a> of the <var title="">message</var> argument, with <var title="">transfer
map</var> as the <i>transfer map</i>. If this throws an exception,
then throw that exception and abort these steps.</p>

</li>

<li><p>Let <var title="">message</var> be the method's first
argument.</li>
<li>

<p>If the method was invoked with a second argument <var title="">transfer</var>, run these substeps:</p>

<ol><li>

<p>Let <var title="">new owner</var> be the owner of <var title="">target port</var>, if there is a <var title="">target
port</var>, or else some arbitrary owner. (This <var title="">new owner</var> is used when transfering objects below.
If there is no <var title="">target port</var>, the
<code><a href=#transferable>Transferable</a></code> objects given in the second argument,
if any, are still <a href=#transfer-a-transferable-object title="transfer a Transferable
object">transfered</a>, but since they are then discarded, it
doesn't matter where they are transfered to.)</p>

</li>


<li>

<p>For each object <var title="">x</var> in <var title="">transfer</var> in turn, obtain a new object <var title="">y</var> by <a href=#transfer-a-transferable-object title="transfer a Transferable
object">transferring</a> the object <var title="">x</var> to
<var title="">new owner</var>, and replace the placeholder
object that was created for the object <var title="">x</var> by
the new object <var title="">y</var> wherever the placeholder
exists (i.e. in <var title="">message clone</var> and in <var title="">new ports</var>).</p>

</li>

</ol></li>

<li>

<p>Let <var title="">message clone</var> be the result of
obtaining a <a href=#structured-clone>structured clone</a> of the <var title="">message</var> argument, with <var title="">transfer
map</var> as the <i>transfer map</i>. If this throws an exception,
then throw that exception and abort these steps.</p>
<p>Make <var title="">new ports</var> into a <a href=#dfn-read-only-array title=dfn-read-only-array>read only</a> array.</p>

</li>

Expand Down
Loading

0 comments on commit c0aa35c

Please sign in to comment.