Skip to content

Commit

Permalink
Add conformance requirements for custom element constructors
Browse files Browse the repository at this point in the history
Fixes #409.
  • Loading branch information
domenic committed Mar 11, 2016
1 parent a5df449 commit 00ed64f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions spec/custom/index.html
Expand Up @@ -749,6 +749,19 @@ <h3>DOM+: New <a href="https://dom.spec.whatwg.org/#document"><code>Document</co
<p>Notably, all the of the ways in which <a href="https://html.spec.whatwg.org/#the-button-element"><code>button</code></a> is special apply to such "plastic buttons" as well: their focus behavior, ability to participate in <a href="https://html.spec.whatwg.org/#form-submission-2">form submission</a>, the <a href="https://html.spec.whatwg.org/#attr-fe-disabled"><code>disabled</code></a> attribute, and so on.</p>
</div>

<p class="monkeypatch">This may belong in HTML, not DOM? Part of the semantics section?</p>

<p>When authoring <a>custom element constructors</a>, developers are bound by the following <a href="https://html.spec.whatwg.org/#conformance-requirements-for-authors">conformance requirements</a>:</p>

<ul>
<li>A parameter-less call to <code>super()</code> must be the first statement in the constructor body, to establish the correct prototype chain and <code>this</code> value before any further code is run.</li>
<li>A <code>return</code> statement must not appear anywhere inside the constructor body.</li>

This comment has been minimized.

Copy link
@rniwa

rniwa Mar 11, 2016

Collaborator

I think this is too strong of a requirement. It's fine to do return this or even return after calling super() as that would default to returning this. What we need instead is to not return any other object but the one created by the super() call.

This comment has been minimized.

Copy link
@domenic

domenic Mar 11, 2016

Author Collaborator

Thanks for catching; early-return is indeed reasonable.

<li>The element's attributes and children must not be inspected, as in the non-<a lt="upgrade a custom element">upgrade</a> case none will be present, and relying on upgrades makes the element less usable.</li>
<li>The element must not gain any attributes or children, as this violates the expectations of consumers who use the <a href="https://dom.spec.whatwg.org/#dom-document-createelement"><code>createElement</code></a> or <a href="https://dom.spec.whatwg.org/#dom-document-createelementns"><code>createElementNS</code></a> methods.</li>
<li>In general, work should be deferred to <code>attachedCallback</code> as much as possible—especially work involving fetching resources or rendering.</li>
<li>In general, the constructor should be used to set up initial state and default values.</li>
</ul>

</section>
</section>
<section id="instantiating-custom-elements">
Expand Down

0 comments on commit 00ed64f

Please sign in to comment.