Add upgrade reaction

This commit is contained in:
Connor Brewster 2017-07-19 13:10:54 -06:00
parent ec528e944a
commit e83a0045f9
3 changed files with 28 additions and 3 deletions

View file

@ -531,7 +531,10 @@ pub fn try_upgrade_element(element: &Element) {
#[derive(HeapSizeOf, JSTraceable)]
#[must_root]
pub enum CustomElementReaction {
// TODO: Support upgrade reactions
Upgrade(
#[ignore_heap_size_of = "Rc"]
Rc<CustomElementDefinition>
),
Callback(
#[ignore_heap_size_of = "Rc"]
Rc<Function>,
@ -545,6 +548,7 @@ impl CustomElementReaction {
pub fn invoke(&self, element: &Element) {
// Step 2.1
match *self {
CustomElementReaction::Upgrade(ref definition) => upgrade_element(definition.clone(), element),
CustomElementReaction::Callback(ref callback, ref arguments) => {
let arguments = arguments.iter().map(|arg| arg.handle()).collect();
let _ = callback.Call_(&*element, arguments, ExceptionHandling::Report);
@ -703,6 +707,14 @@ impl CustomElementReactionStack {
// Step 6
self.enqueue_element(element);
}
/// https://html.spec.whatwg.org/multipage/#enqueue-a-custom-element-upgrade-reaction
pub fn enqueue_upgrade_reaction(&self, element: &Element, definition: Rc<CustomElementDefinition>) {
// Step 1
element.push_upgrade_reaction(definition);
// Step 2
self.enqueue_element(element);
}
}
/// https://html.spec.whatwg.org/multipage/#element-queue

View file

@ -300,6 +300,10 @@ impl Element {
self.custom_element_reaction_queue.borrow_mut().push(CustomElementReaction::Callback(function, args));
}
pub fn push_upgrade_reaction(&self, definition: Rc<CustomElementDefinition>) {
self.custom_element_reaction_queue.borrow_mut().push(CustomElementReaction::Upgrade(definition));
}
pub fn invoke_reactions(&self) {
let mut reaction_queue = self.custom_element_reaction_queue.borrow_mut();
for reaction in reaction_queue.iter() {

View file

@ -39,7 +39,7 @@ use dom::bindings::str::DOMString;
use dom::bindings::structuredclone::StructuredCloneData;
use dom::bindings::trace::JSTraceable;
use dom::bindings::utils::WRAP_CALLBACKS;
use dom::customelementregistry::{CallbackReaction, CustomElementReactionStack};
use dom::customelementregistry::{CallbackReaction, CustomElementDefinition, CustomElementReactionStack};
use dom::document::{Document, DocumentSource, FocusType, HasBrowsingContext, IsHTMLDocument, TouchEventResult};
use dom::element::Element;
use dom::event::{Event, EventBubbles, EventCancelable};
@ -783,6 +783,15 @@ impl ScriptThread {
})
}
pub fn enqueue_upgrade_reaction(element: &Element, definition: Rc<CustomElementDefinition>) {
SCRIPT_THREAD_ROOT.with(|root| {
if let Some(script_thread) = root.get() {
let script_thread = unsafe { &*script_thread };
script_thread.custom_element_reaction_stack.enqueue_upgrade_reaction(element, definition);
}
})
}
pub fn invoke_backup_element_queue() {
SCRIPT_THREAD_ROOT.with(|root| {
if let Some(script_thread) = root.get() {