Changeset 204367 in webkit


Ignore:
Timestamp:
Aug 10, 2016 7:08:17 PM (8 years ago)
Author:
rniwa@webkit.org
Message:

Move document.defineElement to customElements.define
https://bugs.webkit.org/show_bug.cgi?id=160731

Reviewed by Chris Dumez.

Source/WebCore:

Replaced Document.prototype.defineElement by CustomElementsRegistry.prototype.define to match
the latest HTML specification: https://html.spec.whatwg.org/#custom-elements-api

This patch renames the existing CustomElementDefinitions to CustomElementsRegistry and exposes
it on window.customElements. CustomElementDefinitions is now owned by DOMWindow instead of
Document to match the spec's new semantics.

No new tests. The existing tests have been updated to reflect the change.

  • DerivedSources.cpp:
  • DerivedSources.make:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSCustomElementsRegistryCustom.cpp: Added.

(WebCore::JSCustomElementsRegistry::define): Moved from JSDocumentCustom. Removed the check for
the existence of DOMWindow since CustomElementsRegistry is an attribute on DOMWindow itself.

  • bindings/js/JSDocumentCustom.cpp:

(WebCore::JSDocument::defineElement): Deleted.

  • bindings/js/JSHTMLElementCustom.cpp: Added the code to check the existence of DOMWindow since

the registry is associated with DOMWindow, not Document.
(WebCore::constructJSHTMLElement):

  • dom/CustomElementsRegistry.cpp: Renamed from Source/WebCore/dom/CustomElementDefinitions.cpp.

(WebCore::CustomElementsRegistry::create): Added.
(WebCore::CustomElementsRegistry::CustomElementsRegistry): Added.
(WebCore::CustomElementsRegistry::~CustomElementsRegistry): Added.
(WebCore::CustomElementsRegistry::addElementDefinition): Moved from CustomElementDefinitions.
(WebCore::CustomElementsRegistry::addUpgradeCandidate): Ditto.
(WebCore::CustomElementsRegistry::findInterface): Ditto.
(WebCore::CustomElementsRegistry::containsConstructor): Ditto.

  • dom/CustomElementsRegistry.h: Renamed from Source/WebCore/dom/CustomElementDefinitions.h.
  • dom/CustomElementsRegistry.idl: Added.
  • dom/Document.cpp:

(WebCore::createUpgradeCandidateElement): Extracted out of createHTMLElementWithNameValidation
and createFallbackHTMLElement to share code.
(WebCore::createHTMLElementWithNameValidation):
(WebCore::createFallbackHTMLElement): This function was missing a check for the runtime flag.
Sharing code with createHTMLElementWithNameValidation via createUpgradeCandidateElement fixes it.
(WebCore::Document::ensureCustomElementDefinitions): Deleted.

  • dom/Document.h:

(WebCore::Document::customElementDefinitions): Deleted.

  • dom/Document.idl:
  • dom/Element.cpp:

(WebCore::Element::attributeChanged):

  • html/parser/HTMLConstructionSite.cpp:

(WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface):

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::ensureCustomElementsRegistry): Added. Moved from Document.

  • page/DOMWindow.h:
  • page/DOMWindow.idl: Added customElements on DOMWindow.

LayoutTests:

Updated the tests and their expected results to reflect the move of Document.prototype.defineElement to
CustomElementsRegistry.prototype.define. I'm going to rename tests in a follow up.

  • fast/custom-elements/Document-createElement.html:
  • fast/custom-elements/Document-defineElement-expected.txt:
  • fast/custom-elements/Document-defineElement.html: Removed test cases for testing defining elements

in a viewless/windowless document since those documents don't have a corresponding window object.

  • fast/custom-elements/HTMLElement-constructor.html:
  • fast/custom-elements/attribute-changed-callback.html:
  • fast/custom-elements/defined-pseudo-class.html:
  • fast/custom-elements/defined-rule.html:
  • fast/custom-elements/lifecycle-callback-timing.html:
  • fast/custom-elements/parser/parser-constructs-custom-element-in-document-write.html:
  • fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html:
  • fast/custom-elements/parser/parser-constructs-custom-elements-expected.txt:
  • fast/custom-elements/parser/parser-constructs-custom-elements.html:
  • fast/custom-elements/parser/parser-fallsback-to-unknown-element.html:
  • fast/custom-elements/parser/parser-sets-attributes-and-children.html:
  • fast/custom-elements/parser/parser-uses-constructed-element.html:
  • fast/custom-elements/parser/parser-uses-registry-of-owner-document.html:
  • fast/custom-elements/upgrading/Node-cloneNode.html:
  • fast/custom-elements/upgrading/upgrading-parser-created-element.html:
  • platform/mac/js/dom/global-constructors-attributes-expected.txt:
