Skip to content

Commit

Permalink
Change createElement to report exceptions instead of rethrowing
Browse files Browse the repository at this point in the history
Such exceptions can occur due to custom element constructors or invariant checks. This closes WICG/webcomponents#569 by moving the catch-and-return-HTMLUnknownElement from HTML to DOM; HTML will subsequently be updated to remove that logic.
  • Loading branch information
domenic authored and annevk committed Oct 11, 2016
1 parent 17f5118 commit eb28710
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
25 changes: 19 additions & 6 deletions dom.bs
Expand Up @@ -5668,7 +5668,8 @@ given a <var>document</var>, <var>localName</var>, <var>namespace</var>, and opt

<ol>
<li>
<p>If the <var>synchronous custom elements flag</var> is set:
<p>If the <var>synchronous custom elements flag</var> is set, then run these subsubsteps while
catching any exceptions:

<ol>
<li><p>Let <var>C</var> be <var>definition</var>'s
Expand All @@ -5678,14 +5679,13 @@ given a <var>document</var>, <var>localName</var>, <var>namespace</var>, and opt
exceptions.

<li>
<p>If <var>result</var> does not implement the {{HTMLElement}} interface, <a>throw</a> a
<p>If <var>result</var> does not implement the {{HTMLElement}} interface, then <a>throw</a> a
<code>TypeError</code>.

<div class=note>
<p>This is meant to be a brand check to ensure that the object was allocated by the
a HTML element constructor. See
<a href="https://github.com/heycam/webidl/issues/97">webidl #97</a> about making this more
precise.
<p>This is meant to be a brand check to ensure that the object was allocated by the HTML
element constructor. See <a href="https://github.com/heycam/webidl/issues/97">webidl #97</a>
about making this more precise.

<p>If this check passes, then <var>result</var> will already have its <a>custom element
state</a> and <a>custom element definition</a> initialized.
Expand Down Expand Up @@ -5721,6 +5721,19 @@ given a <var>document</var>, <var>localName</var>, <var>namespace</var>, and opt

<li><p>Set <var>result</var>'s <a><code>is</code> value</a> to null.
</ol>

<p>If any of these subsubsteps threw an exception, then:</p>

<ol>
<li><p><a>Report the exception</a>.

<li><p>Set <var>result</var> to a new <a for=/>element</a> that implements the
{{HTMLUnknownElement}} interface, with no attributes, <a for=Element>namespace</a> set to the
<a>HTML namespace</a>, <a for=Element>namespace prefix</a> set to <var>prefix</var>,
<a for=Element>local name</a> set to <var>localName</var>, <a>custom element state</a> set to
"<code>failed</code>", <a>custom element definition</a> set to null,
<a><code>is</code> value</a> set to null, and <a>node document</a> set to <var>document</var>.
</ol>
</li>

