diff --git a/components/script/dom/customelementregistry.rs b/components/script/dom/customelementregistry.rs index a85c44883f390..8b8629a05b061 100644 --- a/components/script/dom/customelementregistry.rs +++ b/components/script/dom/customelementregistry.rs @@ -29,6 +29,8 @@ use js::conversions::ToJSValConvertible; use js::jsapi::{Construct1, IsCallable, IsConstructor, HandleValueArray, HandleObject, MutableHandleValue}; use js::jsapi::{Heap, JS_GetProperty, JSAutoCompartment, JSContext}; use js::jsval::{JSVal, NullValue, ObjectValue, UndefinedValue}; +use microtask::Microtask; +use script_thread::ScriptThread; use std::cell::Cell; use std::collections::HashMap; use std::ptr; @@ -521,6 +523,16 @@ impl CustomElementReactionStack { } } + /// https://html.spec.whatwg.org/multipage/#enqueue-an-element-on-the-appropriate-element-queue + /// Step 4 + pub fn invoke_backup_element_queue(&self) { + // Step 4.1 + self.backup_queue.invoke_reactions(); + + // Step 4.2 + self.processing_backup_element_queue.set(BackupElementQueueFlag::NotProcessing); + } + /// https://html.spec.whatwg.org/multipage/#enqueue-an-element-on-the-appropriate-element-queue pub fn enqueue_element(&self, element: Root) { // TODO: Steps 1 - 2 @@ -538,13 +550,7 @@ impl CustomElementReactionStack { self.processing_backup_element_queue.set(BackupElementQueueFlag::Processing); // Step 4 - // TODO: Invoke Microtask - - // Step 4.1 - self.backup_queue.invoke_reactions(); - - // Step 4.2 - self.processing_backup_element_queue.set(BackupElementQueueFlag::NotProcessing); + ScriptThread::enqueue_microtask(Microtask::CustomElementReaction); } /// https://html.spec.whatwg.org/multipage/#enqueue-a-custom-element-callback-reaction @@ -639,6 +645,7 @@ impl ElementQueue { for element in self.queue.borrow().iter() { element.invoke_reactions() } + self.queue.borrow_mut().clear(); } fn append_element(&self, element: Root) { diff --git a/components/script/microtask.rs b/components/script/microtask.rs index 5028f2849dade..a25b7ff3719e0 100644 --- a/components/script/microtask.rs +++ b/components/script/microtask.rs @@ -15,6 +15,7 @@ use dom::htmlimageelement::ImageElementMicrotask; use dom::htmlmediaelement::MediaElementMicrotask; use dom::mutationobserver::MutationObserver; use msg::constellation_msg::PipelineId; +use script_thread::ScriptThread; use std::cell::Cell; use std::mem; use std::rc::Rc; @@ -33,6 +34,7 @@ pub enum Microtask { Promise(EnqueuedPromiseCallback), MediaElement(MediaElementMicrotask), ImageElement(ImageElementMicrotask), + CustomElementReaction, NotifyMutationObservers, } @@ -87,6 +89,9 @@ impl MicrotaskQueue { Microtask::ImageElement(ref task) => { task.handler(); }, + Microtask::CustomElementReaction => { + ScriptThread::invoke_backup_element_queue(); + }, Microtask::NotifyMutationObservers => { MutationObserver::notify_mutation_observers(); } diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 291acb743dba6..b4a0f746740f0 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -747,6 +747,15 @@ impl ScriptThread { }) } + pub fn invoke_backup_element_queue() { + SCRIPT_THREAD_ROOT.with(|root| { + if let Some(script_thread) = root.get() { + let script_thread = unsafe { &*script_thread }; + script_thread.custom_element_reaction_stack.invoke_backup_element_queue(); + } + }) + } + /// Creates a new script thread. pub fn new(state: InitialScriptState, port: Receiver, diff --git a/tests/wpt/metadata/custom-elements/adopted-callback.html.ini b/tests/wpt/metadata/custom-elements/adopted-callback.html.ini index c823a05e4eca4..7d4f4439a5b60 100644 --- a/tests/wpt/metadata/custom-elements/adopted-callback.html.ini +++ b/tests/wpt/metadata/custom-elements/adopted-callback.html.ini @@ -129,3 +129,48 @@ [Custom Elements: adoptedCallback] expected: FAIL + [Inserting a custom element into the owner document must not enqueue and invoke adoptedCallback] + expected: FAIL + + [Inserting a custom element into the document of the template elements must enqueue and invoke adoptedCallback] + expected: FAIL + + [Moving a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback] + expected: FAIL + + [Inserting a custom element into a new document must enqueue and invoke adoptedCallback] + expected: FAIL + + [Moving a custom element from the owner document into a new document must enqueue and invoke adoptedCallback] + expected: FAIL + + [Inserting a custom element into a cloned document must enqueue and invoke adoptedCallback] + expected: FAIL + + [Moving a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback] + expected: FAIL + + [Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback] + expected: FAIL + + [Moving a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback] + expected: FAIL + + [Inserting a custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback] + expected: FAIL + + [Moving a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback] + expected: FAIL + + [Inserting a custom element into the document of an iframe must enqueue and invoke adoptedCallback] + expected: FAIL + + [Moving a custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback] + expected: FAIL + + [Inserting a custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback] + expected: FAIL + + [Moving a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/connected-callbacks.html.ini b/tests/wpt/metadata/custom-elements/connected-callbacks.html.ini index 656964b574ce2..457ec15b357e1 100644 --- a/tests/wpt/metadata/custom-elements/connected-callbacks.html.ini +++ b/tests/wpt/metadata/custom-elements/connected-callbacks.html.ini @@ -99,3 +99,27 @@ [Custom Elements: connectedCallback] expected: FAIL + [Inserting a custom element into the document must enqueue and invoke connectedCallback] + expected: FAIL + + [Inserting a custom element into the document of the template elements must enqueue and invoke connectedCallback] + expected: FAIL + + [Inserting a custom element into a new document must enqueue and invoke connectedCallback] + expected: FAIL + + [Inserting a custom element into a cloned document must enqueue and invoke connectedCallback] + expected: FAIL + + [Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback] + expected: FAIL + + [Inserting a custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback] + expected: FAIL + + [Inserting a custom element into the document of an iframe must enqueue and invoke connectedCallback] + expected: FAIL + + [Inserting a custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/disconnected-callbacks.html.ini b/tests/wpt/metadata/custom-elements/disconnected-callbacks.html.ini index 55ac810a899a6..caa481be6822d 100644 --- a/tests/wpt/metadata/custom-elements/disconnected-callbacks.html.ini +++ b/tests/wpt/metadata/custom-elements/disconnected-callbacks.html.ini @@ -75,3 +75,51 @@ [Custom Elements: disconnectedCallback] expected: FAIL + [Removing a custom element from the document must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing an ancestor of custom element from the document must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing a custom element from the document of the template elements must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing an ancestor of custom element from the document of the template elements must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing a custom element from a new document must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing an ancestor of custom element from a new document must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing a custom element from a cloned document must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing an ancestor of custom element from a cloned document must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing a custom element from a document created by createHTMLDocument must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing an ancestor of custom element from a document created by createHTMLDocument must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing a custom element from an HTML document created by createDocument must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing an ancestor of custom element from an HTML document created by createDocument must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing a custom element from the document of an iframe must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing an ancestor of custom element from the document of an iframe must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing a custom element from an HTML document fetched by XHR must enqueue and invoke disconnectedCallback] + expected: FAIL + + [Removing an ancestor of custom element from an HTML document fetched by XHR must enqueue and invoke disconnectedCallback] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/reactions/ChildNode.html.ini b/tests/wpt/metadata/custom-elements/reactions/ChildNode.html.ini new file mode 100644 index 0000000000000..4265435e3b656 --- /dev/null +++ b/tests/wpt/metadata/custom-elements/reactions/ChildNode.html.ini @@ -0,0 +1,23 @@ +[ChildNode.html] + type: testharness + [before on ChildNode must enqueue a connected reaction] + expected: FAIL + + [before on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + + [after on ChildNode must enqueue a connected reaction] + expected: FAIL + + [after on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + + [replaceWith on ChildNode must enqueue a connected reaction] + expected: FAIL + + [replaceWith on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + + [replaceWith on ChildNode must enqueue a disconnected reaction] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/reactions/Document.html.ini b/tests/wpt/metadata/custom-elements/reactions/Document.html.ini index 10b246742007d..bf986fdbca0e3 100644 --- a/tests/wpt/metadata/custom-elements/reactions/Document.html.ini +++ b/tests/wpt/metadata/custom-elements/reactions/Document.html.ini @@ -21,3 +21,15 @@ [importNode on Document must construct a new custom element when importing a custom element from a template] expected: FAIL + [adoptNode on Document must enqueue an adopted reaction when importing a custom element] + expected: FAIL + + [title on Document must enqueue disconnectedCallback when removing a custom element] + expected: FAIL + + [write on Document must enqueue connectedCallback after constructing a custom element] + expected: FAIL + + [writeln on Document must enqueue connectedCallback after constructing a custom element] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/reactions/Element.html.ini b/tests/wpt/metadata/custom-elements/reactions/Element.html.ini index bf8e65290906c..d6e6402eece07 100644 --- a/tests/wpt/metadata/custom-elements/reactions/Element.html.ini +++ b/tests/wpt/metadata/custom-elements/reactions/Element.html.ini @@ -69,3 +69,15 @@ [insertAdjacentHTML on Element must enqueue a attributeChanged reaction for a newly constructed custom element] expected: FAIL + [insertAdjacentElement on Element must enqueue a connected reaction] + expected: FAIL + + [insertAdjacentElement on Element must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + + [innerHTML on Element must enqueue a disconnected reaction] + expected: FAIL + + [outerHTML on Element must enqueue a disconnected reaction] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/reactions/HTMLOptionsCollection.html.ini b/tests/wpt/metadata/custom-elements/reactions/HTMLOptionsCollection.html.ini index 88525dabcb326..1a1f74719e6ef 100644 --- a/tests/wpt/metadata/custom-elements/reactions/HTMLOptionsCollection.html.ini +++ b/tests/wpt/metadata/custom-elements/reactions/HTMLOptionsCollection.html.ini @@ -6,3 +6,12 @@ [add on HTMLOptionsCollection must enqueue connectedCallback when inserting a custom element] expected: FAIL + [length on HTMLOptionsCollection must enqueue disconnectedCallback when removing a custom element] + expected: FAIL + + [The indexed setter on HTMLOptionsCollection must enqueue disconnectedCallback when removing a custom element] + expected: FAIL + + [remove on HTMLOptionsCollection must enqueue disconnectedCallback when removing a custom element] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/reactions/HTMLSelectElement.html.ini b/tests/wpt/metadata/custom-elements/reactions/HTMLSelectElement.html.ini index a7965cea05f14..517deb058070a 100644 --- a/tests/wpt/metadata/custom-elements/reactions/HTMLSelectElement.html.ini +++ b/tests/wpt/metadata/custom-elements/reactions/HTMLSelectElement.html.ini @@ -9,3 +9,9 @@ [add on HTMLSelectElement must enqueue connectedCallback when inserting a custom element] expected: FAIL + [length on HTMLSelectElement must enqueue disconnectedCallback when removing a custom element] + expected: FAIL + + [remove on HTMLSelectElement must enqueue disconnectedCallback when removing a custom element] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/reactions/HTMLTitleElement.html.ini b/tests/wpt/metadata/custom-elements/reactions/HTMLTitleElement.html.ini new file mode 100644 index 0000000000000..07e9cb95fc189 --- /dev/null +++ b/tests/wpt/metadata/custom-elements/reactions/HTMLTitleElement.html.ini @@ -0,0 +1,5 @@ +[HTMLTitleElement.html] + type: testharness + [text on HTMLTitleElement must enqueue disconnectedCallback when removing a custom element] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/reactions/Node.html.ini b/tests/wpt/metadata/custom-elements/reactions/Node.html.ini index 19256a1f7b71d..a5be84ba6350c 100644 --- a/tests/wpt/metadata/custom-elements/reactions/Node.html.ini +++ b/tests/wpt/metadata/custom-elements/reactions/Node.html.ini @@ -15,3 +15,24 @@ [cloneNode on Node must enqueue an attributeChanged reaction when cloning an element only for observed attributes] expected: FAIL + [insertBefore on ChildNode must enqueue a connected reaction] + expected: FAIL + + [insertBefore on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + + [appendChild on ChildNode must enqueue a connected reaction] + expected: FAIL + + [appendChild on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + + [replaceChild on ChildNode must enqueue a connected reaction] + expected: FAIL + + [replaceChild on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + + [removeChild on ChildNode must enqueue a disconnected reaction] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/reactions/ParentNode.html.ini b/tests/wpt/metadata/custom-elements/reactions/ParentNode.html.ini new file mode 100644 index 0000000000000..ccdf5de7cf032 --- /dev/null +++ b/tests/wpt/metadata/custom-elements/reactions/ParentNode.html.ini @@ -0,0 +1,14 @@ +[ParentNode.html] + type: testharness + [prepend on ParentNode must enqueue a connected reaction] + expected: FAIL + + [prepend on ParentNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + + [append on ParentNode must enqueue a connected reaction] + expected: FAIL + + [append on ParentNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + diff --git a/tests/wpt/metadata/custom-elements/reactions/Range.html.ini b/tests/wpt/metadata/custom-elements/reactions/Range.html.ini index 662e10a7c4362..64c174992a5a6 100644 --- a/tests/wpt/metadata/custom-elements/reactions/Range.html.ini +++ b/tests/wpt/metadata/custom-elements/reactions/Range.html.ini @@ -15,3 +15,18 @@ [createContextualFragment on Range must construct a custom element] expected: FAIL + [deleteContents on Range must enqueue a disconnected reaction] + expected: FAIL + + [insertNode on Range must enqueue a connected reaction] + expected: FAIL + + [insertNode on Range must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL + + [surroundContents on Range must enqueue a connected reaction] + expected: FAIL + + [surroundContents on Range must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] + expected: FAIL +