<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[204611] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/204611">204611</a></dd>
<dt>Author</dt> <dd>rniwa@webkit.org</dd>
<dt>Date</dt> <dd>2016-08-18 15:19:59 -0700 (Thu, 18 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add basic support for connected and disconnected callbacks
https://bugs.webkit.org/show_bug.cgi?id=160950

Reviewed by Chris Dumez.

Source/WebCore:

Added the basic support for custom elements' connectedCallback and disconnectedCallback. These callbacks
are enqueued by inserting and removing a node as spec'ed by https://dom.spec.whatwg.org/#concept-node-insert
and https://dom.spec.whatwg.org/#concept-node-remove

For now, we only support callbacks on appendChild and removeChild to limit the amount of code changes and
tests that need to be included in this patch.

This patch also renames InvokesCustomElementLifecycleCallbacks IDL attribute to CEReactions to match
the latest specification: https://html.spec.whatwg.org/multipage/scripting.html#cereactions

Tests: fast/custom-elements/connected-callbacks.html
       fast/custom-elements/disconnected-callbacks.html

* bindings/js/JSCustomElementInterface.cpp:
(WebCore::JSCustomElementInterface::invokeCallback): Extracted from invokeAttributeChangedCallback.
(WebCore::JSCustomElementInterface::setConnectedCallback): Added.
(WebCore::JSCustomElementInterface::invokeConnectedCallback): Added.
(WebCore::JSCustomElementInterface::setDisconnectedCallback): Added.
(WebCore::JSCustomElementInterface::invokeDisconnectedCallback): Added.
(WebCore::JSCustomElementInterface::setAttributeChangedCallback):
(WebCore::JSCustomElementInterface::invokeAttributeChangedCallback): Renamed from attributeChanged.
* bindings/js/JSCustomElementInterface.h: Added m_connectedCallback and m_disconnectedCallback as instance
variables. Also removed the superfluous mutable qualifier from m_constructor m_attributeChangedCallback.
* bindings/js/JSCustomElementsRegistryCustom.cpp:
(WebCore::JSCustomElementsRegistry::define): Store connectedCallback and disconnectedCallback.
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
* bindings/scripts/IDLAttributes.txt:
* dom/CustomElementsRegistry.idl:
* dom/Element.cpp:
(WebCore::Element::insertedInto): Call enqueueConnectedCallbackIfNeeded.
(WebCore::Element::removedFrom): Call enqueueDisconnectedCallbackIfNeeded.
* dom/Element.idl:
* dom/LifecycleCallbackQueue.cpp:
(WebCore::LifecycleQueueItem::invoke): Added calls to invokeConnectedCallback and invokeDisconnectedCallback.
(WebCore::findInterfaceForCustomElement): Extracted from enqueueAttributeChangedCallbackIfNeeded.
(WebCore::LifecycleCallbackQueue::enqueueConnectedCallbackIfNeeded): Added.
(WebCore::LifecycleCallbackQueue::enqueueDisconnectedCallbackIfNeeded): Added.
(WebCore::LifecycleCallbackQueue::enqueueAttributeChangedCallbackIfNeeded):
(WebCore::CustomElementLifecycleProcessingStack::ensureCurrentQueue):
* dom/LifecycleCallbackQueue.h:
* dom/Node.idl:

LayoutTests:

Added W3C style testharness.js tests for connectedCallback and disconnectedCallback.

Four test cases are failing due to a bug in window-less document's custom element registry,
which will be addressed in a future patch.

* fast/custom-elements/connected-callbacks-expected.txt: Added.
* fast/custom-elements/connected-callbacks.html: Added.
* fast/custom-elements/disconnected-callbacks-expected.txt: Added.
* fast/custom-elements/disconnected-callbacks.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSCustomElementInterfacecpp">trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSCustomElementInterfaceh">trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSCustomElementsRegistryCustomcpp">trunk/Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm">trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptsIDLAttributestxt">trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt</a></li>
<li><a href="#trunkSourceWebCoredomCustomElementsRegistryidl">trunk/Source/WebCore/dom/CustomElementsRegistry.idl</a></li>
<li><a href="#trunkSourceWebCoredomElementcpp">trunk/Source/WebCore/dom/Element.cpp</a></li>
<li><a href="#trunkSourceWebCoredomElementidl">trunk/Source/WebCore/dom/Element.idl</a></li>
<li><a href="#trunkSourceWebCoredomLifecycleCallbackQueuecpp">trunk/Source/WebCore/dom/LifecycleCallbackQueue.cpp</a></li>
<li><a href="#trunkSourceWebCoredomLifecycleCallbackQueueh">trunk/Source/WebCore/dom/LifecycleCallbackQueue.h</a></li>
<li><a href="#trunkSourceWebCoredomNodeidl">trunk/Source/WebCore/dom/Node.idl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastcustomelementsconnectedcallbacksexpectedtxt">trunk/LayoutTests/fast/custom-elements/connected-callbacks-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastcustomelementsconnectedcallbackshtml">trunk/LayoutTests/fast/custom-elements/connected-callbacks.html</a></li>
<li><a href="#trunkLayoutTestsfastcustomelementsdisconnectedcallbacksexpectedtxt">trunk/LayoutTests/fast/custom-elements/disconnected-callbacks-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastcustomelementsdisconnectedcallbackshtml">trunk/LayoutTests/fast/custom-elements/disconnected-callbacks.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/LayoutTests/ChangeLog        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2016-08-17  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        Add basic support for connected and disconnected callbacks
+        https://bugs.webkit.org/show_bug.cgi?id=160950
+
+        Reviewed by Chris Dumez.
+
+        Added W3C style testharness.js tests for connectedCallback and disconnectedCallback.
+
+        Four test cases are failing due to a bug in window-less document's custom element registry,
+        which will be addressed in a future patch.
+
+        * fast/custom-elements/connected-callbacks-expected.txt: Added.
+        * fast/custom-elements/connected-callbacks.html: Added.
+        * fast/custom-elements/disconnected-callbacks-expected.txt: Added.
+        * fast/custom-elements/disconnected-callbacks.html: Added.
+
</ins><span class="cx"> 2016-08-18  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Align our encoding labels with the encoding specification
</span></span></pre></div>
<a id="trunkLayoutTestsfastcustomelementsconnectedcallbacksexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/custom-elements/connected-callbacks-expected.txt (0 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/custom-elements/connected-callbacks-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/custom-elements/connected-callbacks-expected.txt        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+
+PASS Inserting a custom element into a document must enqueue and invoke connectedCallback 
+PASS Inserting a custom element into a detached node must not enqueue and invoke connectedCallback 
+FAIL Inserting a custom element into a window-less document must enqueue and invoke connectedCallback assert_array_equals: lengths differ, expected 2 got 0
+PASS Inserting an ancestor of a custom element into a document must enqueue and invoke connectedCallback 
+FAIL Inserting an ancestor of custom element into a window-less document must enqueue and invoke connectedCallback assert_array_equals: lengths differ, expected 2 got 0
+PASS Inserting a custom element into a connected shadow tree must enqueue and invoke connectedCallback 
+PASS Inserting the shadow host of a shadow tree with a custom element into a document must enqueue and invoke connectedCallback 
+PASS Inserting a custom element into a detached shadow tree must not enqueue and invoke connectedCallback 
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastcustomelementsconnectedcallbackshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/custom-elements/connected-callbacks.html (0 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/custom-elements/connected-callbacks.html                                (rev 0)
+++ trunk/LayoutTests/fast/custom-elements/connected-callbacks.html        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -0,0 +1,104 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;Custom Elements: connectedCallback&lt;/title&gt;
+&lt;meta name=&quot;author&quot; title=&quot;Ryosuke Niwa&quot; href=&quot;mailto:rniwa@webkit.org&quot;&gt;
+&lt;meta name=&quot;assert&quot; content=&quot;connectedCallback must be enqueued whenever custom element is inserted into a document&quot;&gt;
+&lt;link rel=&quot;help&quot; href=&quot;https://w3c.github.io/webcomponents/spec/custom/#dfn-connected-callback&quot;&gt;
+&lt;script src=&quot;../../resources/testharness.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../../resources/testharnessreport.js&quot;&gt;&lt;/script&gt;
+&lt;link rel='stylesheet' href='../../resources/testharness.css'&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div id=&quot;log&quot;&gt;&lt;/div&gt;
+&lt;script&gt;
+
+var calls = [];
+class MyCustomElement extends HTMLElement {
+    connectedCallback() { calls.push('connected', this); }
+    disconnectedCallback() { calls.push('disconnected', this); }
+}
+customElements.define('my-custom-element', MyCustomElement);
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+
+    calls = [];
+    document.body.appendChild(instance);
+    assert_array_equals(calls, ['connected', instance]);
+}, 'Inserting a custom element into a document must enqueue and invoke connectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+
+    calls = [];
+    var parent = document.createElement('div');
+    parent.appendChild(instance);
+    assert_array_equals(calls, []);
+}, 'Inserting a custom element into a detached node must not enqueue and invoke connectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var documentWithoutWindow = document.implementation.createHTMLDocument();
+
+    calls = [];
+    documentWithoutWindow.body.appendChild(instance);
+    assert_array_equals(calls, ['connected', instance]);
+}, 'Inserting a custom element into a window-less document must enqueue and invoke connectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var parent = document.createElement('div');
+    parent.appendChild(instance);
+
+    calls = [];
+    document.body.appendChild(parent);
+    assert_array_equals(calls, ['connected', instance]);
+}, 'Inserting an ancestor of a custom element into a document must enqueue and invoke connectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var parent = document.createElement('div');
+    parent.appendChild(instance);
+    var documentWithoutWindow = document.implementation.createHTMLDocument();
+
+    calls = [];
+    documentWithoutWindow.body.appendChild(parent);
+    assert_array_equals(calls, ['connected', instance]);
+}, 'Inserting an ancestor of custom element into a window-less document must enqueue and invoke connectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var host = document.createElement('div');
+    var shadowRoot = host.attachShadow({mode: 'closed'});
+    document.body.appendChild(host);
+
+    calls = [];
+    shadowRoot.appendChild(instance);
+    assert_array_equals(calls, ['connected', instance]);
+}, 'Inserting a custom element into a connected shadow tree must enqueue and invoke connectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var host = document.createElement('div');
+    var shadowRoot = host.attachShadow({mode: 'closed'});
+    shadowRoot.appendChild(instance);
+
+    calls = [];
+    document.body.appendChild(host);
+    assert_array_equals(calls, ['connected', instance]);
+}, 'Inserting the shadow host of a shadow tree with a custom element into a document must enqueue and invoke connectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var host = document.createElement('div');
+    var shadowRoot = host.attachShadow({mode: 'closed'});
+
+    calls = [];
+    shadowRoot.appendChild(instance);
+    assert_array_equals(calls, []);
+}, 'Inserting a custom element into a detached shadow tree must not enqueue and invoke connectedCallback');
+
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastcustomelementsdisconnectedcallbacksexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/custom-elements/disconnected-callbacks-expected.txt (0 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/custom-elements/disconnected-callbacks-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/custom-elements/disconnected-callbacks-expected.txt        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+
+PASS Removing a custom element from a document must enqueue and invoke disconnectedCallback 
+PASS Removing a custom element from a detahed node must not enqueue and invoke connectedCallback 
+FAIL Removing a custom element from a window-less document must enqueue and invoke disconnectedCallback assert_array_equals: lengths differ, expected 2 got 0
+PASS Removing an ancestor of a custom element from a document must enqueue and invoke disconnectedCallback 
+FAIL Removing an ancestor of custom element from a a window-less document must enqueue and invoke disconnectedCallback assert_array_equals: lengths differ, expected 2 got 0
+PASS Removing a custom element from a connected shadow tree must enqueue and invoke disconnectedCallback 
+PASS Removing the shadow host of a shadow tree with a custom element from a document must enqueue and invoke disconnectedCallback 
+PASS Removing a custom element from a detached shadow tree must not enqueue and invoke disconnectedCallback 
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastcustomelementsdisconnectedcallbackshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/custom-elements/disconnected-callbacks.html (0 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/custom-elements/disconnected-callbacks.html                                (rev 0)
+++ trunk/LayoutTests/fast/custom-elements/disconnected-callbacks.html        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -0,0 +1,113 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;Custom Elements: disconnectedCallback&lt;/title&gt;
+&lt;meta name=&quot;author&quot; title=&quot;Ryosuke Niwa&quot; href=&quot;mailto:rniwa@webkit.org&quot;&gt;
+&lt;meta name=&quot;assert&quot; content=&quot;disconnectedCallback must be enqueued whenever custom element is removed from a document&quot;&gt;
+&lt;link rel=&quot;help&quot; href=&quot;https://w3c.github.io/webcomponents/spec/custom/#dfn-connected-callback&quot;&gt;
+&lt;script src=&quot;../../resources/testharness.js&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;../../resources/testharnessreport.js&quot;&gt;&lt;/script&gt;
+&lt;link rel='stylesheet' href='../../resources/testharness.css'&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div id=&quot;log&quot;&gt;&lt;/div&gt;
+&lt;script&gt;
+
+var calls = [];
+class MyCustomElement extends HTMLElement {
+    connectedCallback() { calls.push('connected', this); }
+    disconnectedCallback() { calls.push('disconnected', this); }
+}
+customElements.define('my-custom-element', MyCustomElement);
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    document.body.appendChild(instance);
+
+    calls = [];
+    document.body.removeChild(instance);
+    assert_array_equals(calls, ['disconnected', instance]);
+}, 'Removing a custom element from a document must enqueue and invoke disconnectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var parent = document.createElement('div');
+    parent.appendChild(instance);
+
+    calls = [];
+    parent.removeChild(instance);
+    assert_array_equals(calls, []);
+}, 'Removing a custom element from a detahed node must not enqueue and invoke connectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var documentWithoutWindow = document.implementation.createHTMLDocument();
+    documentWithoutWindow.body.appendChild(instance);
+
+    calls = [];
+    documentWithoutWindow.body.removeChild(instance);
+    assert_array_equals(calls, ['disconnected', instance]);
+}, 'Removing a custom element from a window-less document must enqueue and invoke disconnectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var parent = document.createElement('div');
+    parent.appendChild(instance);
+    document.body.appendChild(parent);
+
+    calls = [];
+    document.body.removeChild(parent);
+    assert_array_equals(calls, ['disconnected', instance]);
+}, 'Removing an ancestor of a custom element from a document must enqueue and invoke disconnectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var parent = document.createElement('div');
+    parent.appendChild(instance);
+    var documentWithoutWindow = document.implementation.createHTMLDocument();
+    documentWithoutWindow.body.appendChild(parent);
+
+    calls = [];
+    documentWithoutWindow.body.removeChild(parent);
+    assert_array_equals(calls, ['disconnected', instance]);
+}, 'Removing an ancestor of custom element from a a window-less document must enqueue and invoke disconnectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var host = document.createElement('div');
+    document.body.appendChild(host);
+    var shadowRoot = host.attachShadow({mode: 'closed'});
+    shadowRoot.appendChild(instance);
+
+    calls = [];
+    shadowRoot.removeChild(instance);
+    assert_array_equals(calls, ['disconnected', instance]);
+}, 'Removing a custom element from a connected shadow tree must enqueue and invoke disconnectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var host = document.createElement('div');
+    var shadowRoot = host.attachShadow({mode: 'closed'});
+    shadowRoot.appendChild(instance);
+    document.body.appendChild(host);
+
+    calls = [];
+    document.body.removeChild(host);
+    assert_array_equals(calls, ['disconnected', instance]);
+}, 'Removing the shadow host of a shadow tree with a custom element from a document must enqueue and invoke disconnectedCallback');
+
+test(function () {
+    var instance = document.createElement('my-custom-element');
+    var host = document.createElement('div');
+    var shadowRoot = host.attachShadow({mode: 'closed'});
+    shadowRoot.appendChild(instance);
+
+    calls = [];
+    shadowRoot.removeChild(instance);
+    assert_array_equals(calls, []);
+}, 'Removing a custom element from a detached shadow tree must not enqueue and invoke disconnectedCallback');
+
+
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/ChangeLog        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -1,3 +1,53 @@
</span><ins>+2016-08-17  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
+
+        Add basic support for connected and disconnected callbacks
+        https://bugs.webkit.org/show_bug.cgi?id=160950
+
+        Reviewed by Chris Dumez.
+
+        Added the basic support for custom elements' connectedCallback and disconnectedCallback. These callbacks
+        are enqueued by inserting and removing a node as spec'ed by https://dom.spec.whatwg.org/#concept-node-insert
+        and https://dom.spec.whatwg.org/#concept-node-remove
+
+        For now, we only support callbacks on appendChild and removeChild to limit the amount of code changes and
+        tests that need to be included in this patch.
+
+        This patch also renames InvokesCustomElementLifecycleCallbacks IDL attribute to CEReactions to match
+        the latest specification: https://html.spec.whatwg.org/multipage/scripting.html#cereactions
+
+        Tests: fast/custom-elements/connected-callbacks.html
+               fast/custom-elements/disconnected-callbacks.html
+
+        * bindings/js/JSCustomElementInterface.cpp:
+        (WebCore::JSCustomElementInterface::invokeCallback): Extracted from invokeAttributeChangedCallback.
+        (WebCore::JSCustomElementInterface::setConnectedCallback): Added.
+        (WebCore::JSCustomElementInterface::invokeConnectedCallback): Added.
+        (WebCore::JSCustomElementInterface::setDisconnectedCallback): Added.
+        (WebCore::JSCustomElementInterface::invokeDisconnectedCallback): Added.
+        (WebCore::JSCustomElementInterface::setAttributeChangedCallback):
+        (WebCore::JSCustomElementInterface::invokeAttributeChangedCallback): Renamed from attributeChanged.
+        * bindings/js/JSCustomElementInterface.h: Added m_connectedCallback and m_disconnectedCallback as instance
+        variables. Also removed the superfluous mutable qualifier from m_constructor m_attributeChangedCallback.
+        * bindings/js/JSCustomElementsRegistryCustom.cpp:
+        (WebCore::JSCustomElementsRegistry::define): Store connectedCallback and disconnectedCallback.
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+        * bindings/scripts/IDLAttributes.txt:
+        * dom/CustomElementsRegistry.idl:
+        * dom/Element.cpp:
+        (WebCore::Element::insertedInto): Call enqueueConnectedCallbackIfNeeded.
+        (WebCore::Element::removedFrom): Call enqueueDisconnectedCallbackIfNeeded.
+        * dom/Element.idl:
+        * dom/LifecycleCallbackQueue.cpp:
+        (WebCore::LifecycleQueueItem::invoke): Added calls to invokeConnectedCallback and invokeDisconnectedCallback.
+        (WebCore::findInterfaceForCustomElement): Extracted from enqueueAttributeChangedCallbackIfNeeded.
+        (WebCore::LifecycleCallbackQueue::enqueueConnectedCallbackIfNeeded): Added.
+        (WebCore::LifecycleCallbackQueue::enqueueDisconnectedCallbackIfNeeded): Added.
+        (WebCore::LifecycleCallbackQueue::enqueueAttributeChangedCallbackIfNeeded):
+        (WebCore::CustomElementLifecycleProcessingStack::ensureCurrentQueue):
+        * dom/LifecycleCallbackQueue.h:
+        * dom/Node.idl:
+
</ins><span class="cx"> 2016-08-18  Beth Dakin  &lt;bdakin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Update the accessibility titles for list insertion
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSCustomElementInterfacecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/bindings/js/JSCustomElementInterface.cpp        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -151,27 +151,19 @@
</span><span class="cx">     ASSERT(wrappedElement-&gt;isCustomElement());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void JSCustomElementInterface::setAttributeChangedCallback(JSC::JSObject* callback, const Vector&lt;String&gt;&amp; observedAttributes)
</del><ins>+void JSCustomElementInterface::invokeCallback(Element&amp; element, JSObject* callback, const Function&lt;void(ExecState*, MarkedArgumentBuffer&amp;)&gt;&amp; addArguments)
</ins><span class="cx"> {
</span><del>-    m_attributeChangedCallback = callback;
-    m_observedAttributes.clear();
-    for (auto&amp; name : observedAttributes)
-        m_observedAttributes.add(name);
-}
-
-void JSCustomElementInterface::attributeChanged(Element&amp; element, const QualifiedName&amp; attributeName, const AtomicString&amp; oldValue, const AtomicString&amp; newValue)
-{
</del><span class="cx">     if (!canInvokeCallback())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    auto* context = scriptExecutionContext();
+    if (!context)
+        return;
+
</ins><span class="cx">     Ref&lt;JSCustomElementInterface&gt; protectedThis(*this);
</span><del>-
</del><span class="cx">     JSLockHolder lock(m_isolatedWorld-&gt;vm());
</span><span class="cx"> 
</span><del>-    ScriptExecutionContext* context = scriptExecutionContext();
-    if (!context)
-        return;
-
</del><ins>+    ASSERT(context);
</ins><span class="cx">     ASSERT(context-&gt;isDocument());
</span><span class="cx">     JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(context, *m_isolatedWorld);
</span><span class="cx">     ExecState* state = globalObject-&gt;globalExec();
</span><span class="lines">@@ -179,20 +171,16 @@
</span><span class="cx">     JSObject* jsElement = asObject(toJS(state, globalObject, element));
</span><span class="cx"> 
</span><span class="cx">     CallData callData;
</span><del>-    CallType callType = m_attributeChangedCallback-&gt;methodTable()-&gt;getCallData(m_attributeChangedCallback.get(), callData);
</del><ins>+    CallType callType = callback-&gt;methodTable()-&gt;getCallData(callback, callData);
</ins><span class="cx">     ASSERT(callType != CallType::None);
</span><span class="cx"> 
</span><del>-    const AtomicString&amp; namespaceURI = attributeName.namespaceURI();
</del><span class="cx">     MarkedArgumentBuffer args;
</span><del>-    args.append(jsStringWithCache(state, attributeName.localName()));
-    args.append(oldValue == nullAtom ? jsNull() : jsStringWithCache(state, oldValue));
-    args.append(newValue == nullAtom ? jsNull() : jsStringWithCache(state, newValue));
-    args.append(namespaceURI == nullAtom ? jsNull() : jsStringWithCache(state, attributeName.namespaceURI()));
</del><ins>+    addArguments(state, args);
</ins><span class="cx"> 
</span><span class="cx">     InspectorInstrumentationCookie cookie = JSMainThreadExecState::instrumentFunctionCall(context, callType, callData);
</span><span class="cx"> 
</span><span class="cx">     NakedPtr&lt;Exception&gt; exception;
</span><del>-    JSMainThreadExecState::call(state, m_attributeChangedCallback.get(), callType, callData, jsElement, args, exception);
</del><ins>+    JSMainThreadExecState::call(state, callback, callType, callData, jsElement, args, exception);
</ins><span class="cx"> 
</span><span class="cx">     InspectorInstrumentation::didCallFunction(cookie, context);
</span><span class="cx"> 
</span><span class="lines">@@ -199,7 +187,45 @@
</span><span class="cx">     if (exception)
</span><span class="cx">         reportException(state, exception);
</span><span class="cx"> }
</span><del>-    
</del><ins>+
+void JSCustomElementInterface::setConnectedCallback(JSC::JSObject* callback)
+{
+    m_connectedCallback = callback;
+}
+
+void JSCustomElementInterface::invokeConnectedCallback(Element&amp; element)
+{
+    invokeCallback(element, m_connectedCallback.get());
+}
+
+void JSCustomElementInterface::setDisconnectedCallback(JSC::JSObject* callback)
+{
+    m_disconnectedCallback = callback;
+}
+
+void JSCustomElementInterface::invokeDisconnectedCallback(Element&amp; element)
+{
+    invokeCallback(element, m_disconnectedCallback.get());
+}
+
+void JSCustomElementInterface::setAttributeChangedCallback(JSC::JSObject* callback, const Vector&lt;String&gt;&amp; observedAttributes)
+{
+    m_attributeChangedCallback = callback;
+    m_observedAttributes.clear();
+    for (auto&amp; name : observedAttributes)
+        m_observedAttributes.add(name);
+}
+
+void JSCustomElementInterface::invokeAttributeChangedCallback(Element&amp; element, const QualifiedName&amp; attributeName, const AtomicString&amp; oldValue, const AtomicString&amp; newValue)
+{
+    invokeCallback(element, m_attributeChangedCallback.get(), [&amp;](ExecState* state, MarkedArgumentBuffer&amp; args) {
+        args.append(jsStringWithCache(state, attributeName.localName()));
+        args.append(jsStringOrNull(state, oldValue));
+        args.append(jsStringOrNull(state, newValue));
+        args.append(jsStringOrNull(state, attributeName.namespaceURI()));
+    });
+}
+
</ins><span class="cx"> void JSCustomElementInterface::didUpgradeLastElementInConstructionStack()
</span><span class="cx"> {
</span><span class="cx">     m_constructionStack.last() = nullptr;
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSCustomElementInterfaceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/bindings/js/JSCustomElementInterface.h        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include &lt;heap/WeakInlines.h&gt;
</span><span class="cx"> #include &lt;runtime/JSObject.h&gt;
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><ins>+#include &lt;wtf/Function.h&gt;
</ins><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/text/AtomicStringHash.h&gt;
</span><span class="lines">@@ -66,9 +67,15 @@
</span><span class="cx"> 
</span><span class="cx">     void upgradeElement(Element&amp;);
</span><span class="cx"> 
</span><ins>+    void setConnectedCallback(JSC::JSObject*);
+    void invokeConnectedCallback(Element&amp;);
+
+    void setDisconnectedCallback(JSC::JSObject*);
+    void invokeDisconnectedCallback(Element&amp;);
+
</ins><span class="cx">     void setAttributeChangedCallback(JSC::JSObject* callback, const Vector&lt;String&gt;&amp; observedAttributes);
</span><span class="cx">     bool observesAttribute(const AtomicString&amp; name) const { return m_observedAttributes.contains(name); }
</span><del>-    void attributeChanged(Element&amp;, const QualifiedName&amp;, const AtomicString&amp; oldValue, const AtomicString&amp; newValue);
</del><ins>+    void invokeAttributeChangedCallback(Element&amp;, const QualifiedName&amp;, const AtomicString&amp; oldValue, const AtomicString&amp; newValue);
</ins><span class="cx"> 
</span><span class="cx">     ScriptExecutionContext* scriptExecutionContext() const { return ContextDestructionObserver::scriptExecutionContext(); }
</span><span class="cx">     JSC::JSObject* constructor() { return m_constructor.get(); }
</span><span class="lines">@@ -84,9 +91,13 @@
</span><span class="cx"> private:
</span><span class="cx">     JSCustomElementInterface(const QualifiedName&amp;, JSC::JSObject* callback, JSDOMGlobalObject*);
</span><span class="cx"> 
</span><ins>+    void invokeCallback(Element&amp;, JSC::JSObject* callback, const Function&lt;void(JSC::ExecState*, JSC::MarkedArgumentBuffer&amp;)&gt;&amp; addArguments = {});
+
</ins><span class="cx">     QualifiedName m_name;
</span><del>-    mutable JSC::Weak&lt;JSC::JSObject&gt; m_constructor;
-    mutable JSC::Weak&lt;JSC::JSObject&gt; m_attributeChangedCallback;
</del><ins>+    JSC::Weak&lt;JSC::JSObject&gt; m_constructor;
+    JSC::Weak&lt;JSC::JSObject&gt; m_connectedCallback;
+    JSC::Weak&lt;JSC::JSObject&gt; m_disconnectedCallback;
+    JSC::Weak&lt;JSC::JSObject&gt; m_attributeChangedCallback;
</ins><span class="cx">     RefPtr&lt;DOMWrapperWorld&gt; m_isolatedWorld;
</span><span class="cx">     Vector&lt;RefPtr&lt;Element&gt;, 1&gt; m_constructionStack;
</span><span class="cx">     HashSet&lt;AtomicString&gt; m_observedAttributes;
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSCustomElementsRegistryCustomcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -104,15 +104,20 @@
</span><span class="cx">         return throwTypeError(&amp;state, ASCIILiteral(&quot;Custom element constructor's prototype must be an object&quot;));
</span><span class="cx">     JSObject&amp; prototypeObject = *asObject(prototypeValue);
</span><span class="cx"> 
</span><del>-    // FIXME: Add the support for connectedCallback.
-    getLifecycleCallback(state, prototypeObject, Identifier::fromString(&amp;vm, &quot;connectedCallback&quot;));
</del><ins>+    QualifiedName name(nullAtom, localName, HTMLNames::xhtmlNamespaceURI);
+    auto elementInterface = JSCustomElementInterface::create(name, constructor, globalObject());
+
+    auto* connectedCallback = getLifecycleCallback(state, prototypeObject, Identifier::fromString(&amp;vm, &quot;connectedCallback&quot;));
</ins><span class="cx">     if (state.hadException())
</span><span class="cx">         return jsUndefined();
</span><ins>+    if (connectedCallback)
+        elementInterface-&gt;setConnectedCallback(connectedCallback);
</ins><span class="cx"> 
</span><del>-    // FIXME: Add the support for disconnectedCallback.
-    getLifecycleCallback(state, prototypeObject, Identifier::fromString(&amp;vm, &quot;disconnectedCallback&quot;));
</del><ins>+    auto* disconnectedCallback = getLifecycleCallback(state, prototypeObject, Identifier::fromString(&amp;vm, &quot;disconnectedCallback&quot;));
</ins><span class="cx">     if (state.hadException())
</span><span class="cx">         return jsUndefined();
</span><ins>+    if (disconnectedCallback)
+        elementInterface-&gt;setDisconnectedCallback(disconnectedCallback);
</ins><span class="cx"> 
</span><span class="cx">     // FIXME: Add the support for adoptedCallback.
</span><span class="cx">     getLifecycleCallback(state, prototypeObject, Identifier::fromString(&amp;vm, &quot;adoptedCallback&quot;));
</span><span class="lines">@@ -119,9 +124,6 @@
</span><span class="cx">     if (state.hadException())
</span><span class="cx">         return jsUndefined();
</span><span class="cx"> 
</span><del>-    QualifiedName name(nullAtom, localName, HTMLNames::xhtmlNamespaceURI);
-    auto elementInterface = JSCustomElementInterface::create(name, constructor, globalObject());
-
</del><span class="cx">     auto* attributeChangedCallback = getLifecycleCallback(state, prototypeObject, Identifier::fromString(&amp;vm, &quot;attributeChangedCallback&quot;));
</span><span class="cx">     if (state.hadException())
</span><span class="cx">         return jsUndefined();
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -3340,7 +3340,7 @@
</span><span class="cx"> 
</span><span class="cx">             $implIncludes{&quot;&lt;runtime/Error.h&gt;&quot;} = 1;
</span><span class="cx"> 
</span><del>-            if ($function-&gt;signature-&gt;extendedAttributes-&gt;{&quot;InvokesCustomElementLifecycleCallbacks&quot;}) {
</del><ins>+            if ($function-&gt;signature-&gt;extendedAttributes-&gt;{&quot;CEReactions&quot;}) {
</ins><span class="cx">                 push(@implContent, &quot;#if ENABLE(CUSTOM_ELEMENTS)\n&quot;);
</span><span class="cx">                 push(@implContent, &quot;    CustomElementLifecycleProcessingStack customElementLifecycleProcessingStack;\n&quot;);
</span><span class="cx">                 push(@implContent, &quot;#endif\n&quot;);
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptsIDLAttributestxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -21,6 +21,7 @@
</span><span class="cx"> ActiveDOMObject
</span><span class="cx"> AppleCopyright
</span><span class="cx"> AtomicString
</span><ins>+CEReactions
</ins><span class="cx"> CachedAttribute
</span><span class="cx"> CallbackNeedsOperatorEqual
</span><span class="cx"> Callback=FunctionOnly
</span><span class="lines">@@ -91,7 +92,6 @@
</span><span class="cx"> LenientThis
</span><span class="cx"> MasqueradesAsUndefined
</span><span class="cx"> NamedConstructor=*
</span><del>-InvokesCustomElementLifecycleCallbacks
</del><span class="cx"> NewImpurePropertyFiresWatchpoints
</span><span class="cx"> NewObject
</span><span class="cx"> NoInterfaceObject
</span></span></pre></div>
<a id="trunkSourceWebCoredomCustomElementsRegistryidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/CustomElementsRegistry.idl (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/CustomElementsRegistry.idl        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/dom/CustomElementsRegistry.idl        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -29,6 +29,6 @@
</span><span class="cx">     ImplementationLacksVTable
</span><span class="cx"> ] interface CustomElementsRegistry {
</span><span class="cx"> 
</span><del>-    [InvokesCustomElementLifecycleCallbacks, Custom] void define(DOMString name, Function constructor);
</del><ins>+    [CEReactions, Custom] void define(DOMString name, Function constructor);
</ins><span class="cx"> 
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.cpp (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.cpp        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/dom/Element.cpp        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -1596,6 +1596,11 @@
</span><span class="cx">             updateLabel(*newScope, nullAtom, attributeWithoutSynchronization(forAttr));
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+#if ENABLE(CUSTOM_ELEMENTS)
+    if (newDocument &amp;&amp; UNLIKELY(isCustomElement()))
+        LifecycleCallbackQueue::enqueueConnectedCallbackIfNeeded(*this);
+#endif
+
</ins><span class="cx">     return InsertionDone;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1641,6 +1646,11 @@
</span><span class="cx">             if (oldScope-&gt;shouldCacheLabelsByForAttribute())
</span><span class="cx">                 updateLabel(*oldScope, attributeWithoutSynchronization(forAttr), nullAtom);
</span><span class="cx">         }
</span><ins>+
+#if ENABLE(CUSTOM_ELEMENTS)
+        if (oldDocument &amp;&amp; UNLIKELY(isCustomElement()))
+            LifecycleCallbackQueue::enqueueDisconnectedCallbackIfNeeded(*this);
+#endif
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (!parentNode()) {
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.idl (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.idl        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/dom/Element.idl        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -31,15 +31,13 @@
</span><span class="cx"> 
</span><span class="cx">     DOMString? getAttribute(DOMString name);
</span><span class="cx"> 
</span><del>-    [ObjCLegacyUnnamedParameters, RaisesException, InvokesCustomElementLifecycleCallbacks]
</del><ins>+    [ObjCLegacyUnnamedParameters, RaisesException, CEReactions] void setAttribute(DOMString name, DOMString value);
</ins><span class="cx"> 
</span><del>-    void setAttribute(DOMString name, DOMString value);
-
-    [InvokesCustomElementLifecycleCallbacks] void removeAttribute(DOMString name);
</del><ins>+    [CEReactions] void removeAttribute(DOMString name);
</ins><span class="cx">     Attr? getAttributeNode(DOMString name);
</span><span class="cx"> 
</span><del>-    [RaisesException, InvokesCustomElementLifecycleCallbacks] Attr? setAttributeNode(Attr newAttr);
-    [RaisesException, InvokesCustomElementLifecycleCallbacks] Attr removeAttributeNode(Attr oldAttr);
</del><ins>+    [RaisesException, CEReactions] Attr? setAttributeNode(Attr newAttr);
+    [RaisesException, CEReactions] Attr removeAttributeNode(Attr oldAttr);
</ins><span class="cx"> 
</span><span class="cx">     HTMLCollection getElementsByTagName(DOMString name);
</span><span class="cx"> 
</span><span class="lines">@@ -50,16 +48,14 @@
</span><span class="cx"> 
</span><span class="cx">     [ObjCLegacyUnnamedParameters] DOMString? getAttributeNS(DOMString? namespaceURI, DOMString localName);
</span><span class="cx"> 
</span><del>-    [ObjCLegacyUnnamedParameters, RaisesException, InvokesCustomElementLifecycleCallbacks]
</del><ins>+    [ObjCLegacyUnnamedParameters, RaisesException, CEReactions] void setAttributeNS(DOMString? namespaceURI, DOMString qualifiedName, DOMString value);
</ins><span class="cx"> 
</span><del>-    void setAttributeNS(DOMString? namespaceURI, DOMString qualifiedName, DOMString value);
</del><ins>+    [ObjCLegacyUnnamedParameters, CEReactions] void removeAttributeNS(DOMString? namespaceURI, DOMString localName);
</ins><span class="cx"> 
</span><del>-    [ObjCLegacyUnnamedParameters, InvokesCustomElementLifecycleCallbacks] void removeAttributeNS(DOMString? namespaceURI, DOMString localName);
-
</del><span class="cx">     HTMLCollection getElementsByTagNameNS(DOMString? namespaceURI, DOMString localName);
</span><span class="cx"> 
</span><span class="cx">     [ObjCLegacyUnnamedParameters] Attr? getAttributeNodeNS(DOMString? namespaceURI, DOMString localName);
</span><del>-    [RaisesException, InvokesCustomElementLifecycleCallbacks] Attr? setAttributeNodeNS(Attr newAttr);
</del><ins>+    [RaisesException, CEReactions] Attr? setAttributeNodeNS(Attr newAttr);
</ins><span class="cx">     boolean hasAttribute(DOMString name);
</span><span class="cx"> 
</span><span class="cx">     [ObjCLegacyUnnamedParameters] boolean hasAttributeNS(DOMString? namespaceURI, DOMString localName);
</span></span></pre></div>
<a id="trunkSourceWebCoredomLifecycleCallbackQueuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/LifecycleCallbackQueue.cpp (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/LifecycleCallbackQueue.cpp        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/dom/LifecycleCallbackQueue.cpp        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -44,6 +44,8 @@
</span><span class="cx"> public:
</span><span class="cx">     enum class Type {
</span><span class="cx">         ElementUpgrade,
</span><ins>+        Connected,
+        Disconnected,
</ins><span class="cx">         AttributeChanged,
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="lines">@@ -68,9 +70,15 @@
</span><span class="cx">         case Type::ElementUpgrade:
</span><span class="cx">             m_interface-&gt;upgradeElement(m_element.get());
</span><span class="cx">             break;
</span><ins>+        case Type::Connected:
+            m_interface-&gt;invokeConnectedCallback(m_element.get());
+            break;
+        case Type::Disconnected:
+            m_interface-&gt;invokeDisconnectedCallback(m_element.get());
+            break;
</ins><span class="cx">         case Type::AttributeChanged:
</span><span class="cx">             ASSERT(m_attributeName);
</span><del>-            m_interface-&gt;attributeChanged(m_element.get(), m_attributeName.value(), m_oldValue, m_newValue);
</del><ins>+            m_interface-&gt;invokeAttributeChangedCallback(m_element.get(), m_attributeName.value(), m_oldValue, m_newValue);
</ins><span class="cx">             break;
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="lines">@@ -98,25 +106,50 @@
</span><span class="cx">         queue-&gt;m_items.append(LifecycleQueueItem(LifecycleQueueItem::Type::ElementUpgrade, element, elementInterface));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LifecycleCallbackQueue::enqueueAttributeChangedCallbackIfNeeded(Element&amp; element, const QualifiedName&amp; attributeName, const AtomicString&amp; oldValue, const AtomicString&amp; newValue)
</del><ins>+static JSCustomElementInterface* findInterfaceForCustomElement(Element&amp; element)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(element.isCustomElement());
</span><span class="cx">     auto* window = element.document().domWindow();
</span><span class="cx">     if (!window)
</span><del>-        return;
</del><ins>+        return nullptr;
</ins><span class="cx"> 
</span><span class="cx">     auto* registry = window-&gt;customElementsRegistry();
</span><span class="cx">     if (!registry)
</span><ins>+        return nullptr;
+
+    return registry-&gt;findInterface(element.tagQName());
+}
+
+void LifecycleCallbackQueue::enqueueConnectedCallbackIfNeeded(Element&amp; element)
+{
+    auto* elementInterface = findInterfaceForCustomElement(element);
+    if (!elementInterface)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    auto* elementInterface = registry-&gt;findInterface(element.tagQName());
-    if (!elementInterface-&gt;observesAttribute(attributeName.localName()))
</del><ins>+    if (auto* queue = CustomElementLifecycleProcessingStack::ensureCurrentQueue())
+        queue-&gt;m_items.append({LifecycleQueueItem::Type::Connected, element, *elementInterface});
+}
+
+void LifecycleCallbackQueue::enqueueDisconnectedCallbackIfNeeded(Element&amp; element)
+{
+    auto* elementInterface = findInterfaceForCustomElement(element);
+    if (!elementInterface)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (auto* queue = CustomElementLifecycleProcessingStack::ensureCurrentQueue())
</span><del>-        queue-&gt;m_items.append(LifecycleQueueItem(element, *elementInterface, attributeName, oldValue, newValue));
</del><ins>+        queue-&gt;m_items.append({LifecycleQueueItem::Type::Disconnected, element, *elementInterface});
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void LifecycleCallbackQueue::enqueueAttributeChangedCallbackIfNeeded(Element&amp; element, const QualifiedName&amp; attributeName, const AtomicString&amp; oldValue, const AtomicString&amp; newValue)
+{
+    auto* elementInterface = findInterfaceForCustomElement(element);
+    if (!elementInterface || !elementInterface-&gt;observesAttribute(attributeName.localName()))
+        return;
+
+    if (auto* queue = CustomElementLifecycleProcessingStack::ensureCurrentQueue())
+        queue-&gt;m_items.append({element, *elementInterface, attributeName, oldValue, newValue});
+}
+
</ins><span class="cx"> void LifecycleCallbackQueue::invokeAll()
</span><span class="cx"> {
</span><span class="cx">     Vector&lt;LifecycleQueueItem&gt; items;
</span><span class="lines">@@ -127,7 +160,7 @@
</span><span class="cx"> 
</span><span class="cx"> LifecycleCallbackQueue* CustomElementLifecycleProcessingStack::ensureCurrentQueue()
</span><span class="cx"> {
</span><del>-    // FIXME: This early exit indicates a bug that some DOM API is missing InvokesCustomElementLifecycleCallbacks
</del><ins>+    // FIXME: This early exit indicates a bug that some DOM API is missing CEReactions
</ins><span class="cx">     if (!s_currentProcessingStack)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomLifecycleCallbackQueueh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/LifecycleCallbackQueue.h (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/LifecycleCallbackQueue.h        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/dom/LifecycleCallbackQueue.h        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -46,6 +46,8 @@
</span><span class="cx">     ~LifecycleCallbackQueue();
</span><span class="cx"> 
</span><span class="cx">     static void enqueueElementUpgrade(Element&amp;, JSCustomElementInterface&amp;);
</span><ins>+    static void enqueueConnectedCallbackIfNeeded(Element&amp;);
+    static void enqueueDisconnectedCallbackIfNeeded(Element&amp;);
</ins><span class="cx">     static void enqueueAttributeChangedCallbackIfNeeded(Element&amp;, const QualifiedName&amp;, const AtomicString&amp; oldValue, const AtomicString&amp; newValue);
</span><span class="cx"> 
</span><span class="cx">     void invokeAll();
</span></span></pre></div>
<a id="trunkSourceWebCoredomNodeidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Node.idl (204610 => 204611)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Node.idl        2016-08-18 21:19:26 UTC (rev 204610)
+++ trunk/Source/WebCore/dom/Node.idl        2016-08-18 22:19:59 UTC (rev 204611)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2006-2016 Apple Inc. All rights reserved.
</ins><span class="cx">  * Copyright (C) 2006 Samuel Weinig &lt;sam.weinig@gmail.com&gt;
</span><span class="cx">  *
</span><span class="cx">  * This library is free software; you can redistribute it and/or
</span><span class="lines">@@ -57,13 +57,12 @@
</span><span class="cx"> 
</span><span class="cx">     [ObjCLegacyUnnamedParameters, Custom, RaisesException] Node insertBefore([CustomReturn] Node newChild, Node? refChild);
</span><span class="cx">     [ObjCLegacyUnnamedParameters, Custom, RaisesException] Node replaceChild(Node newChild, [CustomReturn] Node oldChild);
</span><del>-    [Custom, RaisesException] Node removeChild([CustomReturn] Node oldChild);
-    [Custom, RaisesException] Node appendChild([CustomReturn] Node newChild);
</del><ins>+    [Custom, RaisesException, CEReactions] Node removeChild([CustomReturn] Node oldChild);
+    [Custom, RaisesException, CEReactions] Node appendChild([CustomReturn] Node newChild);
</ins><span class="cx"> 
</span><span class="cx">     boolean            hasChildNodes();
</span><span class="cx"> 
</span><del>-    [NewObject, RaisesException, ImplementedAs=cloneNodeForBindings, InvokesCustomElementLifecycleCallbacks]
-    Node cloneNode(optional boolean deep = false);
</del><ins>+    [NewObject, RaisesException, ImplementedAs=cloneNodeForBindings, CEReactions] Node cloneNode(optional boolean deep = false);
</ins><span class="cx"> 
</span><span class="cx">     void               normalize();
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>