<li>
Expand Down
21 changes: 15 additions & 6 deletions dom.html
Expand Up @@ -71,7 +71,7 @@
<p data-fill-with="logo"><a class="logo" href="https://whatwg.org/"> <img alt="WHATWG" height="100" src="https://resources.whatwg.org/logo-dom.svg"> </a> </p>
<hgroup>
<h1 class="p-name no-ref allcaps" id="title">DOM</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard — Last Updated <time class="dt-updated" datetime="2016-10-10">10 October 2016</time></span></h2>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard — Last Updated <time class="dt-updated" datetime="2016-10-11">11 October 2016</time></span></h2>
</hgroup>
<div data-fill-with="spec-metadata">
<dl>
Expand Down Expand Up @@ -3544,19 +3544,19 @@ <h3 class="heading settled" data-level="4.9" id="interface-element"><span class=
<p>Otherwise, if <var>definition</var> is non-null, then: </p>
<ol>
<li>
<p>If the <var>synchronous custom elements flag</var> is set: </p>
<p>If the <var>synchronous custom elements flag</var> is set, then run these subsubsteps while
catching any exceptions: </p>
<ol>
<li>
<p>Let <var>C</var> be <var>definition</var>’s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/scripting.html#concept-custom-element-definition-constructor">constructor</a>. </p>
<li>
<p>Set <var>result</var> to <a data-link-type="abstract-op" href="https://tc39.github.io/ecma262/#sec-construct">Construct</a>(<var>C</var>). Rethrow any
exceptions. </p>
<li>
<p>If <var>result</var> does not implement the <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/dom.html#htmlelement">HTMLElement</a></code> interface, <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code>TypeError</code>. </p>
<p>If <var>result</var> does not implement the <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/dom.html#htmlelement">HTMLElement</a></code> interface, then <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code>TypeError</code>. </p>
<div class="note" role="note">
<p>This is meant to be a brand check to ensure that the object was allocated by the
a HTML element constructor. See <a href="https://github.com/heycam/webidl/issues/97">webidl #97</a> about making this more
precise. </p>
<p>This is meant to be a brand check to ensure that the object was allocated by the HTML
element constructor. See <a href="https://github.com/heycam/webidl/issues/97">webidl #97</a> about making this more precise. </p>
<p>If this check passes, then <var>result</var> will already have its <a data-link-type="dfn" href="#concept-element-custom-element-state">custom element
state</a> and <a data-link-type="dfn" href="#concept-element-custom-element-definition">custom element definition</a> initialized. </p>
</div>
Expand All @@ -3582,6 +3582,14 @@ <h3 class="heading settled" data-level="4.9" id="interface-element"><span class=
<li>
<p>Set <var>result</var>’s <a data-link-type="dfn" href="#concept-element-is-value"><code>is</code> value</a> to null. </p>
</ol>
<p>If any of these subsubsteps threw an exception, then:</p>
<ol>
<li>
<p><a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#report-the-exception">Report the exception</a>. </p>
<li>
<p>Set <var>result</var> to a new <a data-link-type="dfn" href="#concept-element">element</a> that implements the <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/dom.html#htmlunknownelement">HTMLUnknownElement</a></code> interface, with no attributes, <a data-link-type="dfn" href="#concept-element-namespace">namespace</a> set to the <a data-link-type="dfn" href="#html-namespace">HTML namespace</a>, <a data-link-type="dfn" href="#concept-element-namespace-prefix">namespace prefix</a> set to <var>prefix</var>, <a data-link-type="dfn" href="#concept-element-local-name">local name</a> set to <var>localName</var>, <a data-link-type="dfn" href="#concept-element-custom-element-state">custom element state</a> set to
"<code>failed</code>", <a data-link-type="dfn" href="#concept-element-custom-element-definition">custom element definition</a> set to null, <a data-link-type="dfn" href="#concept-element-is-value"><code>is</code> value</a> set to null, and <a data-link-type="dfn" href="#concept-node-document">node document</a> set to <var>document</var>. </p>
</ol>
<li>
<p>Otherwise: </p>
<ol>
Expand Down Expand Up @@ -6494,6 +6502,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span cla
<li><a href="https://html.spec.whatwg.org/multipage/dom.html#htmlelement">HTMLElement</a>
<li><a href="https://html.spec.whatwg.org/multipage/semantics.html#htmlhtmlelement">HTMLHtmlElement</a>
<li><a href="https://html.spec.whatwg.org/multipage/scripting.html#htmlslotelement">HTMLSlotElement</a>
<li><a href="https://html.spec.whatwg.org/multipage/dom.html#htmlunknownelement">HTMLUnknownElement</a>
<li><a href="https://html.spec.whatwg.org/multipage/browsers.html#hashchangeevent">HashChangeEvent</a>
<li><a href="https://html.spec.whatwg.org/multipage/comms.html#messageevent">MessageEvent</a>
<li><a href="https://html.spec.whatwg.org/multipage/browsers.html#pagetransitionevent">PageTransitionEvent</a>
Expand Down

0 comments on commit eb28710

Please sign in to comment.