⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 244293 in webkit


Ignore:
Timestamp:
Apr 15, 2019, 2:49:06 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

Throw TypeError when custom element constructor returns a wrong element or tries to create itself
https://bugs.webkit.org/show_bug.cgi?id=196892

Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

Update the tests according to https://github.com/web-platform-tests/wpt/pull/16328.

  • web-platform-tests/custom-elements/upgrading/Node-cloneNode-expected.txt:
  • web-platform-tests/custom-elements/upgrading/Node-cloneNode.html:
  • web-platform-tests/custom-elements/upgrading/upgrading-parser-created-element-expected.txt:
  • web-platform-tests/custom-elements/upgrading/upgrading-parser-created-element.html:

Source/WebCore:

Throw TypeError instead of InvalidStateError for consistency. This updates WebKit's custom elements
implementation for https://github.com/whatwg/html/pull/4525.

Tests: imported/w3c/web-platform-tests/custom-elements/upgrading/Node-cloneNode.html

imported/w3c/web-platform-tests/custom-elements/upgrading/upgrading-parser-created-element.html

  • bindings/js/JSCustomElementInterface.cpp:

(WebCore::JSCustomElementInterface::upgradeElement):

  • bindings/js/JSHTMLElementCustom.cpp:

(WebCore::constructJSHTMLElement):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r244216 r244293  
     12019-04-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Throw TypeError when custom element constructor returns a wrong element or tries to create itself
     4        https://bugs.webkit.org/show_bug.cgi?id=196892
     5
     6        Reviewed by Dean Jackson.
     7
     8        Update the tests according to https://github.com/web-platform-tests/wpt/pull/16328.
     9
     10        * web-platform-tests/custom-elements/upgrading/Node-cloneNode-expected.txt:
     11        * web-platform-tests/custom-elements/upgrading/Node-cloneNode.html:
     12        * web-platform-tests/custom-elements/upgrading/upgrading-parser-created-element-expected.txt:
     13        * web-platform-tests/custom-elements/upgrading/upgrading-parser-created-element.html:
     14
    1152019-04-12  Rob Buis  <rbuis@igalia.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/upgrading/Node-cloneNode-expected.txt

    r230330 r244293  
    66PASS Node.prototype.cloneNode(true) must be able to clone a descendent custom element
    77PASS Node.prototype.cloneNode(true) must set parentNode, previousSibling, and nextSibling before upgrading custom elements
    8 PASS HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself after super() call
    9 PASS HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself before super() call
    10 PASS Upgrading a custom element must throw InvalidStateError when the custom element's constructor returns another element
     8PASS HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself after super() call
     9PASS HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself before super() call
     10PASS Upgrading a custom element must throw TypeError when the custom element's constructor returns another element
    1111PASS Inserting an element must not try to upgrade a custom element when it had already failed to upgrade once
    1212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/upgrading/Node-cloneNode.html

    r230330 r244293  
    166166    window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
    167167    instance.cloneNode(false);
    168     assert_equals(uncaughtError.name, 'InvalidStateError');
    169 }, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
     168    assert_equals(uncaughtError.name, 'TypeError');
     169}, 'HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed'
    170170    + ' due to a custom element constructor constructing itself after super() call');
    171171
     
    184184    window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
    185185    instance.cloneNode(false);
    186     assert_equals(uncaughtError.name, 'InvalidStateError');
    187 }, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
     186    assert_equals(uncaughtError.name, 'TypeError');
     187}, 'HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed'
    188188    + ' due to a custom element constructor constructing itself before super() call');
    189189
     
    204204    window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
    205205    instance.cloneNode(false);
    206     assert_equals(uncaughtError.name, 'InvalidStateError');
    207 }, 'Upgrading a custom element must throw InvalidStateError when the custom element\'s constructor returns another element');
     206    assert_equals(uncaughtError.name, 'TypeError');
     207}, 'Upgrading a custom element must throw TypeError when the custom element\'s constructor returns another element');
    208208
    209209test(function () {
  • trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/upgrading/upgrading-parser-created-element-expected.txt

    r207703 r244293  
    11
    22PASS Element.prototype.createElement must add an unresolved custom element to the upgrade candidates map
    3 PASS HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself after super() call
    4 PASS HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself before super() call
    5 PASS Upgrading a custom element must throw an InvalidStateError when the returned element is not SameValue as the upgraded element
     3PASS HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself after super() call
     4PASS HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself before super() call
     5PASS Upgrading a custom element must throw an TypeError when the returned element is not SameValue as the upgraded element
     6PASS Upgrading a custom element whose constructor returns a Text node must throw
     7PASS Upgrading a custom element whose constructor returns an Element must throw
    68
  • trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/upgrading/upgrading-parser-created-element.html

    r207703 r244293  
    1616<my-other-element id="instance"></my-other-element>
    1717<my-other-element id="otherInstance"></my-other-element>
     18<not-an-element></not-an-element>
     19<not-an-html-element></not-an-html-element>
    1820<script>
    1921
     
    4951    window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
    5052    customElements.define('instantiates-itself-after-super', InstantiatesItselfAfterSuper);
    51     assert_equals(uncaughtError.name, 'InvalidStateError');
    52 }, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
     53    assert_equals(uncaughtError.name, 'TypeError');
     54}, 'HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed'
    5355    + ' due to a custom element constructor constructing itself after super() call');
    5456
     
    6567    window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
    6668    customElements.define('instantiates-itself-before-super', InstantiatesItselfBeforeSuper);
    67     assert_equals(uncaughtError.name, 'InvalidStateError');
    68 }, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
     69    assert_equals(uncaughtError.name, 'TypeError');
     70}, 'HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed'
    6971    + ' due to a custom element constructor constructing itself before super() call');
    7072
     
    8688    window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
    8789    customElements.define('my-other-element', MyOtherElement);
    88     assert_equals(uncaughtError.name, 'InvalidStateError');
     90    assert_equals(uncaughtError.name, 'TypeError');
    8991
    9092    assert_true(document.createElement('my-other-element') instanceof MyOtherElement,
    9193        'Upgrading of custom elements must happen after the definition was added to the registry.');
    9294
    93 }, 'Upgrading a custom element must throw an InvalidStateError when the returned element is not SameValue as the upgraded element');
     95}, 'Upgrading a custom element must throw an TypeError when the returned element is not SameValue as the upgraded element');
     96
     97test(() => {
     98  class NotAnElement extends HTMLElement {
     99    constructor() {
     100      return new Text();
     101    }
     102  }
     103
     104  let uncaughtError;
     105  window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
     106  customElements.define("not-an-element", NotAnElement);
     107  assert_equals(uncaughtError.name, "TypeError");
     108}, "Upgrading a custom element whose constructor returns a Text node must throw");
     109
     110test(() => {
     111  class NotAnHTMLElement extends HTMLElement {
     112    constructor() {
     113      return document.createElementNS("", "test");
     114    }
     115  }
     116
     117  let uncaughtError;
     118  window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
     119  customElements.define("not-an-html-element", NotAnHTMLElement);
     120  assert_equals(uncaughtError.name, "TypeError");
     121}, "Upgrading a custom element whose constructor returns an Element must throw");
    94122
    95123</script>
  • trunk/Source/WebCore/ChangeLog

    r244292 r244293  
     12019-04-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Throw TypeError when custom element constructor returns a wrong element or tries to create itself
     4        https://bugs.webkit.org/show_bug.cgi?id=196892
     5
     6        Reviewed by Dean Jackson.
     7
     8        Throw TypeError instead of InvalidStateError for consistency. This updates WebKit's custom elements
     9        implementation for https://github.com/whatwg/html/pull/4525.
     10
     11        Tests: imported/w3c/web-platform-tests/custom-elements/upgrading/Node-cloneNode.html
     12               imported/w3c/web-platform-tests/custom-elements/upgrading/upgrading-parser-created-element.html
     13
     14        * bindings/js/JSCustomElementInterface.cpp:
     15        (WebCore::JSCustomElementInterface::upgradeElement):
     16        * bindings/js/JSHTMLElementCustom.cpp:
     17        (WebCore::constructJSHTMLElement):
     18
    1192019-04-15  Don Olmstead  <don.olmstead@sony.com>
    220
  • trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp

    r243163 r244293  
    215215    if (!wrappedElement || wrappedElement != &element) {
    216216        element.setIsFailedCustomElement(*this);
    217         reportException(state, createDOMException(state, InvalidStateError, "Custom element constructor failed to upgrade an element"));
     217        reportException(state, createDOMException(state, TypeError, "Custom element constructor returned a wrong element"));
    218218        return;
    219219    }
  • trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp

    r234957 r244293  
    9090    Element* elementToUpgrade = elementInterface->lastElementInConstructionStack();
    9191    if (!elementToUpgrade) {
    92         throwInvalidStateError(exec, scope, "Cannot instantiate a custom element inside its own constructor during upgrades"_s);
     92        throwTypeError(&exec, scope, "Cannot instantiate a custom element inside its own constructor during upgrades"_s);
    9393        return JSValue::encode(jsUndefined());
    9494    }
Note: See TracChangeset for help on using the changeset viewer.