Update type of custom element constructor

This commit is contained in:
tigercosmos 2018-05-29 16:39:24 -07:00
parent 7cc4165dda
commit 6d426f7c14
2 changed files with 12 additions and 5 deletions

View file

@ -5,6 +5,7 @@
use dom::bindings::callback::{CallbackContainer, ExceptionHandling};
use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::CustomElementRegistryBinding;
use dom::bindings::codegen::Bindings::CustomElementRegistryBinding::CustomElementConstructor;
use dom::bindings::codegen::Bindings::CustomElementRegistryBinding::CustomElementRegistryMethods;
use dom::bindings::codegen::Bindings::CustomElementRegistryBinding::ElementDefinitionOptions;
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
@ -193,7 +194,11 @@ unsafe fn get_callback(
impl CustomElementRegistryMethods for CustomElementRegistry {
#[allow(unsafe_code, unrooted_must_root)]
/// <https://html.spec.whatwg.org/multipage/#dom-customelementregistry-define>
fn Define(&self, name: DOMString, constructor_: Rc<Function>, options: &ElementDefinitionOptions) -> ErrorResult {
fn Define(
&self, name: DOMString,
constructor_: Rc<CustomElementConstructor>,
options: &ElementDefinitionOptions
) -> ErrorResult {
let cx = self.window.get_cx();
rooted!(in(cx) let constructor = constructor_.callback());
let name = LocalName::from(&*name);
@ -402,7 +407,7 @@ pub struct CustomElementDefinition {
pub local_name: LocalName,
#[ignore_malloc_size_of = "Rc"]
pub constructor: Rc<Function>,
pub constructor: Rc<CustomElementConstructor>,
pub observed_attributes: Vec<DOMString>,
@ -414,7 +419,7 @@ pub struct CustomElementDefinition {
impl CustomElementDefinition {
fn new(name: LocalName,
local_name: LocalName,
constructor: Rc<Function>,
constructor: Rc<CustomElementConstructor>,
observed_attributes: Vec<DOMString>,
callbacks: LifecycleCallbacks)
-> CustomElementDefinition {
@ -543,7 +548,7 @@ pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Elemen
/// <https://html.spec.whatwg.org/multipage/#concept-upgrade-an-element>
/// Steps 7.1-7.2
#[allow(unsafe_code)]
fn run_upgrade_constructor(constructor: &Rc<Function>, element: &Element) -> ErrorResult {
fn run_upgrade_constructor(constructor: &Rc<CustomElementConstructor>, element: &Element) -> ErrorResult {
let window = window_from_node(element);
let cx = window.get_cx();
rooted!(in(cx) let constructor_val = ObjectValue(constructor.callback()));

View file

@ -6,13 +6,15 @@
[Pref="dom.customelements.enabled"]
interface CustomElementRegistry {
[Throws, CEReactions]
void define(DOMString name, Function constructor_, optional ElementDefinitionOptions options);
void define(DOMString name, CustomElementConstructor constructor_, optional ElementDefinitionOptions options);
any get(DOMString name);
Promise<void> whenDefined(DOMString name);
};
callback CustomElementConstructor = any();
dictionary ElementDefinitionOptions {
DOMString extends;
};