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

Tidy up the window.postMessage algorithm further #1586

Merged
merged 5 commits into from
Jul 27, 2016
Merged
Changes from 1 commit
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
75 changes: 35 additions & 40 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -94357,9 +94357,23 @@ function receiver(e) {

<ol> <!-- a lot of this is similar or identical to port.postMessage -->

<li><p>Let <var>targetWindow</var> be this <code>Window</code> object.</p>

<li><p>Let <var>targetRealm</var> be <var>targetWindow</var>'s <span
data-x="concept-global-object-realm">Realm</span>.</p></li>

<li><p>Let <var>incumbentSettings</var> be the <span>incumbent settings object</span>.</p></li>
<!-- This is one of the few cases where incumbent is probably the right choice. Current or
relevant would mean that the MessageEvent's source property always points to the "calling"
window, in same-origin cases. See discussion at
https://github.com/whatwg/html/issues/1542#issuecomment-233502636 -->

<li><p>If <var>targetOrigin</var> is a single U+002F SOLIDUS character (/), set
Copy link
Member

Choose a reason for hiding this comment

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

then*

<var>targetOrigin</var> to <var>incumbentSettings</var>'s <span>origin</span>.</p>

<li>
<p>If the value of the <var>targetOrigin</var> argument is neither a single U+002A ASTERISK
character (*) nor a single U+002F SOLIDUS character (/), then:</p>
<p>Otherwise, if <var>targetOrigin</var> is not a single U+002A ASTERISK character (*),
then:</p>

<ol>
<li><p>Let <var>parsedURL</var> be the result of running the <span>URL parser</span> on
Expand All @@ -94373,59 +94387,40 @@ function receiver(e) {
</ol>
</li>

<li><p>Let <var>targetRealm</var> be this <code>Window</code> object's <span
data-x="concept-global-object-realm">Realm</span>.</p></li>

<li><p>Let <var>incumbentSettings</var> be the <span>incumbent settings object</span>.</p></li>
<!-- This is one of the few cases where incumbent is probably the right choice. Current or
relevant would mean that the MessageEvent's source property always points to the "calling"
window, in same-origin cases. See discussion at
https://github.com/whatwg/html/issues/1542#issuecomment-233502636 -->

<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>message clone</var> be <var>cloneRecord</var>.[[Clone]].</p></li>
<li><p>Let <var>messageClone</var> be <var>cloneRecord</var>.[[Clone]].</p></li>

<li><p>Let <var>new ports</var> be a new <span>frozen array</span> consisting of all
<li><p>Let <var>newPorts</var> be a new <span>frozen array</span> consisting of all
Copy link
Member

Choose a reason for hiding this comment

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

If you're changing these steps we should maybe also update the corresponding steps in dom-MessagePort-postMessage

<code>MessagePort</code> objects in <var>cloneRecord</var>.[[TransferList]], if any, maintaining
their relative order.</p></li>

<li><p>Return, but continue running these steps in <span>in parallel</span>.</p></li>

<li>
<p>If the <var>targetOrigin</var> argument is a single literal U+002F SOLIDUS character (/), and
this <code>Window</code> object's <span data-x="concept-document-window">associated
<code>Document</code></span>'s <span>origin</span> is not <span>same origin</span> with
<var>incumbentSettings</var>'s <span>responsible document</span>'s <span>origin</span>, then
abort these steps.</p>

<p>Otherwise, if the <var>targetOrigin</var> argument is not a single literal U+002A ASTERISK
character (*) and this <code>Window</code> object's <span
data-x="concept-document-window">associated <code>Document</code></span>'s <span>origin</span>
is not <span>same origin</span> with <var>targetOrigin</var>, then abort these steps.</p>
</li>
<li><p>If the <var>targetOrigin</var> argument is not a single literal U+002A ASTERISK character
(*) and <var>targetWindow</var>'s <span data-x="concept-document-window">associated
<code>Document</code></span>'s <span>origin</span> is not <span>same origin</span> with
<var>targetOrigin</var>, then abort these steps.</p></li>

<li><p>Create a <span data-x="concept-events-trusted">trusted</span> event that uses the
<code>MessageEvent</code> interface, with the event type <code
data-x="event-message">message</code>, which does not bubble, is not cancelable, and has no
default action. The <code data-x="dom-MessageEvent-data">data</code> attribute must be
initialised to the value of <var>message clone</var>, the <code
data-x="dom-MessageEvent-origin">origin</code> attribute must be initialised to the <span
data-x="Unicode serialisation of an origin">Unicode serialisation</span> of the
<span>origin</span> specified by <var>incumbentSettings</var>, the <code
data-x="event-message">message</code>, which does not bubble and is not cancelable. The <code
data-x="dom-MessageEvent-data">data</code> attribute must be initialised to
<var>messageClone</var>, the <code data-x="dom-MessageEvent-origin">origin</code> attribute must
be initialised to the <span data-x="Unicode serialisation of an origin">Unicode
serialisation</span> of <var>incumbentSettings</var>'s <span>origin</span>, the <code
data-x="dom-MessageEvent-source">source</code> attribute must be initialised to the
<code>WindowProxy</code> object corresponding to the <span
data-x="concept-settings-object-global">global object</span> (a <code>Window</code> object)
specified by <var>incumbentSettings</var>, and the <code
data-x="dom-MessageEvent-ports">ports</code> attribute must be initialised to the <var>new
ports</var> array.</p></li> <!-- invariant: the global object is always a Window if the script
can see this method -->
<code>WindowProxy</code> object corresponding <var>incumbentSettings</var>'s <span
data-x="concept-settings-object-global">global object</span> (a <code>Window</code> object), and
the <code data-x="dom-MessageEvent-ports">ports</code> attribute must be initialised to
<var>newPorts</var>.</p></li> <!-- invariant: the global object is always a Window if the
script can see this method -->

<li><p><span>Queue a task</span> to <span data-x="concept-event-dispatch">dispatch</span> the
event created in the previous step at the <code>Window</code> object on which the method was
invoked. The <span>task source</span> for this <span data-x="concept-task">task</span> is the
<span>posted message task source</span>.</p></li>
event created in the previous step at <var>targetWindow</var>. The <span>task source</span> for
this <span data-x="concept-task">task</span> is the <span>posted message task
source</span>.</p></li>

</ol>

Expand Down