Skip to content

Commit

Permalink
Update type of custom element constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
tigercosmos committed May 30, 2018
1 parent 7cc4165 commit 6d426f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 9 additions & 4 deletions components/script/dom/customelementregistry.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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>,

Expand All @@ -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 {
Expand Down Expand Up @@ -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()));
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/webidls/CustomElementRegistry.webidl
Expand Up @@ -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;
};

0 comments on commit 6d426f7

Please sign in to comment.