Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MessagePort.postMessage to create clones in correct Realm. #2277

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -95280,26 +95280,19 @@ interface <dfn>MessagePort</dfn> : <span>EventTarget</span> {
lost.</p></li>

<li>
<p>Let <var>targetRealm</var> be <var>targetPort</var>'s <span
data-x="concept-port-owner">owner</span>'s <span data-x="environment settings object's
realm">Realm</span>, if <var>targetPort</var> is non-null and <var>doomed</var> is false;
otherwise let <var>targetRealm</var> be some arbitrary Realm.</p>
<p>Let <var>targetRealm</var> be a user-agent defined Realm.</p>

<p class="note"><var>targetRealm</var> is used when cloning and transferring objects below. If
there is no target port, or if the <var>targetPort</var> is one of the objects being
transferred, the transferable objects given in the second argument, if any, are still
transferred, but since they are then discarded, it doesn't matter where they are transferred
to.)</p>
<p class="note">The <var>targetPort</var> could get transferred to a different Realm before
this message is delivered, so objects can't get cloned and transferred to the correct Realm
immediately.</p>
</li>

<li><p>Let <var>cloneRecord</var> be <span>StructuredCloneWithTransfer</span>(<var>message</var>,
<var>transfer</var>, <var>targetRealm</var>). Rethrow any exceptions.</p></li>

<li><p>Let <var>messageClone</var> be <var>cloneRecord</var>.[[Clone]].</p></li>

<li><p>Let <var>newPorts</var> be a new <span>frozen array</span> consisting of all
<code>MessagePort</code> objects in <var>cloneRecord</var>.[[TransferList]], if any, maintaining
their relative order.</p></li>
<li><p>Let <var>transferClone</var> be <var>cloneRecord</var>.[[TransferList]].</p></li>

<li><p>If there is no <var>targetPort</var> (i.e. if this <code>MessagePort</code> is not
entangled), or if <var>doomed</var> is true, then abort these steps.</p></li>
Expand All @@ -95310,14 +95303,6 @@ interface <dfn>MessagePort</dfn> : <span>EventTarget</span> {
algorithm runs scripts). We don't throw an exception for 'doomed' being true, because this can't
necessarily be detected right now every time -->

<li><p>Let <var>e</var> be the result of <span>creating an event</span> using
<code>MessageEvent</code>.</p></li>

<li><p>Initialize <var>e</var>'s <code data-x="dom-Event-type">type</code> attribute to <code
data-x="event-message">message</code>, its <code data-x="dom-MessageEvent-data">data</code>
attribute to <var>messageClone</var>, and its <code data-x="dom-MessageEvent-ports">ports</code>
attribute to <var>newPorts</var>.</p></li>

<li>
<p>Add a <span data-x="concept-task">task</span> that runs the following steps to the <span>port
message queue</span> of <var>targetPort</var>:</p>
Expand All @@ -95326,6 +95311,25 @@ interface <dfn>MessagePort</dfn> : <span>EventTarget</span> {
<li><p>Let <var>target</var> be the <code>MessagePort</code> in whose <span>port message
queue</span> the event <var>e</var> now finds itself.</p></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This e is no longer defined now. I tried to do this patch once before and this is where I got stuck.


<li><p>Let <var>targetRealm</var> be <var>target</var>'s <span>relevant settings
object</span>'s <span data-x="environment settings object's realm">Realm</span>.</p></li>

<li><p>Let <var>targetCloneRecord</var> be
<span>StructuredCloneWithTransfer</span>(<var>messageClone</var>, <var>transferClone</var>,
<var>targetRealm</var>).</p></li>

<li><p>Let <var>newPorts</var> be a new <span>frozen array</span> consisting of all
<code>MessagePort</code> objects in <var>targetCloneRecord</var>.[[TransferList]], if any,
maintaining their relative order.</p></li>

<li><p>Let <var>e</var> be the result of <span>creating an event</span> using
<code>MessageEvent</code>.</p></li>

<li><p>Initialize <var>e</var>'s <code data-x="dom-Event-type">type</code> attribute to <code
data-x="event-message">message</code>, its <code data-x="dom-MessageEvent-data">data</code>
attribute to <var>targetCloneRecord</var>.[[Clone]], and its <code data-x="dom-MessageEvent-ports">ports</code>
attribute to <var>newPorts</var>.</p></li>

<li><p><span data-x="concept-event-dispatch">Dispatch</span> <var>e</var> at
<var>target</var>.</p></li>
</ol>
Expand Down