Location:
trunk
Files:
2 added
39 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r204363 r204367  
     12016-08-10  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Move document.defineElement to customElements.define
     4        https://bugs.webkit.org/show_bug.cgi?id=160731
     5
     6        Reviewed by Chris Dumez.
     7
     8        Updated the tests and their expected results to reflect the move of Document.prototype.defineElement to
     9        CustomElementsRegistry.prototype.define. I'm going to rename tests in a follow up.
     10
     11        * fast/custom-elements/Document-createElement.html:
     12        * fast/custom-elements/Document-defineElement-expected.txt:
     13        * fast/custom-elements/Document-defineElement.html: Removed test cases for testing defining elements
     14        in a viewless/windowless document since those documents don't have a corresponding window object.
     15        * fast/custom-elements/HTMLElement-constructor.html:
     16        * fast/custom-elements/attribute-changed-callback.html:
     17        * fast/custom-elements/defined-pseudo-class.html:
     18        * fast/custom-elements/defined-rule.html:
     19        * fast/custom-elements/lifecycle-callback-timing.html:
     20        * fast/custom-elements/parser/parser-constructs-custom-element-in-document-write.html:
     21        * fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html:
     22        * fast/custom-elements/parser/parser-constructs-custom-elements-expected.txt:
     23        * fast/custom-elements/parser/parser-constructs-custom-elements.html:
     24        * fast/custom-elements/parser/parser-fallsback-to-unknown-element.html:
     25        * fast/custom-elements/parser/parser-sets-attributes-and-children.html:
     26        * fast/custom-elements/parser/parser-uses-constructed-element.html:
     27        * fast/custom-elements/parser/parser-uses-registry-of-owner-document.html:
     28        * fast/custom-elements/upgrading/Node-cloneNode.html:
     29        * fast/custom-elements/upgrading/upgrading-parser-created-element.html:
     30        * platform/mac/js/dom/global-constructors-attributes-expected.txt:
     31
    1322016-08-10  Simon Fraser  <simon.fraser@apple.com>
    233
  • trunk/LayoutTests/fast/custom-elements/Document-createElement.html

    r197602 r204367  
    1919    assert_false(document.createElement('my-custom-element') instanceof MyCustomElement);
    2020
    21     document.defineElement('my-custom-element', MyCustomElement);
     21    customElements.define('my-custom-element', MyCustomElement);
    2222    var instance = document.createElement('my-custom-element');
    2323    assert_true(instance instanceof MyCustomElement);
     
    3434        }
    3535    };
    36     document.defineElement('object-custom-element', ObjectCustomElement);
     36    customElements.define('object-custom-element', ObjectCustomElement);
    3737
    3838    var instance = new ObjectCustomElement;
     
    5050        }
    5151    };
    52     document.defineElement('text-custom-element', TextCustomElement);
     52    customElements.define('text-custom-element', TextCustomElement);
    5353    assert_true(new TextCustomElement instanceof Text);
    5454    assert_equals(document.createElement('object-custom-element'), null);
     
    6565        }
    6666    };
    67     document.defineElement('div-custom-element', DivCustomElement);
     67    customElements.define('div-custom-element', DivCustomElement);
    6868    assert_true(new DivCustomElement instanceof HTMLDivElement);
    6969
     
    8383        }
    8484    };
    85     document.defineElement('throw-custom-element', ThrowCustomElement);
     85    customElements.define('throw-custom-element', ThrowCustomElement);
    8686
    8787    assert_throws(null, function () { new ThrowCustomElement; });
  • trunk/LayoutTests/fast/custom-elements/Document-defineElement-expected.txt

    r197602 r204367  
    11
    2 PASS Check the existence of defineElement on Document interface
    3 PASS document.defineElement should throw with an invalid name
    4 PASS document.defineElement should throw when there is already a custom element of the same name
    5 PASS document.defineElement should throw when there is already a custom element with the same class
    6 PASS document.defineElement must throw a NotSupportedError when the context object is an associated inert template document
    7 PASS document.defineElement must throw a NotSupportedError when the context object is created by DOMImplementation.createHTMLDocument
    8 PASS document.defineElement must throw a NotSupportedError when the context object is created by DOMImplementation.createDocument
    9 PASS document.defineElement should throw when the element interface is not a constructor
    10 PASS document.defineElement should define an instantiatable custom element
     2PASS Check the existence of CustomElementsRegistry.prototype.define on CustomElementsRegistry interface
     3PASS customElements.define should throw with an invalid name
     4PASS customElements.define should throw when there is already a custom element of the same name
     5PASS customElements.define should throw when there is already a custom element with the same class
     6PASS customElements.define should throw when the element interface is not a constructor
     7PASS customElements.define should define an instantiatable custom element
    118
  • trunk/LayoutTests/fast/custom-elements/Document-defineElement.html

    r197602 r204367  
    44<title>Custom Elements: Extensions to Document interface</title>
    55<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
    6 <meta name="assert" content="document.defineElement should define a custom element">
     6<meta name="assert" content="customElements.define should define a custom element">
    77<script src="../../resources/testharness.js"></script>
    88<script src="../../resources/testharnessreport.js"></script>
     
    1414
    1515test(function () {
    16     assert_true('defineElement' in Document.prototype, '"defineElement" exists on Document.prototype');
    17     assert_true('defineElement' in document, '"defineElement" exists on document');
    18 }, 'Check the existence of defineElement on Document interface');
     16    assert_true('define' in CustomElementsRegistry.prototype, '"define" exists on CustomElementsRegistry.prototype');
     17    assert_true('define' in customElements, '"define" exists on window.customElements');
     18}, 'Check the existence of CustomElementsRegistry.prototype.define on CustomElementsRegistry interface');
    1919
    2020test(function () {
    2121    class MyCustomElement extends HTMLElement {};
    2222
    23     assert_throws({'name': 'SyntaxError'}, function () { document.defineElement(null, MyCustomElement); },
    24         'document.defineElement must throw a SyntaxError if the tag name is null');
    25     assert_throws({'name': 'SyntaxError'}, function () { document.defineElement('', MyCustomElement); },
    26         'document.defineElement must throw a SyntaxError if the tag name is empty');
    27     assert_throws({'name': 'SyntaxError'}, function () { document.defineElement('abc', MyCustomElement); },
    28         'document.defineElement must throw a SyntaxError if the tag name does not contain "-"');
    29     assert_throws({'name': 'SyntaxError'}, function () { document.defineElement('a-Bc', MyCustomElement); },
    30         'document.defineElement must throw a SyntaxError if the tag name contains an upper case letter');
     23    assert_throws({'name': 'SyntaxError'}, function () { customElements.define(null, MyCustomElement); },
     24        'customElements.define must throw a SyntaxError if the tag name is null');
     25    assert_throws({'name': 'SyntaxError'}, function () { customElements.define('', MyCustomElement); },
     26        'customElements.define must throw a SyntaxError if the tag name is empty');
     27    assert_throws({'name': 'SyntaxError'}, function () { customElements.define('abc', MyCustomElement); },
     28        'customElements.define must throw a SyntaxError if the tag name does not contain "-"');
     29    assert_throws({'name': 'SyntaxError'}, function () { customElements.define('a-Bc', MyCustomElement); },
     30        'customElements.define must throw a SyntaxError if the tag name contains an upper case letter');
    3131
    3232    var builtinTagNames = [
     
    4242
    4343    for (var tagName of builtinTagNames) {
    44         assert_throws({'name': 'SyntaxError'}, function () { document.defineElement(tagName, MyCustomElement); },
    45             'document.defineElement must throw a SyntaxError if the tag name is "' + tagName + '"');
     44        assert_throws({'name': 'SyntaxError'}, function () { customElements.define(tagName, MyCustomElement); },
     45            'customElements.define must throw a SyntaxError if the tag name is "' + tagName + '"');
    4646    }
    4747
    48 }, 'document.defineElement should throw with an invalid name');
     48}, 'customElements.define should throw with an invalid name');
    4949
    5050test(function () {
     
    5252    class OtherCustomElement extends HTMLElement {};
    5353
    54     document.defineElement('some-custom-element', SomeCustomElement);
    55     assert_throws({'name': 'NotSupportedError'}, function () { document.defineElement('some-custom-element', OtherCustomElement); },
    56         'document.defineElement must throw a NotSupportedError if the specified tag name is already used');
     54    customElements.define('some-custom-element', SomeCustomElement);
     55    assert_throws({'name': 'NotSupportedError'}, function () { customElements.define('some-custom-element', OtherCustomElement); },
     56        'customElements.define must throw a NotSupportedError if the specified tag name is already used');
    5757
    58 }, 'document.defineElement should throw when there is already a custom element of the same name');
     58}, 'customElements.define should throw when there is already a custom element of the same name');
    5959
    6060test(function () {
    6161    class AnotherCustomElement extends HTMLElement {};
    6262
    63     document.defineElement('another-custom-element', AnotherCustomElement);
    64     assert_throws({'name': 'NotSupportedError'}, function () { document.defineElement('some-other-element', AnotherCustomElement); },
    65         'document.defineElement must throw a NotSupportedError if the specified class already defines an element');
     63    customElements.define('another-custom-element', AnotherCustomElement);
     64    assert_throws({'name': 'NotSupportedError'}, function () { customElements.define('some-other-element', AnotherCustomElement); },
     65        'customElements.define must throw a NotSupportedError if the specified class already defines an element');
    6666
    67 }, 'document.defineElement should throw when there is already a custom element with the same class');
     67}, 'customElements.define should throw when there is already a custom element with the same class');
    6868
    6969test(function () {
    70     class SomeCustomElement extends HTMLElement {};
    71 
    72     var templateContentOwnerDocument = document.createElement('template').content.ownerDocument;
    73     assert_throws({'name': 'NotSupportedError'}, function () {
    74         templateContentOwnerDocument.defineElement('some-custom-element', SomeCustomElement);
    75     });
    76 
    77 }, 'document.defineElement must throw a NotSupportedError when the context object is an associated inert template document');
    78 
    79 test(function () {
    80     class SomeCustomElement extends HTMLElement {};
    81 
    82     var windowlessDocument = document.implementation.createHTMLDocument();
    83     assert_throws({'name': 'NotSupportedError'}, function () {
    84         windowlessDocument.defineElement('some-custom-element', SomeCustomElement);
    85     });
    86 
    87 }, 'document.defineElement must throw a NotSupportedError when the context object is created by DOMImplementation.createHTMLDocument');
    88 
    89 test(function () {
    90     class SomeCustomElement extends HTMLElement {};
    91 
    92     var windowlessDocument = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null)
    93     assert_throws({'name': 'NotSupportedError'}, function () {
    94         windowlessDocument.defineElement('some-custom-element', SomeCustomElement);
    95     });
    96 
    97 }, 'document.defineElement must throw a NotSupportedError when the context object is created by DOMImplementation.createDocument');
    98 
    99 test(function () {
    100     assert_throws({'name': 'TypeError'}, function () { document.defineElement('invalid-element', 1); },
    101         'document.defineElement must throw a TypeError when the element interface is a number');
    102     assert_throws({'name': 'TypeError'}, function () { document.defineElement('invalid-element', '123'); },
    103         'document.defineElement must throw a TypeError when the element interface is a string');
    104     assert_throws({'name': 'TypeError'}, function () { document.defineElement('invalid-element', {}); },
    105         'document.defineElement must throw a TypeError when the element interface is an object');
    106     assert_throws({'name': 'TypeError'}, function () { document.defineElement('invalid-element', []); },
    107         'document.defineElement must throw a TypeError when the element interface is an array');
    108 }, 'document.defineElement should throw when the element interface is not a constructor');
     70    assert_throws({'name': 'TypeError'}, function () { customElements.define('invalid-element', 1); },
     71        'customElements.define must throw a TypeError when the element interface is a number');
     72    assert_throws({'name': 'TypeError'}, function () { customElements.define('invalid-element', '123'); },
     73        'customElements.define must throw a TypeError when the element interface is a string');
     74    assert_throws({'name': 'TypeError'}, function () { customElements.define('invalid-element', {}); },
     75        'customElements.define must throw a TypeError when the element interface is an object');
     76    assert_throws({'name': 'TypeError'}, function () { customElements.define('invalid-element', []); },
     77        'customElements.define must throw a TypeError when the element interface is an array');
     78}, 'customElements.define should throw when the element interface is not a constructor');
    10979
    11080test(function () {
    11181    class MyCustomElement extends HTMLElement {};
    112     document.defineElement('my-custom-element', MyCustomElement);
     82    customElements.define('my-custom-element', MyCustomElement);
    11383
    11484    var instance = new MyCustomElement;
     
    12595        'A custom element HTML must use HTML namespace');
    12696
    127 }, 'document.defineElement should define an instantiatable custom element');
     97}, 'customElements.define should define an instantiatable custom element');
    12898
    12999</script>
  • trunk/LayoutTests/fast/custom-elements/HTMLElement-constructor.html

    r197602 r204367  
    1515test(function () {
    1616    class SomeDefinedElement extends HTMLElement {};
    17     document.defineElement('defined-element', SomeDefinedElement);
     17    customElements.define('defined-element', SomeDefinedElement);
    1818    assert_throws({'name': 'TypeError'}, function () { new HTMLElement('defined-element'); });
    1919}, 'HTMLElement constructor must throw a TypeError when there is no derived class');
     
    2222    class SomeCustomElement extends HTMLElement {};
    2323    assert_throws({'name': 'TypeError'}, function () { new SomeCustomElement; },
    24         'Instantiating a custom element without calling defineElement must throw TypeError');
     24        'Instantiating a custom element without calling customElements.define must throw TypeError');
    2525}, 'HTMLElement constructor must throw TypeError when custom element is not well defined');
    2626
    2727test(function () {
    2828    class CustomElementWithInferredTagName extends HTMLElement {};
    29     document.defineElement('inferred-name', CustomElementWithInferredTagName);
     29    customElements.define('inferred-name', CustomElementWithInferredTagName);
    3030
    3131    var instance = new CustomElementWithInferredTagName;
     
    4747    class ConcreteCustomElement extends HTMLElement { };
    4848    class SubCustomElement extends ConcreteCustomElement { };
    49     document.defineElement('concrete-custom-element', ConcreteCustomElement);
    50     document.defineElement('sub-custom-element', SubCustomElement);
     49    customElements.define('concrete-custom-element', ConcreteCustomElement);
     50    customElements.define('sub-custom-element', SubCustomElement);
    5151
    5252    var instance = new ConcreteCustomElement();
     
    6767    class AbstractCustomElement extends HTMLElement { };
    6868    class ConcreteSubCustomElement extends AbstractCustomElement { };
    69     document.defineElement('concrete-sub-custom-element', ConcreteSubCustomElement);
     69    customElements.define('concrete-sub-custom-element', ConcreteSubCustomElement);
    7070
    7171    var instance = new ConcreteSubCustomElement();
  • trunk/LayoutTests/fast/custom-elements/attribute-changed-callback.html

    r197611 r204367  
    2020    }
    2121}
    22 document.defineElement('my-custom-element', MyCustomElement);
     22customElements.define('my-custom-element', MyCustomElement);
    2323
    2424test(function () {
  • trunk/LayoutTests/fast/custom-elements/defined-pseudo-class.html

    r197952 r204367  
    2626    }
    2727}
    28 document.defineElement('my-element', MyElement);
     28customElements.define('my-element', MyElement);
    2929
    3030test(function () {
     
    6060    }
    6161}
    62 document.defineElement('returns-another-node', ReturnsAnotherNode);
     62customElements.define('returns-another-node', ReturnsAnotherNode);
    6363
    6464document.write('<returns-another-node></returns-another-node>');
     
    7373    var instance = document.createElement('returns-another-node-2');
    7474    try {
    75         document.defineElement('returns-another-node-2', class extends ReturnsAnotherNode {});
     75        customElements.define('returns-another-node-2', class extends ReturnsAnotherNode {});
    7676    } catch (e) { }
    7777    assert_false(instance.matches(':defined'));
  • trunk/LayoutTests/fast/custom-elements/defined-rule.html

    r197952 r204367  
    3232    <script>
    3333
    34         document.defineElement('my-defined-element', class extends HTMLElement {});
     34        customElements.define('my-defined-element', class extends HTMLElement {});
    3535
    3636    </script>
  • trunk/LayoutTests/fast/custom-elements/lifecycle-callback-timing.html

    r197634 r204367  
    2121    handler() { }
    2222}
    23 document.defineElement('my-custom-element', MyCustomElement);
     23customElements.define('my-custom-element', MyCustomElement);
    2424
    2525test(function () {
     
    6464        }
    6565    }
    66     document.defineElement('self-cloning-element', SelfCloningElement);
     66    customElements.define('self-cloning-element', SelfCloningElement);
    6767
    6868    var instance = document.createElement('self-cloning-element');
  • trunk/LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-in-document-write.html

    r197602 r204367  
    1414
    1515class MyCustomElement extends HTMLElement { }
    16 document.defineElement('my-custom-element', MyCustomElement);
     16customElements.define('my-custom-element', MyCustomElement);
    1717
    1818document.write('<my-custom-element></my-custom-element>');
  • trunk/LayoutTests/fast/custom-elements/parser/parser-constructs-custom-element-synchronously.html

    r197602 r204367  
    2525    }
    2626};
    27 document.defineElement('my-custom-element', MyCustomElement);
     27customElements.define('my-custom-element', MyCustomElement);
    2828
    2929</script>
  • trunk/LayoutTests/fast/custom-elements/parser/parser-constructs-custom-elements-expected.txt

    r197463 r204367  
    11
    2 PASS HTML parser must NOT create a custom element before defineElement is called
     2PASS HTML parser must NOT create a custom element before customElements.define is called
    33PASS HTML parser must create a defined custom element before executing inline scripts
    44
  • trunk/LayoutTests/fast/custom-elements/parser/parser-constructs-custom-elements.html

    r197602 r204367  
    2424    assert_equals(customElement.namespaceURI, 'http://www.w3.org/1999/xhtml', 'A custom element HTML must use HTML namespace');
    2525
    26 }, 'HTML parser must NOT create a custom element before defineElement is called');
     26}, 'HTML parser must NOT create a custom element before customElements.define is called');
    2727
    28 document.defineElement('my-custom-element', MyCustomElement);
     28customElements.define('my-custom-element', MyCustomElement);
    2929
    3030</script>
  • trunk/LayoutTests/fast/custom-elements/parser/parser-fallsback-to-unknown-element.html

    r197602 r204367  
    1919    }
    2020};
    21 document.defineElement('returns-text', ReturnsTextNode);
     21customElements.define('returns-text', ReturnsTextNode);
    2222
    2323class ReturnsNonElementObject extends HTMLElement {
     
    2727    }
    2828};
    29 document.defineElement('returns-non-element-object', ReturnsNonElementObject);
     29customElements.define('returns-non-element-object', ReturnsNonElementObject);
    3030
    3131class LacksSuperCall extends HTMLElement {
    3232    constructor() { }
    3333};
    34 document.defineElement('lacks-super-call', LacksSuperCall);
     34customElements.define('lacks-super-call', LacksSuperCall);
    3535
    3636class ThrowsException extends HTMLElement {
     
    3939    }
    4040};
    41 document.defineElement('throws-exception', ThrowsException);
     41customElements.define('throws-exception', ThrowsException);
    4242
    4343</script>
  • trunk/LayoutTests/fast/custom-elements/parser/parser-sets-attributes-and-children.html

    r197602 r204367  
    2323    }
    2424};
    25 document.defineElement('my-custom-element', MyCustomElement);
     25customElements.define('my-custom-element', MyCustomElement);
    2626
    2727</script>
  • trunk/LayoutTests/fast/custom-elements/parser/parser-uses-constructed-element.html

    r197602 r204367  
    2626    }
    2727};
    28 document.defineElement('instantiates-itself-before-super', InstantiatesItselfBeforeSuper);
     28customElements.define('instantiates-itself-before-super', InstantiatesItselfBeforeSuper);
    2929
    3030let shouldCreateAnotherInstance = true;
     
    4343    }
    4444};
    45 document.defineElement('returns-another-instance', ReturnsAnotherInstance);
     45customElements.define('returns-another-instance', ReturnsAnotherInstance);
    4646
    4747</script>
  • trunk/LayoutTests/fast/custom-elements/parser/parser-uses-registry-of-owner-document.html

    r197602 r204367  
    1414
    1515class MyCustomElement extends HTMLElement { };
    16 document.defineElement('my-custom-element', MyCustomElement);
     16customElements.define('my-custom-element', MyCustomElement);
    1717
    1818document.write('<template><my-custom-element></my-custom-element></template>');
     
    4444
    4545class ElementInIFrame extends iframe.contentWindow.HTMLElement { };
    46 iframe.contentDocument.defineElement('element-in-iframe', ElementInIFrame);
     46iframe.contentWindow.customElements.define('element-in-iframe', ElementInIFrame);
    4747iframe.contentDocument.body.innerHTML = '<element-in-iframe></element-in-iframe>';
    4848
  • trunk/LayoutTests/fast/custom-elements/upgrading/Node-cloneNode.html

    r197917 r204367  
    2626test(function () {
    2727    class MyCustomElement extends HTMLElement {}
    28     document.defineElement('my-custom-element', MyCustomElement);
     28    customElements.define('my-custom-element', MyCustomElement);
    2929
    3030    var instance = document.createElement('my-custom-element');
     
    4343    withNewDocumentWithABrowsingContext(function (contentWindow, contentDocument) {
    4444        class MyCustomElement extends contentWindow.HTMLElement {}
    45         contentDocument.defineElement('my-custom-element', MyCustomElement);
     45        contentWindow.customElements.define('my-custom-element', MyCustomElement);
    4646
    4747        var instance = contentDocument.createElement('my-custom-element');
     
    6161    withNewDocumentWithABrowsingContext(function (contentWindow, contentDocument) {
    6262        class MyCustomElement extends contentWindow.HTMLElement { }
    63         contentDocument.defineElement('my-custom-element', MyCustomElement);
     63        contentWindow.customElements.define('my-custom-element', MyCustomElement);
    6464
    6565        var instance = contentDocument.createElement('my-custom-element');
     
    9292            }
    9393        }
    94         contentDocument.defineElement('my-custom-element', MyCustomElement);
     94        contentWindow.customElements.define('my-custom-element', MyCustomElement);
    9595
    9696        var instance = contentDocument.createElement('my-custom-element');
     
    122122            }
    123123        }
    124         contentDocument.defineElement('my-custom-element', MyCustomElement);
     124        contentWindow.customElements.define('my-custom-element', MyCustomElement);
    125125
    126126        var instance = contentDocument.createElement('my-custom-element');
     
    139139            }
    140140        }
    141         contentDocument.defineElement('my-custom-element', MyCustomElement);
     141        contentWindow.customElements.define('my-custom-element', MyCustomElement);
    142142
    143143        var instance = contentDocument.createElement('my-custom-element');
     
    157157            }
    158158        }
    159         contentDocument.defineElement('my-custom-element', MyCustomElement);
     159        contentWindow.customElements.define('my-custom-element', MyCustomElement);
    160160
    161161        var instance = contentDocument.createElement('my-custom-element');
  • trunk/LayoutTests/fast/custom-elements/upgrading/upgrading-parser-created-element.html

    r197917 r204367  
    2828    assert_false(instance instanceof MyCustomElement);
    2929
    30     document.defineElement('my-custom-element', MyCustomElement);
     30    customElements.define('my-custom-element', MyCustomElement);
    3131
    3232    assert_true(instance instanceof HTMLElement);
    3333    assert_true(instance instanceof MyCustomElement,
    34         'Calling defineElement must upgrade existing custom elements');
     34        'Calling customElements.define must upgrade existing custom elements');
    3535
    3636}, 'Element.prototype.createElement must add an unresolved custom element to the upgrade candidates map');
     
    4747
    4848    assert_throws({'name': 'InvalidStateError'}, function () {
    49         document.defineElement('instantiates-itself-after-super', InstantiatesItselfAfterSuper);
     49        customElements.define('instantiates-itself-after-super', InstantiatesItselfAfterSuper);
    5050    });
    5151}, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
     
    6262
    6363    assert_throws({'name': 'InvalidStateError'}, function () {
    64         document.defineElement('instantiates-itself-before-super', InstantiatesItselfBeforeSuper);
     64        customElements.define('instantiates-itself-before-super', InstantiatesItselfBeforeSuper);
    6565    });
    6666}, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
     
    8282
    8383    assert_throws({'name': 'InvalidStateError'}, function () {
    84         document.defineElement('my-other-element', MyOtherElement);
     84        customElements.define('my-other-element', MyOtherElement);
    8585    });
    8686
  • trunk/LayoutTests/platform/efl/js/dom/global-constructors-attributes-expected.txt

    r204242 r204367  
    264264PASS Object.getOwnPropertyDescriptor(global, 'Crypto').enumerable is false
    265265PASS Object.getOwnPropertyDescriptor(global, 'Crypto').configurable is true
     266PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').value is CustomElementsRegistry
     267PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('get') is false
     268PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('set') is false
     269PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').enumerable is false
     270PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').configurable is true
    266271PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').value is CustomEvent
    267272PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/gtk/js/dom/global-constructors-attributes-expected.txt

    r204242 r204367  
    264264PASS Object.getOwnPropertyDescriptor(global, 'Crypto').enumerable is false
    265265PASS Object.getOwnPropertyDescriptor(global, 'Crypto').configurable is true
     266PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').value is CustomElementsRegistry
     267PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('get') is false
     268PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('set') is false
     269PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').enumerable is false
     270PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').configurable is true
    266271PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').value is CustomEvent
    267272PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt

    r204242 r204367  
    284284PASS Object.getOwnPropertyDescriptor(global, 'Crypto').enumerable is false
    285285PASS Object.getOwnPropertyDescriptor(global, 'Crypto').configurable is true
     286PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').value is CustomElementsRegistry
     287PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('get') is false
     288PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('set') is false
     289PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').enumerable is false
     290PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').configurable is true
    286291PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').value is CustomEvent
    287292PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/mac/js/dom/global-constructors-attributes-expected.txt

    r204242 r204367  
    284284PASS Object.getOwnPropertyDescriptor(global, 'Crypto').enumerable is false
    285285PASS Object.getOwnPropertyDescriptor(global, 'Crypto').configurable is true
     286PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').value is CustomElementsRegistry
     287PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('get') is false
     288PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('set') is false
     289PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').enumerable is false
     290PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').configurable is true
    286291PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').value is CustomEvent
    287292PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').hasOwnProperty('get') is false
  • trunk/LayoutTests/platform/win/js/dom/global-constructors-attributes-expected.txt

    r204242 r204367  
    199199PASS Object.getOwnPropertyDescriptor(global, 'Crypto').enumerable is false
    200200PASS Object.getOwnPropertyDescriptor(global, 'Crypto').configurable is true
     201PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').value is CustomElementsRegistry
     202PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('get') is false
     203PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').hasOwnProperty('set') is false
     204PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').enumerable is false
     205PASS Object.getOwnPropertyDescriptor(global, 'CustomElementsRegistry').configurable is true
    201206PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').value is CustomEvent
    202207PASS Object.getOwnPropertyDescriptor(global, 'CustomEvent').hasOwnProperty('get') is false
  • trunk/Source/WebCore/CMakeLists.txt

    r204327 r204367  
    368368    dom/Comment.idl
    369369    dom/CompositionEvent.idl
     370    dom/CustomElementsRegistry.idl
    370371    dom/CustomEvent.idl
    371372    dom/DOMCoreException.idl
     
    11211122    bindings/js/JSCryptoOperationData.cpp
    11221123    bindings/js/JSCustomElementInterface.cpp
     1124    bindings/js/JSCustomElementsRegistryCustom.cpp
    11231125    bindings/js/JSCustomEventCustom.cpp
    11241126    bindings/js/JSCustomSQLStatementErrorCallback.cpp
     
    14211423    dom/ContainerNodeAlgorithms.cpp
    14221424    dom/ContextDestructionObserver.cpp
    1423     dom/CustomElementDefinitions.cpp
     1425    dom/CustomElementsRegistry.cpp
    14241426    dom/CustomEvent.cpp
    14251427    dom/DOMCoreException.cpp
  • trunk/Source/WebCore/ChangeLog

    r204366 r204367  
     12016-08-10  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Move document.defineElement to customElements.define
     4        https://bugs.webkit.org/show_bug.cgi?id=160731
     5
     6        Reviewed by Chris Dumez.
     7
     8        Replaced Document.prototype.defineElement by CustomElementsRegistry.prototype.define to match
     9        the latest HTML specification: https://html.spec.whatwg.org/#custom-elements-api
     10
     11        This patch renames the existing CustomElementDefinitions to CustomElementsRegistry and exposes
     12        it on window.customElements. CustomElementDefinitions is now owned by DOMWindow instead of
     13        Document to match the spec's new semantics.
     14
     15        No new tests. The existing tests have been updated to reflect the change.
     16
     17        * DerivedSources.cpp:
     18        * DerivedSources.make:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        * bindings/js/JSCustomElementsRegistryCustom.cpp: Added.
     21        (WebCore::JSCustomElementsRegistry::define): Moved from JSDocumentCustom. Removed the check for
     22        the existence of DOMWindow since CustomElementsRegistry is an attribute on DOMWindow itself.
     23        * bindings/js/JSDocumentCustom.cpp:
     24        (WebCore::JSDocument::defineElement): Deleted.
     25        * bindings/js/JSHTMLElementCustom.cpp: Added the code to check the existence of DOMWindow since
     26        the registry is associated with DOMWindow, not Document.
     27        (WebCore::constructJSHTMLElement):
     28        * dom/CustomElementsRegistry.cpp: Renamed from Source/WebCore/dom/CustomElementDefinitions.cpp.
     29        (WebCore::CustomElementsRegistry::create): Added.
     30        (WebCore::CustomElementsRegistry::CustomElementsRegistry): Added.
     31        (WebCore::CustomElementsRegistry::~CustomElementsRegistry): Added.
     32        (WebCore::CustomElementsRegistry::addElementDefinition): Moved from CustomElementDefinitions.
     33        (WebCore::CustomElementsRegistry::addUpgradeCandidate): Ditto.
     34        (WebCore::CustomElementsRegistry::findInterface): Ditto.
     35        (WebCore::CustomElementsRegistry::containsConstructor): Ditto.
     36        * dom/CustomElementsRegistry.h: Renamed from Source/WebCore/dom/CustomElementDefinitions.h.
     37        * dom/CustomElementsRegistry.idl: Added.
     38        * dom/Document.cpp:
     39        (WebCore::createUpgradeCandidateElement): Extracted out of createHTMLElementWithNameValidation
     40        and createFallbackHTMLElement to share code.
     41        (WebCore::createHTMLElementWithNameValidation):
     42        (WebCore::createFallbackHTMLElement): This function was missing a check for the runtime flag.
     43        Sharing code with createHTMLElementWithNameValidation via createUpgradeCandidateElement fixes it.
     44        (WebCore::Document::ensureCustomElementDefinitions): Deleted.
     45        * dom/Document.h:
     46        (WebCore::Document::customElementDefinitions): Deleted.
     47        * dom/Document.idl:
     48        * dom/Element.cpp:
     49        (WebCore::Element::attributeChanged):
     50        * html/parser/HTMLConstructionSite.cpp:
     51        (WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface):
     52        * page/DOMWindow.cpp:
     53        (WebCore::DOMWindow::ensureCustomElementsRegistry): Added. Moved from Document.
     54        * page/DOMWindow.h:
     55        * page/DOMWindow.idl: Added customElements on DOMWindow.
     56
    1572016-08-10  Alex Christensen  <achristensen@webkit.org>
    258
  • trunk/Source/WebCore/DerivedSources.cpp

    r203818 r204367  
    139139#include "JSCSSValue.cpp"
    140140#include "JSCSSValueList.cpp"
     141#if ENABLE(CUSTOM_ELEMENTS)
     142#include "JSCustomElementsRegistry.cpp"
     143#endif
    141144#include "JSCustomEvent.cpp"
    142145#include "JSDatabase.cpp"
  • trunk/Source/WebCore/DerivedSources.make

    r204259 r204367  
    283283    $(WebCore)/dom/Comment.idl \
    284284    $(WebCore)/dom/CompositionEvent.idl \
     285    $(WebCore)/dom/CustomElementsRegistry.idl \
    285286    $(WebCore)/dom/CustomEvent.idl \
    286287    $(WebCore)/dom/DOMCoreException.idl \
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r204347 r204367  
    39293929                9BAF3B2412C1A39800014BF1 /* WritingDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BAF3B2312C1A39800014BF1 /* WritingDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
    39303930                9BB737651B41C03500AE13EB /* NSAttributedStringSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BB737641B41C03500AE13EB /* NSAttributedStringSPI.h */; };
     3931                9BC5F9E01D5AAF6B002B749D /* JSCustomElementsRegistryCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BC5F9DF1D5AAF6A002B749D /* JSCustomElementsRegistryCustom.cpp */; };
    39313932                9BC6C21B13CCC97B008E0337 /* HTMLTextFormControlElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BC6C21913CCC97B008E0337 /* HTMLTextFormControlElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
    39323933                9BC6C21C13CCC97B008E0337 /* HTMLTextFormControlElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BC6C21A13CCC97B008E0337 /* HTMLTextFormControlElement.cpp */; };
     
    39353936                9BD4E9161C462872005065BC /* JSCustomElementInterface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BD4E9141C462872005065BC /* JSCustomElementInterface.cpp */; };
    39363937                9BD4E9171C462872005065BC /* JSCustomElementInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BD4E9151C462872005065BC /* JSCustomElementInterface.h */; };
    3937                 9BD4E91A1C462CFC005065BC /* CustomElementDefinitions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BD4E9181C462CFC005065BC /* CustomElementDefinitions.cpp */; };
    3938                 9BD4E91B1C462CFC005065BC /* CustomElementDefinitions.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BD4E9191C462CFC005065BC /* CustomElementDefinitions.h */; };
     3938                9BD4E91A1C462CFC005065BC /* CustomElementsRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BD4E9181C462CFC005065BC /* CustomElementsRegistry.cpp */; };
     3939                9BD4E91B1C462CFC005065BC /* CustomElementsRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BD4E9191C462CFC005065BC /* CustomElementsRegistry.h */; };
    39393940                9BD8A95A18BEFC7600987E9A /* CollectionIndexCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BD8A95918BEFC7600987E9A /* CollectionIndexCache.cpp */; };
    39403941                9BDA64D71B975CE5009C4387 /* JSShadowRoot.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B6BC9601B975966005AE1F0 /* JSShadowRoot.cpp */; };
    39413942                9BDA64D81B975CF2009C4387 /* JSShadowRoot.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B6BC9611B975966005AE1F0 /* JSShadowRoot.h */; };
     3943                9BE6710B1D5AEB2100345514 /* JSCustomElementsRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BE671091D5AEB0400345514 /* JSCustomElementsRegistry.cpp */; };
     3944                9BE6710C1D5AEB2500345514 /* JSCustomElementsRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BE6710A1D5AEB0400345514 /* JSCustomElementsRegistry.h */; };
    39423945                9BF9A8801648DD2F001C6B23 /* JSHTMLFormControlsCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BF9A87E1648DD2F001C6B23 /* JSHTMLFormControlsCollection.cpp */; };
    39433946                9BF9A8811648DD2F001C6B23 /* JSHTMLFormControlsCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BF9A87F1648DD2F001C6B23 /* JSHTMLFormControlsCollection.h */; };
     
    1149511498                9BAF3B2312C1A39800014BF1 /* WritingDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritingDirection.h; sourceTree = "<group>"; };
    1149611499                9BB737641B41C03500AE13EB /* NSAttributedStringSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSAttributedStringSPI.h; sourceTree = "<group>"; };
     11500                9BC5F9DE1D5AAD5D002B749D /* CustomElementsRegistry.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CustomElementsRegistry.idl; sourceTree = "<group>"; };
     11501                9BC5F9DF1D5AAF6A002B749D /* JSCustomElementsRegistryCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomElementsRegistryCustom.cpp; sourceTree = "<group>"; };
    1149711502                9BC6C21913CCC97B008E0337 /* HTMLTextFormControlElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLTextFormControlElement.h; sourceTree = "<group>"; };
    1149811503                9BC6C21A13CCC97B008E0337 /* HTMLTextFormControlElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLTextFormControlElement.cpp; sourceTree = "<group>"; };
     
    1150111506                9BD4E9141C462872005065BC /* JSCustomElementInterface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomElementInterface.cpp; sourceTree = "<group>"; };
    1150211507                9BD4E9151C462872005065BC /* JSCustomElementInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCustomElementInterface.h; sourceTree = "<group>"; };
    11503                 9BD4E9181C462CFC005065BC /* CustomElementDefinitions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomElementDefinitions.cpp; sourceTree = "<group>"; };
    11504                 9BD4E9191C462CFC005065BC /* CustomElementDefinitions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomElementDefinitions.h; sourceTree = "<group>"; };
     11508                9BD4E9181C462CFC005065BC /* CustomElementsRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomElementsRegistry.cpp; sourceTree = "<group>"; };
     11509                9BD4E9191C462CFC005065BC /* CustomElementsRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomElementsRegistry.h; sourceTree = "<group>"; };
    1150511510                9BD8A95918BEFC7600987E9A /* CollectionIndexCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CollectionIndexCache.cpp; sourceTree = "<group>"; };
     11511                9BE671091D5AEB0400345514 /* JSCustomElementsRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSCustomElementsRegistry.cpp; path = "JSCustomElementsRegistry.cpp"; sourceTree = "<group>"; };
     11512                9BE6710A1D5AEB0400345514 /* JSCustomElementsRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSCustomElementsRegistry.h; path = "JSCustomElementsRegistry.h"; sourceTree = "<group>"; };
    1150611513                9BF9A87E1648DD2F001C6B23 /* JSHTMLFormControlsCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLFormControlsCollection.cpp; sourceTree = "<group>"; };
    1150711514                9BF9A87F1648DD2F001C6B23 /* JSHTMLFormControlsCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLFormControlsCollection.h; sourceTree = "<group>"; };
     
    2048520492                                FE6FD48B0F676E9300092873 /* JSCoordinates.cpp */,
    2048620493                                FE6FD48C0F676E9300092873 /* JSCoordinates.h */,
     20494                                9BE671091D5AEB0400345514 /* JSCustomElementsRegistry.cpp */,
     20495                                9BE6710A1D5AEB0400345514 /* JSCustomElementsRegistry.h */,
    2048720496                                BCA83E4D0D7CE1E9003421A8 /* JSDataTransfer.cpp */,
    2048820497                                BCA83E4E0D7CE1E9003421A8 /* JSDataTransfer.h */,
     
    2209122100                                AD726FEA16D9F40B003A4E6D /* JSCSSStyleDeclarationCustom.h */,
    2209222101                                BC20FB7E0C0E8E6C00D1447F /* JSCSSValueCustom.cpp */,
     22102                                9BC5F9DF1D5AAF6A002B749D /* JSCustomElementsRegistryCustom.cpp */,
    2209322103                                DEC2975D1B4DEB2A005F5945 /* JSCustomEventCustom.cpp */,
    2209422104                                07FBDE2B18FED178001A7CFF /* JSDataCueCustom.cpp */,
     
    2393223942                                97627B8B14FB3CEE002CDCA1 /* ContextDestructionObserver.cpp */,
    2393323943                                97627B8C14FB3CEE002CDCA1 /* ContextDestructionObserver.h */,
    23934                                 9BD4E9181C462CFC005065BC /* CustomElementDefinitions.cpp */,
    23935                                 9BD4E9191C462CFC005065BC /* CustomElementDefinitions.h */,
     23944                                9BD4E9181C462CFC005065BC /* CustomElementsRegistry.cpp */,
     23945                                9BD4E9191C462CFC005065BC /* CustomElementsRegistry.h */,
     23946                                9BC5F9DE1D5AAD5D002B749D /* CustomElementsRegistry.idl */,
    2393623947                                62CD32561157E57C0063B0A7 /* CustomEvent.cpp */,
    2393723948                                62CD32571157E57C0063B0A7 /* CustomEvent.h */,
     
    2517825189                                BC2272A20E82E87C00E7F975 /* CursorData.h in Headers */,
    2517925190                                BC2272AD0E82E8F300E7F975 /* CursorList.h in Headers */,
    25180                                 9BD4E91B1C462CFC005065BC /* CustomElementDefinitions.h in Headers */,
     25191                                9BD4E91B1C462CFC005065BC /* CustomElementsRegistry.h in Headers */,
    2518125192                                62CD325A1157E57C0063B0A7 /* CustomEvent.h in Headers */,
    2518225193                                A8CB413E0E8633FD0032C4F0 /* DashArray.h in Headers */,
     
    2680426815                                CDBEAEAD19D92B6C00BEBA88 /* MediaSelectionGroupAVFObjC.h in Headers */,
    2680526816                                C9027F421B1D0AD200BFBFEF /* MediaSession.h in Headers */,
     26817                                9BE6710C1D5AEB2500345514 /* JSCustomElementsRegistry.h in Headers */,
    2680626818                                C9F87CFE1B28F40E00979B83 /* MediaSessionEvents.h in Headers */,
    2680726819                                C96F5EC81B5872260091EA9D /* MediaSessionInterruptionProvider.h in Headers */,
     
    2901629028                                265541521489B233000DFC5D /* CursorIOS.cpp in Sources */,
    2901729029                                93F19A2608245E59001E9ABC /* CursorMac.mm in Sources */,
    29018                                 9BD4E91A1C462CFC005065BC /* CustomElementDefinitions.cpp in Sources */,
     29030                                9BD4E91A1C462CFC005065BC /* CustomElementsRegistry.cpp in Sources */,
    2901929031                                62CD32591157E57C0063B0A7 /* CustomEvent.cpp in Sources */,
    2902029032                                97BC6A201505F081001B74AC /* Database.cpp in Sources */,
     
    3052230534                                BCE1C41C0D982981003B02F2 /* Location.cpp in Sources */,
    3052330535                                A8239E0009B3CF8A00B60641 /* Logging.cpp in Sources */,
     30536                                9BE6710B1D5AEB2100345514 /* JSCustomElementsRegistry.cpp in Sources */,
    3052430537                                1402645E0AFDC19B005919E2 /* LoggingMac.mm in Sources */,
    3052530538                                1A0409F31A43675C009E47F3 /* MachSendRight.cpp in Sources */,
     
    3104331056                                073BE34E17D180B2002BD431 /* RTCSessionDescriptionDescriptor.cpp in Sources */,
    3104431057                                078E090E17D14CEE00420AA1 /* RTCStatsReport.cpp in Sources */,
     31058                                9BC5F9E01D5AAF6B002B749D /* JSCustomElementsRegistryCustom.cpp in Sources */,
    3104531059                                078E091017D14CEE00420AA1 /* RTCStatsResponse.cpp in Sources */,
    3104631060                                5E2C43671BCEE3770001E2BC /* RTCTrackEvent.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp

    r204246 r204367  
    2121#include "JSDocument.h"
    2222
    23 #include "CustomElementDefinitions.h"
    2423#include "ExceptionCode.h"
    2524#include "Frame.h"
     
    143142#endif
    144143
    145 #if ENABLE(CUSTOM_ELEMENTS)
    146 JSValue JSDocument::defineElement(ExecState& state)
    147 {
    148     AtomicString tagName(state.argument(0).toString(&state)->toAtomicString(&state));
    149     if (UNLIKELY(state.hadException()))
    150         return jsUndefined();
    151 
    152     JSObject* object = state.argument(1).getObject();
    153     ConstructData callData;
    154     if (!object || object->methodTable()->getConstructData(object, callData) == ConstructType::None)
    155         return throwTypeError(&state, ASCIILiteral("The second argument must be a constructor"));
    156 
    157     Document& document = wrapped();
    158     if (!document.domWindow()) {
    159         throwNotSupportedError(state, "Cannot define a custom element in a docuemnt without a browsing context");
    160         return jsUndefined();
    161     }
    162 
    163     switch (Document::validateCustomElementName(tagName)) {
    164     case CustomElementNameValidationStatus::Valid:
    165         break;
    166     case CustomElementNameValidationStatus::ConflictsWithBuiltinNames:
    167         return throwSyntaxError(&state, "Custom element name cannot be same as one of the builtin elements");
    168     case CustomElementNameValidationStatus::NoHyphen:
    169         return throwSyntaxError(&state, "Custom element name must contain a hyphen");
    170     case CustomElementNameValidationStatus::ContainsUpperCase:
    171         return throwSyntaxError(&state, "Custom element name cannot contain an upper case letter");
    172     }
    173 
    174     auto& definitions = document.ensureCustomElementDefinitions();
    175     if (definitions.findInterface(tagName)) {
    176         throwNotSupportedError(state, "Cannot define multiple custom elements with the same tag name");
    177         return jsUndefined();
    178     }
    179 
    180     if (definitions.containsConstructor(object)) {
    181         throwNotSupportedError(state, "Cannot define multiple custom elements with the same class");
    182         return jsUndefined();
    183     }
    184 
    185     // FIXME: 10. Let prototype be Get(constructor, "prototype"). Rethrow any exceptions.
    186     // FIXME: 11. If Type(prototype) is not Object, throw a TypeError exception.
    187     // FIXME: 12. Let attachedCallback be Get(prototype, "attachedCallback"). Rethrow any exceptions.
    188     // FIXME: 13. Let detachedCallback be Get(prototype, "detachedCallback"). Rethrow any exceptions.
    189     // FIXME: 14. Let attributeChangedCallback be Get(prototype, "attributeChangedCallback"). Rethrow any exceptions.
    190 
    191     PrivateName uniquePrivateName;
    192     globalObject()->putDirect(globalObject()->vm(), uniquePrivateName, object);
    193 
    194     QualifiedName name(nullAtom, tagName, HTMLNames::xhtmlNamespaceURI);
    195     definitions.addElementDefinition(JSCustomElementInterface::create(name, object, globalObject()));
    196 
    197     // FIXME: 17. Let map be registry's upgrade candidates map.
    198     // FIXME: 18. Upgrade a newly-defined element given map and definition.
    199 
    200     return jsUndefined();
    201 }
    202 #endif
    203 
    204144} // namespace WebCore
  • trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp

    r202981 r204367  
    2727#include "JSHTMLElement.h"
    2828
    29 #include "CustomElementDefinitions.h"
     29#include "CustomElementsRegistry.h"
     30#include "DOMWindow.h"
    3031#include "Document.h"
    3132#include "HTMLFormElement.h"
     33#include "JSCustomElementInterface.h"
    3234#include "JSNodeCustom.h"
    3335#include <runtime/InternalFunction.h>
     
    4850    auto& document = downcast<Document>(*context);
    4951
    50     auto* definitions = document.customElementDefinitions();
    51     if (!definitions)
    52         return throwVMTypeError(&exec, "new.target is not a valid custom element constructor");
     52    auto* window = document.domWindow();
     53    if (!window)
     54        return throwVMTypeError(&exec, ASCIILiteral("new.target is not a valid custom element constructor"));
     55
     56    auto* registry = window->customElementsRegistry();
     57    if (!registry)
     58        return throwVMTypeError(&exec, ASCIILiteral("new.target is not a valid custom element constructor"));
    5359
    5460    VM& vm = exec.vm();
    5561    JSValue newTargetValue = exec.thisValue();
    5662    JSObject* newTarget = newTargetValue.getObject();
    57     auto* elementInterface = definitions->findInterface(newTarget);
     63    auto* elementInterface = registry->findInterface(newTarget);
    5864    if (!elementInterface)
    59         return throwVMTypeError(&exec, "new.target does not define a custom element");
     65        return throwVMTypeError(&exec, ASCIILiteral("new.target does not define a custom element"));
    6066
    6167    if (!elementInterface->isUpgradingElement()) {
     
    7581    Element* elementToUpgrade = elementInterface->lastElementInConstructionStack();
    7682    if (!elementToUpgrade) {
    77         throwInvalidStateError(exec, "Cannot instantiate a custom element inside its own constrcutor during upgrades");
     83        throwInvalidStateError(exec, ASCIILiteral("Cannot instantiate a custom element inside its own constrcutor during upgrades"));
    7884        return JSValue::encode(jsUndefined());
    7985    }
  • trunk/Source/WebCore/dom/CustomElementsRegistry.cpp

    r204366 r204367  
    11/*
    2  * Copyright (C) 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#include "config.h"
    27 #include "CustomElementDefinitions.h"
     27#include "CustomElementsRegistry.h"
    2828
    2929#if ENABLE(CUSTOM_ELEMENTS)
     
    4040namespace WebCore {
    4141
    42 void CustomElementDefinitions::addElementDefinition(Ref<JSCustomElementInterface>&& elementInterface)
     42Ref<CustomElementsRegistry> CustomElementsRegistry::create()
     43{
     44    return adoptRef(*new CustomElementsRegistry());
     45}
     46
     47CustomElementsRegistry::CustomElementsRegistry()
     48{ }
     49
     50CustomElementsRegistry::~CustomElementsRegistry()
     51{ }
     52
     53void CustomElementsRegistry::addElementDefinition(Ref<JSCustomElementInterface>&& elementInterface)
    4354{
    4455    AtomicString localName = elementInterface->name().localName();
     
    6475}
    6576
    66 void CustomElementDefinitions::addUpgradeCandidate(Element& candidate)
     77void CustomElementsRegistry::addUpgradeCandidate(Element& candidate)
    6778{
    6879    auto result = m_upgradeCandidatesMap.ensure(candidate.localName(), [] {
     
    7485}
    7586
    76 JSCustomElementInterface* CustomElementDefinitions::findInterface(const QualifiedName& name) const
     87JSCustomElementInterface* CustomElementsRegistry::findInterface(const QualifiedName& name) const
    7788{
    7889    auto it = m_nameMap.find(name.localName());
    79     return it == m_nameMap.end() || it->value->name() != name ? nullptr : it->value.get();
     90    return it == m_nameMap.end() || it->value->name() != name ? nullptr : const_cast<JSCustomElementInterface*>(it->value.ptr());
    8091}
    8192
    82 JSCustomElementInterface* CustomElementDefinitions::findInterface(const AtomicString& name) const
     93JSCustomElementInterface* CustomElementsRegistry::findInterface(const AtomicString& name) const
    8394{
    8495    return m_nameMap.get(name);
    8596}
    8697
    87 JSCustomElementInterface* CustomElementDefinitions::findInterface(const JSC::JSObject* constructor) const
     98JSCustomElementInterface* CustomElementsRegistry::findInterface(const JSC::JSObject* constructor) const
    8899{
    89100    return m_constructorMap.get(constructor);
    90101}
    91102
    92 bool CustomElementDefinitions::containsConstructor(const JSC::JSObject* constructor) const
     103bool CustomElementsRegistry::containsConstructor(const JSC::JSObject* constructor) const
    93104{
    94105    return m_constructorMap.contains(constructor);
  • trunk/Source/WebCore/dom/CustomElementsRegistry.h

    r204366 r204367  
    2424 */
    2525
    26 #include "JSCustomElementInterface.h"
     26#pragma once
     27
     28#if ENABLE(CUSTOM_ELEMENTS)
     29
    2730#include "QualifiedName.h"
    2831#include <wtf/HashMap.h>
    2932#include <wtf/text/AtomicString.h>
    3033#include <wtf/text/AtomicStringHash.h>
    31 
    32 #ifndef CustomElementDefinitions_h
    33 #define CustomElementDefinitions_h
    34 
    35 #if ENABLE(CUSTOM_ELEMENTS)
    3634
    3735namespace JSC {
     
    4442
    4543class Element;
     44class JSCustomElementInterface;
    4645class QualifiedName;
    4746
    48 class CustomElementDefinitions {
    49     WTF_MAKE_FAST_ALLOCATED;
     47class CustomElementsRegistry : public RefCounted<CustomElementsRegistry> {
    5048public:
     49    static Ref<CustomElementsRegistry> create();
     50    ~CustomElementsRegistry();
     51
    5152    void addElementDefinition(Ref<JSCustomElementInterface>&&);
    5253    void addUpgradeCandidate(Element&);
     
    5859
    5960private:
     61    CustomElementsRegistry();
     62
    6063    HashMap<AtomicString, Vector<RefPtr<Element>>> m_upgradeCandidatesMap;
    61     HashMap<AtomicString, RefPtr<JSCustomElementInterface>> m_nameMap;
     64    HashMap<AtomicString, Ref<JSCustomElementInterface>> m_nameMap;
    6265    HashMap<const JSC::JSObject*, JSCustomElementInterface*> m_constructorMap;
    6366};
     
    6669
    6770#endif
    68 
    69 #endif /* CustomElementDefinitions_h */
  • trunk/Source/WebCore/dom/Document.cpp

    r204260 r204367  
    4545#include "ContentSecurityPolicy.h"
    4646#include "CookieJar.h"
    47 #include "CustomElementDefinitions.h"
     47#include "CustomElementsRegistry.h"
    4848#include "CustomEvent.h"
    4949#include "DOMImplementation.h"
     
    101101#include "ImageLoader.h"
    102102#include "InspectorInstrumentation.h"
     103#include "JSCustomElementInterface.h"
    103104#include "JSLazyEventListener.h"
    104105#include "JSModuleLoader.h"
     
    880881}
    881882
     883#if ENABLE(CUSTOM_ELEMENTS)
     884static ALWAYS_INLINE RefPtr<HTMLElement> createUpgradeCandidateElement(Document& document, DOMWindow* window, const QualifiedName& name)
     885{
     886    if (!window || !RuntimeEnabledFeatures::sharedFeatures().customElementsEnabled())
     887        return nullptr;
     888
     889    if (Document::validateCustomElementName(name.localName()) != CustomElementNameValidationStatus::Valid)
     890        return nullptr;
     891
     892    auto element = HTMLElement::create(name, document);
     893    element->setIsUnresolvedCustomElement();
     894    window->ensureCustomElementsRegistry().addUpgradeCandidate(element.get());
     895    return WTFMove(element);
     896}
     897#endif
     898
    882899static RefPtr<Element> createHTMLElementWithNameValidation(Document& document, const AtomicString& localName, ExceptionCode& ec)
    883900{
     
    887904
    888905#if ENABLE(CUSTOM_ELEMENTS)
    889     auto* definitions = document.customElementDefinitions();
    890     if (UNLIKELY(definitions)) {
    891         if (auto* elementInterface = definitions->findInterface(localName))
    892             return elementInterface->constructElement(localName, JSCustomElementInterface::ShouldClearException::DoNotClear);
     906    auto* window = document.domWindow();
     907    if (window) {
     908        auto* registry = window->customElementsRegistry();
     909        if (UNLIKELY(registry)) {
     910            if (auto* elementInterface = registry->findInterface(localName))
     911                return elementInterface->constructElement(localName, JSCustomElementInterface::ShouldClearException::DoNotClear);
     912        }
    893913    }
    894914#endif
     
    902922
    903923#if ENABLE(CUSTOM_ELEMENTS)
    904     if (RuntimeEnabledFeatures::sharedFeatures().customElementsEnabled()
    905         && Document::validateCustomElementName(localName) == CustomElementNameValidationStatus::Valid) {
    906         Ref<HTMLElement> element = HTMLElement::create(qualifiedName, document);
    907         element->setIsUnresolvedCustomElement();
    908         document.ensureCustomElementDefinitions().addUpgradeCandidate(element.get());
     924    if (auto element = createUpgradeCandidateElement(document, window, qualifiedName))
    909925        return WTFMove(element);
    910     }
    911926#endif
    912927
     
    10721087{
    10731088#if ENABLE(CUSTOM_ELEMENTS)
    1074     auto* definitions = document.customElementDefinitions();
    1075     if (UNLIKELY(definitions)) {
    1076         if (auto* elementInterface = definitions->findInterface(name)) {
    1077             Ref<HTMLElement> element = HTMLElement::create(name, document);
    1078             element->setIsUnresolvedCustomElement();
    1079             LifecycleCallbackQueue::enqueueElementUpgrade(element.get(), *elementInterface);
    1080             return element;
     1089    auto* window = document.domWindow();
     1090    if (window) {
     1091        auto* registry = window->customElementsRegistry();
     1092        if (UNLIKELY(registry)) {
     1093            if (auto* elementInterface = registry->findInterface(name)) {
     1094                auto element = HTMLElement::create(name, document);
     1095                element->setIsUnresolvedCustomElement();
     1096                LifecycleCallbackQueue::enqueueElementUpgrade(element.get(), *elementInterface);
     1097                return element;
     1098            }
    10811099        }
    10821100    }
    10831101    // FIXME: Should we also check the equality of prefix between the custom element and name?
    1084     if (Document::validateCustomElementName(name.localName()) == CustomElementNameValidationStatus::Valid) {
    1085         Ref<HTMLElement> element = HTMLElement::create(name, document);
    1086         element->setIsUnresolvedCustomElement();
    1087         document.ensureCustomElementDefinitions().addUpgradeCandidate(element.get());
    1088         return element;
    1089     }
     1102    if (auto element = createUpgradeCandidateElement(document, window, name))
     1103        return element.releaseNonNull();
    10901104#endif
    10911105    return HTMLUnknownElement::create(name, document);
     
    64976511}
    64986512
    6499 #if ENABLE(CUSTOM_ELEMENTS)
    6500 CustomElementDefinitions& Document::ensureCustomElementDefinitions()
    6501 {
    6502     if (!m_customElementDefinitions)
    6503         m_customElementDefinitions = std::make_unique<CustomElementDefinitions>();
    6504     return *m_customElementDefinitions;
    6505 }
    6506 #endif
    6507 
    65086513LayoutRect Document::absoluteEventHandlerBounds(bool& includesFixedPositionElements)
    65096514{
  • trunk/Source/WebCore/dom/Document.h

    r204259 r204367  
    179179#endif
    180180
    181 #if ENABLE(CUSTOM_ELEMENTS)
    182 class CustomElementDefinitions;
    183 #endif
    184 
    185181#if ENABLE(DASHBOARD_SUPPORT)
    186182struct AnnotatedRegionValue;
     
    12201216    }
    12211217
    1222 #if ENABLE(CUSTOM_ELEMENTS)
    1223     CustomElementDefinitions* customElementDefinitions() { return m_customElementDefinitions.get(); }
    1224     CustomElementDefinitions& ensureCustomElementDefinitions();
    1225 #endif
    1226 
    12271218    const EventTargetSet* wheelEventTargets() const { return m_wheelEventTargets.get(); }
    12281219
     
    17541745    Document* m_templateDocumentHost; // Manually managed weakref (backpointer from m_templateDocument).
    17551746
    1756 #if ENABLE(CUSTOM_ELEMENTS)
    1757     std::unique_ptr<CustomElementDefinitions> m_customElementDefinitions;
    1758 #endif
    1759 
    17601747    Ref<CSSFontSelector> m_fontSelector;
    17611748
  • trunk/Source/WebCore/dom/Document.idl

    r204259 r204367  
    244244#endif
    245245
    246     [Custom, RaisesException, Conditional=CUSTOM_ELEMENTS, EnabledAtRuntime=CustomElements]
    247     void defineElement(DOMString localName, Function constructor);
    248246#endif
    249247
  • trunk/Source/WebCore/dom/Element.cpp

    r204235 r204367  
    3838#include "ComposedTreeAncestorIterator.h"
    3939#include "ContainerNodeAlgorithms.h"
    40 #include "CustomElementDefinitions.h"
     40#include "CustomElementsRegistry.h"
    4141#include "DOMTokenList.h"
    4242#include "Dictionary.h"
     
    12931293#if ENABLE(CUSTOM_ELEMENTS)
    12941294    if (UNLIKELY(isCustomElement())) {
    1295         auto* definitions = document().customElementDefinitions();
    1296         auto* elementInterface = definitions->findInterface(tagQName());
    1297         RELEASE_ASSERT(elementInterface);
    1298         LifecycleCallbackQueue::enqueueAttributeChangedCallback(*this, *elementInterface, name, oldValue, newValue);
     1295        if (auto* window = document().domWindow()) {
     1296            if (auto* registry = window->customElementsRegistry()) {
     1297                auto* elementInterface = registry->findInterface(tagQName());
     1298                RELEASE_ASSERT(elementInterface);
     1299                LifecycleCallbackQueue::enqueueAttributeChangedCallback(*this, *elementInterface, name, oldValue, newValue);
     1300            }
     1301        }
    12991302    }
    13001303#endif
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp

    r202559 r204367  
    2929
    3030#include "Comment.h"
    31 #include "CustomElementDefinitions.h"
     31#include "CustomElementsRegistry.h"
     32#include "DOMWindow.h"
    3233#include "DocumentFragment.h"
    3334#include "DocumentType.h"
     
    659660    if (UNLIKELY(!element)) {
    660661#if ENABLE(CUSTOM_ELEMENTS)
    661         if (customElementInterface) {
    662             auto* definitions = ownerDocument.customElementDefinitions();
    663             if (UNLIKELY(definitions)) {
    664                 if (auto* elementInterface = definitions->findInterface(localName)) {
     662        auto* window = ownerDocument.domWindow();
     663        if (customElementInterface && window) {
     664            auto* registry = window->customElementsRegistry();
     665            if (UNLIKELY(registry)) {
     666                if (auto* elementInterface = registry->findInterface(localName)) {
    665667                    *customElementInterface = elementInterface;
    666668                    return nullptr;
     
    674676        QualifiedName qualifiedName(nullAtom, localName, xhtmlNamespaceURI);
    675677#if ENABLE(CUSTOM_ELEMENTS)
    676         if (Document::validateCustomElementName(localName) == CustomElementNameValidationStatus::Valid) {
     678        if (window && Document::validateCustomElementName(localName) == CustomElementNameValidationStatus::Valid) {
    677679            element = HTMLElement::create(qualifiedName, ownerDocument);
    678680            element->setIsUnresolvedCustomElement();
    679             ownerDocument.ensureCustomElementDefinitions().addUpgradeCandidate(*element);
     681            window->ensureCustomElementsRegistry().addUpgradeCandidate(*element);
    680682        } else
    681683#endif
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r204259 r204367  
    3939#include "ContentExtensionRule.h"
    4040#include "Crypto.h"
     41#include "CustomElementsRegistry.h"
    4142#include "DOMApplicationCache.h"
    4243#include "DOMSelection.h"
     
    618619}
    619620
     621#if ENABLE(CUSTOM_ELEMENTS)
     622CustomElementsRegistry& DOMWindow::ensureCustomElementsRegistry()
     623{
     624    if (!m_customElementsRegistry)
     625        m_customElementsRegistry = CustomElementsRegistry::create();
     626    return *m_customElementsRegistry;
     627}
     628#endif
     629
    620630#if ENABLE(ORIENTATION_EVENTS)
    621631int DOMWindow::orientation() const
  • trunk/Source/WebCore/page/DOMWindow.h

    r204259 r204367  
    5050    class CSSStyleDeclaration;
    5151    class Crypto;
     52    class CustomElementsRegistry;
    5253    class DOMApplicationCache;
    5354    class DOMSelection;
     
    305306        DOMApplicationCache* optionalApplicationCache() const { return m_applicationCache.get(); }
    306307
     308#if ENABLE(CUSTOM_ELEMENTS)
     309        CustomElementsRegistry* customElementsRegistry() { return m_customElementsRegistry.get(); }
     310        CustomElementsRegistry& ensureCustomElementsRegistry();
     311#endif
     312
    307313#if ENABLE(ORIENTATION_EVENTS)
    308314        // This is the interface orientation in degrees. Some examples are:
     
    417423        mutable RefPtr<DOMApplicationCache> m_applicationCache;
    418424
     425#if ENABLE(CUSTOM_ELEMENTS)
     426        RefPtr<CustomElementsRegistry> m_customElementsRegistry;
     427#endif
     428
    419429#if ENABLE(WEB_TIMING)
    420430        mutable RefPtr<Performance> m_performance;
  • trunk/Source/WebCore/page/DOMWindow.idl

    r204246 r204367  
    202202#endif // defined(LANGUAGE_JAVASCRIPT)
    203203
     204#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
     205    [Conditional=CUSTOM_ELEMENTS, ImplementedAs=ensureCustomElementsRegistry] readonly attribute CustomElementsRegistry customElements;
     206#endif
     207
    204208
    205209    // Event Handlers
Note: See TracChangeset for help on using the changeset viewer.