Skip to content
Permalink
Browse files

Cross-origin objects: do not wrap JavaScript functions

Instead, carefully refer to the original algorithm and use that.
Otherwise we confuse the globals.

This can become more formalized once IDL generates an abstract
operation for each member of an object.

Fixes #1436.
  • Loading branch information...
annevk authored and domenic committed Jun 21, 2016
1 parent c2a8d60 commit db361b608157b5cf9fd0d491d7dc76cdce80380b
Showing with 42 additions and 74 deletions.
  1. +42 −74 source
116 source
<li><p>Let <var>originalDesc</var> be <span>OrdinaryGetOwnProperty</span>(<var>O</var>,
<var>P</var>).</p></li>

<li><p>Let <var>crossOriginDesc</var> be
<span>CrossOriginPropertyDescriptor</span>(<var>e</var>, <var>originalDesc</var>).</p></li>
<li><p>Let <var>crossOriginDesc</var> be undefined.</p></li>

<li><p>Create an entry in the value of the [[<span>CrossOriginPropertyDescriptorMap</span>]]
internal slot of <var>O</var> with key <var>crossOriginKey</var> and value
<var>crossOriginDesc</var>.</p></li>
<li>
<p>If <var>e</var>.[[NeedsGet]] and <var>e</var>.[[NeedsSet]] are absent, then:</p>

<li><p>Return <var>crossOriginDesc</var>.</p></li>
</ol>
</li>
</ol>
</li>
<ol>
<li><p>Let <var>value</var> be <var>originalDesc</var>.[[Value]].</p></li>

<li><p>Return undefined.</p></li>
</ol>
<li><p>If <span>IsCallable</span>(<var>value</var>) is true, then set <var>value</var> to
an anonymous built-in function, created in the <span>current Realm Record</span>, that
performs the same steps as the IDL operation <var>P</var> on object <var>O</var>.</p></li>

<h6><dfn>CrossOriginPropertyDescriptor</dfn> ( <var>crossOriginProperty</var>,
<var>originalDesc</var> )</h6>
<li><p>Set <var>crossOriginDesc</var> to <span>PropertyDescriptor</span>{
[[Value]]: <var>value</var>,
[[Enumerable]]: false,
[[Writable]]: false,
[[Configurable]]: true }.</p></li>
</ol>
</li>

<ol>
<li>
<p>If <var>crossOriginProperty</var>.[[NeedsGet]] and
<var>crossOriginProperty</var>.[[NeedsSet]] are absent, then:</p>
<li>
<p>Otherwise:</p>

<ol>
<li><p>Let <var>value</var> be <var>originalDesc</var>.[[Value]].</p></li>
<ol>
<li><p>Let <var>crossOriginGet</var> be undefined.</p></li>

<li><p>If <span>IsCallable</span>(<var>value</var>) is true, set <var>value</var> to
<span>CrossOriginFunctionWrapper</span>(true, <var>value</var>).</p></li>
<li><p>If <var>e</var>.[[NeedsGet]] is true, then set <var>crossOriginGet</var> to an
anonymous built-in function, created in the <span>current Realm Record</span>, that
performs the same steps as the getter of the IDL attribute <var>P</var> on object
<var>O</var>.</p></li>

<li><p>Return <span>PropertyDescriptor</span>{
[[Value]]: <var>value</var>,
[[Enumerable]]: false,
[[Writable]]: false,
[[Configurable]]: true }.</p></li>
</ol>
</li>
<li><p>Let <var>crossOriginSet</var> be undefined.</p></li>

<li>
<p>Otherwise:</p>
<li><p>If <var>e</var>.[[NeedsSet]] is true, then set <var>crossOriginSet</var> to an
anonymous built-in function, created in the <span>current Realm Record</span>, that
performs the same steps as the setter of the IDL attribute <var>P</var> on object
<var>O</var>.</p></li>

<ol>
<li><p>Let <var>crossOriginGet</var> be
<span>CrossOriginFunctionWrapper</span>(<var>crossOriginProperty</var>.[[NeedsGet]],
<var>originalDesc</var>.[[Get]]).</p></li>
<li><p>Set <var>crossOriginDesc</var> to <span>PropertyDescriptor</span>{
[[Get]]: <var>crossOriginGet</var>,
[[Set]]: <var>crossOriginSet</var>,
[[Enumerable]]: false,
[[Configurable]]: true }.</p></li>
</ol>
</li>

<li><p>Let <var>crossOriginSet</var> be
<span>CrossOriginFunctionWrapper</span>(<var>crossOriginProperty</var>.[[NeedsSet]],
<var>originalDesc</var>.[[Set]]).</p></li>
<li><p>Create an entry in the value of the [[<span>CrossOriginPropertyDescriptorMap</span>]]
internal slot of <var>O</var> with key <var>crossOriginKey</var> and value
<var>crossOriginDesc</var>.</p></li>

<li><p>Return <span>PropertyDescriptor</span>{
[[Get]]: <var>crossOriginGet</var>,
[[Set]]: <var>crossOriginSet</var>,
[[Enumerable]]: false,
[[Configurable]]: true }.</p></li>
<li><p>Return <var>crossOriginDesc</var>.</p></li>
</ol>
</li>
</ol>
</li>
</ol>

<h6><dfn>CrossOriginFunctionWrapper</dfn> ( <var>needsWrapping</var>, <var>functionToWrap</var>
)</h6>

<ol>
<li><p>If <var>needsWrapping</var> is false, then return undefined.</p></li>

<li><p>Return a new <span>cross-origin wrapper function</span> whose [[Wrapped]] internal slot is
<var>functionToWrap</var>.</p></li>
</ol>

<hr>

<p>A <dfn>cross-origin wrapper function</dfn> is an anonymous built-in function that has a
[[Wrapped]] internal slot.</p>

<p>When a <span>cross-origin wrapper function</span> <var>F</var> is called with a list of
arguments <var>argumentsList</var>, the following steps are taken:</p>

<ol>
<li><p>Assert: <var>F</var> has a [[Wrapped]] internal slot that is a function.</p></li>

<li><p>Let <var>wrappedFunction</var> be the [[Wrapped]] internal slot of <var>F</var>.</p></li>

<li><p>Return ? <span>Call</span>(<var>wrappedFunction</var>, <b>this</b>,
<var>argumentsList</var>).</p></li>
<li><p>Return undefined.</p></li>
</ol>

<p class="note">Due to this being invoked from a different <span>origin</span>, a
<span>cross-origin wrapper function</span> will have a different value for
<code data-x="">Function.prototype</code> from the function being wrapped. This follows from how
JavaScript creates anonymous built-in functions.</p>

<h5><dfn>CrossOriginGet</dfn> ( <var>O</var>, <var>P</var>, <var>Receiver</var> )</h5>

<ol>

0 comments on commit db361b6

Please sign in to comment.
You can’t perform that action at this time.