From 70ec265b9ca766836d22bd76f6062b7d66e67950 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 21 Mar 2016 14:20:03 -0400 Subject: [PATCH] Add checks on custom element constructor return values Closes #412. --- spec/custom/index.html | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/spec/custom/index.html b/spec/custom/index.html index 7e323882..21681705 100644 --- a/spec/custom/index.html +++ b/spec/custom/index.html @@ -255,6 +255,9 @@

Requirements for custom element constructors
  • In general, work should be deferred to connectedCallback as much as possible—especially work involving fetching resources or rendering. However, note that connectedCallback can be called more than once, so any initialization work that is truly one-time will need a guard to prevent it from running twice.
  • In general, the constructor should be used to set up initial state and default values, and to set up event listeners.
  • + +

    Several of these requirements are checked during element creation, either directly or indirectly, and failing to follow them will result in a custom element that cannot be instantiated by the parser or DOM APIs.

    +
    @@ -531,9 +534,9 @@

    DOM+: Elements

    If typeExtension is not null:

      -
    1. If registry is null, throw a NotSupportedError and abort these steps.
    2. +
    3. If registry is null, throw a NotSupportedError exception.
    4. -
    5. If namespace is not the HTML namespace, throw a TypeError exception and abort these steps.
    6. +
    7. If namespace is not the HTML namespace, throw a TypeError exception.
    8. Let interface be the element interface for localName and the HTML namespace.
    9. @@ -541,7 +544,7 @@

      DOM+: Elements

      If there is an the entry in registry with name typeExtension, let definition be that entry, and perform the following subsubsteps:

        -
      1. If definition's local name is not localName, throw a TypeError exception and abort these steps.
      2. +
      3. If definition's local name is not localName, throw a TypeError exception.
      4. Let result be a new element that implements interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix, local name set to localName, defined flag unset, and node document set to document.
      5. @@ -582,11 +585,27 @@

        DOM+: Elements

      6. Let result be Construct(C). Rethrow any exceptions.
      7. -

        If result does not implement the HTMLElement interface, throw a TypeError exception and abort these steps.

        +

        If result does not implement the HTMLElement interface, throw a TypeError exception.

        This is meant to be a brand check to ensure that the object was allocated by the HTMLElement constructor. Eventually Web IDL may give us a more precise way to do brand checks.

      8. +
      9. If the value of result's [[\Prototype]] internal slot is not equal to definition's prototype, throw a TypeError exception.
      10. + +
      11. If result's attribute list is not empty, throw a NotSupportedError exception.
      12. + +
      13. If result has children, throw a NotSupportedError exception.
      14. + +
      15. If result's parent is not null, throw a NotSupportedError exception.
      16. + +
      17. If result's node document is not document, throw a NotSupportedError exception.
      18. + +
      19. If result's namespace is not the HTML namespace, throw a NotSupportedError exception.
      20. + +
      21. If result's local name is not localName, throw a NotSupportedError exception.
      22. + +
      23. Set result's namespace prefix to prefix.
      24. +
      25. Set result's defined flag.
      26. Return result.