From d00b810aeccf9a272b17400ed3daed7f100adec1 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Thu, 15 Sep 2016 10:33:03 -0400 Subject: [PATCH] Clear the custom element reaction queue if upgrading fails Fixes https://github.com/w3c/webcomponents/issues/563, and an analogous issue when the constructor uses return-override, by ensuring that all exceptions go through the same path, which both sets the custom element state to "failed", and clears the custom element reaction queue. --- source | 84 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/source b/source index db742fa340d..f86b22ef516 100644 --- a/source +++ b/source @@ -66692,62 +66692,64 @@ customElements.define("x-foo", class extends HTMLElement { data-x="concept-custom-element-definition-constructor">constructor.

  • -

    Let constructResult be Construct(C).

    +

    Run the following substeps while catching any exceptions:

    -

    If C non-conformantly uses - an API decorated with the [CEReactions] extended attribute, - then the reactions enqueued at the beginning of this algorithm will execute during this step, - before C finishes and control returns to this algorithm. Otherwise, they will execute - after C and the rest of the upgrade process finishes.

    -
  • +
      +
    1. +

      Let constructResult be Construct(C).

      -
    2. -

      Remove the last entry from the end of definition's construction stack.

      +

      If C non-conformantly + uses an API decorated with the [CEReactions] extended + attribute, then the reactions enqueued at the beginning of this algorithm will execute during + this step, before C finishes and control returns to this algorithm. Otherwise, they + will execute after C and the rest of the upgrade process finishes.

      +
    3. -
      -

      Assuming C calls super() (as it will if it is conformant), and that the call succeeds, this will be - the already - constructed marker that replaced the element we pushed at the beginning - of this algorithm. (The HTML element constructor - carries out this replacement.)

      - -

      If C does not call super() (i.e. it is not conformant), or if any step in the HTML element constructor throws, then this entry will - still be element.

      -
      - +
    4. +

      If SameValue(constructResult, element) is false, + then throw an "InvalidStateError" DOMException.

      -
    5. -

      If constructResult is an abrupt completion, then:

      +

      This can occur if C constructs another instance of the same custom + element before calling super(), or if C uses JavaScript's + return-override feature to return an arbitrary object from the + constructor.

      +
    6. +
    + +

    Then, perform the following substep, regardless of whether the above steps threw an exception + or not:

      -
    1. Set element's custom element state to "failed".

    2. +
    3. +

      Remove the last entry from the end of definition's construction stack.

      -
    4. Return constructResult (i.e., rethrow the exception), and terminate these - steps.

    5. +
      +

      Assuming C calls super() (as it will if it is conformant), and that the call succeeds, this will be + the already + constructed marker that replaced the element we pushed at the beginning + of this algorithm. (The HTML element constructor + carries out this replacement.)

      + +

      If C does not call super() (i.e. it is not conformant), or if any step in the HTML element constructor throws, then this entry will + still be element.

      +
      +
    - -
  • -

    If SameValue(constructResult.[[value]], element) is false, - then:

    +

    Finally, if the above steps threw an exception, then:

    1. Set element's custom element state to "failed".

    2. -
    3. Throw an "InvalidStateError" DOMException, and - terminate these steps.

    4. -
    +
  • Empty element's custom element reaction queue.

    -

    This can occur if C constructs another instance of the same custom - element before calling super(), or if C uses JavaScript's - return-override feature to return an arbitrary object from the - constructor.

    +
  • Rethrow the exception, and terminate this algorithm.

  • +
  • Set element's custom element state to "