Skip to content

Commit

Permalink
Convert custom element callbacks to Web IDL callback types
Browse files Browse the repository at this point in the history
This ensures that the incumbent global is correctly set up when calling
them. We also remove the redundant "prepare to run script" and "clean
up after running script" in the element definition algorithm, since
element definition happens synchronously from user code.

Part of whatwg#855.
  • Loading branch information
domenic authored and Alice Boxhall committed Jan 7, 2019
1 parent 6ec18d2 commit f773299
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2917,8 +2917,8 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
<li><dfn data-noexport="" data-x="idl-ArrayBufferView" data-x-href="https://heycam.github.io/webidl/#common-ArrayBufferView"><code>ArrayBufferView</code></dfn>
<li><dfn data-noexport="" data-x="idl-boolean" data-x-href="https://heycam.github.io/webidl/#idl-boolean"><code>boolean</code></dfn>
<li><dfn data-noexport="" data-x="idl-DOMString" data-x-href="https://heycam.github.io/webidl/#idl-DOMString"><code>DOMString</code></dfn>
<li><dfn data-noexport="" data-x="idl-USVString" data-x-href="https://heycam.github.io/webidl/#idl-USVString"><code>USVString</code></dfn>
<li><dfn data-noexport="" data-x="idl-double" data-x-href="https://heycam.github.io/webidl/#idl-double"><code>double</code></dfn>
<li><dfn data-noexport="" data-x="IDL enumeration" data-x-href="https://heycam.github.io/webidl/#idl-enums">enumeration</dfn>
<li><dfn data-noexport="" data-x="idl-Error" data-x-href="https://heycam.github.io/webidl/#idl-Error"><code>Error</code></dfn>
<li><dfn data-noexport="" data-x="idl-Function" data-x-href="https://heycam.github.io/webidl/#common-Function"><code>Function</code></dfn>
<li><dfn data-noexport="" data-x="idl-long" data-x-href="https://heycam.github.io/webidl/#idl-long"><code>long</code></dfn>
Expand All @@ -2927,7 +2927,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
<li><dfn data-noexport="" data-x="idl-Uint8ClampedArray" data-x-href="https://heycam.github.io/webidl/#idl-Uint8ClampedArray"><code>Uint8ClampedArray</code></dfn>
<li><dfn data-noexport="" data-x="idl-unrestricted-double" data-x-href="https://heycam.github.io/webidl/#idl-unrestricted-double"><code>unrestricted double</code></dfn>
<li><dfn data-noexport="" data-x="idl-unsigned-long" data-x-href="https://heycam.github.io/webidl/#idl-unsigned-long"><code>unsigned long</code></dfn>
<li><dfn data-noexport="" data-x="IDL enumeration" data-x-href="https://heycam.github.io/webidl/#idl-enums">enumeration</dfn>
<li><dfn data-noexport="" data-x="idl-USVString" data-x-href="https://heycam.github.io/webidl/#idl-USVString"><code>USVString</code></dfn>

</ul>

Expand Down Expand Up @@ -66330,8 +66330,9 @@ console.log(plasticButton2.getAttribute("is")); // will output "plastic-button"<
data-x="concept-custom-element-definition-lifecycle-callbacks">lifecycle callbacks</dfn></dt>
<dd>A map, whose three keys are the strings "<code data-x="">connectedCallback</code>",
"<code data-x="">disconnectedCallback</code>", and "<code
data-x="">attributeChangedCallback</code>". The corresponding values are either a JavaScript
function object, or undefined. By default the value of each entry is undefined.</dd>
data-x="">attributeChangedCallback</code>". The corresponding values are either a Web IDL
<code data-x="idl-Function">Function</code> callback function type value, or null. By default the
value of each entry is null.</dd>

<dt>A <dfn data-x="concept-custom-element-definition-construction-stack">construction
stack</dfn></dt>
Expand Down Expand Up @@ -66534,8 +66535,6 @@ dictionary <dfn>ElementDefinitionOptions</dfn> {
<li><p>Add <var>constructor</var> to this <code>CustomElementsRegistry</code>'s <span>set of
being-defined constructors</span>.</p></li>

<li><p><span>Prepare to run script</span> with the <span>current settings object</span>.</p></li>

<li>
<p>Run the following substeps while catching any exceptions:</p>

Expand All @@ -66546,35 +66545,44 @@ dictionary <dfn>ElementDefinitionOptions</dfn> {
<li><p>If <span data-x="js-Type">Type</span>(<var>prototype</var>) is not Object, then throw a
<code>TypeError</code> exception.</p></li>

<li><p>Let <var>connectedCallback</var> be <span data-x="js-Get">Get</span>(<var>prototype</var>,
"connectedCallback"). Rethrow any exceptions.</p></li>
<li><p>Let <var>connectedCallback</var>, <var>disconnectedCallback</var>, and
<var>attributeChangedCallback</var> be null.</p>

<li><p>If <var>connectedCallback</var> is not undefined, and
<span>IsCallable</span>(<var>connectedCallback</var>) is false, then throw a
<code>TypeError</code> exception.</p></li>
<li><p>Let <var>connectedCallbackValue</var> be <span
data-x="js-Get">Get</span>(<var>prototype</var>, "connectedCallback"). Rethrow any
exceptions.</p></li>

<li><p>Let <var>disconnectedCallback</var> be <span
<li><p>If <var>connectedCallbackValue</var> is not undefined, then set
<var>connectedCallback</var> to the result of <span
data-x="concept-idl-convert">converting</span> <var>connectedCallbackValue</var> to the Web IDL
<code data-x="idl-Function">Function</code> callback type. Rethrow any exceptions.</p></li>

<li><p>Let <var>disconnectedCallbackValue</var> be <span
data-x="js-Get">Get</span>(<var>prototype</var>, "disconnectedCallback"). Rethrow any
exceptions.</p></li>

<li><p>If <var>disconnectedCallback</var> is not undefined, and
<span>IsCallable</span>(<var>disconnectedCallback</var>) is false, then throw a
<code>TypeError</code> exception.</p></li>
<li><p>If <var>disconnectedCallbackValue</var> is not undefined, then set
<var>disconnectedCallback</var> to the result of <span
data-x="concept-idl-convert">converting</span> <var>disconnectedCallbackValue</var> to the Web
IDL <code data-x="idl-Function">Function</code> callback type. Rethrow any exceptions.</p></li>

<li><p>Let <var>attributeChangedCallback</var> be <span
<li><p>Let <var>attributeChangedCallbackValue</var> be <span
data-x="js-Get">Get</span>(<var>prototype</var>, "attributeChangedCallback"). Rethrow any
exceptions.</p></li>

<li><p>If <var>attributeChangedCallbackValue</var> is not undefined, then set
<var>attributeChangedCallback</var> to the result of <span
data-x="concept-idl-convert">converting</span> <var>attributeChangedCallbackValue</var> to the
Web IDL <code data-x="idl-Function">Function</code> callback type. Rethrow any
exceptions.</p></li>

<li><p>Let <var>observedAttributes</var> be an empty <code
data-x="">sequence&lt;DOMString></code>.</p></li>

<li>
<p>If <var>attributeChangedCallback</var> is not undefined, then:</p>
<p>If <var>attributeChangedCallback</var> is not null, then:</p>

<ol>
<li><p>If <span>IsCallable</span>(<var>attributeChangedCallback</var>) is false, then throw
a <code>TypeError</code> exception.</p></li>

<li><p>Let <var>observedAttributesIterable</var> be <span
data-x="js-Get">Get</span>(<var>constructor</var>, "observedAttributes"). Rethrow any
exceptions.</p></li>
Expand All @@ -66590,9 +66598,6 @@ dictionary <dfn>ElementDefinitionOptions</dfn> {
exception or not:</p>

<ol>
<li><p><span>Clean up after running script</span> with the <span>current settings
object</span>.</p></li>

<li><p>Remove <var>name</var> from this <code>CustomElementsRegistry</code>'s <span>set of
being-defined names</span>.</p></li>

Expand Down Expand Up @@ -66964,7 +66969,7 @@ customElements.define("x-foo", class extends HTMLElement {
data-x="concept-custom-element-definition-lifecycle-callbacks">lifecycle callbacks</span> with
key <var>callbackName</var>.</p></li>

<li><p>If <var>callback</var> is undefined, then abort these steps.</p></li>
<li><p>If <var>callback</var> is null, then abort these steps.</p></li>

<li>
<p>If <var>callbackName</var> is "<code data-x="">attributeChangedCallback</code>", then:</p>
Expand Down

0 comments on commit f773299

Please sign in to comment.