mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Auto merge of #20879 - tigercosmos:ccc, r=jdm
Update type of custom element constructor <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #20875 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20879) <!-- Reviewable:end -->
This commit is contained in:
commit
0356be3021
2 changed files with 12 additions and 5 deletions
|
@ -5,6 +5,7 @@
|
||||||
use dom::bindings::callback::{CallbackContainer, ExceptionHandling};
|
use dom::bindings::callback::{CallbackContainer, ExceptionHandling};
|
||||||
use dom::bindings::cell::DomRefCell;
|
use dom::bindings::cell::DomRefCell;
|
||||||
use dom::bindings::codegen::Bindings::CustomElementRegistryBinding;
|
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::CustomElementRegistryMethods;
|
||||||
use dom::bindings::codegen::Bindings::CustomElementRegistryBinding::ElementDefinitionOptions;
|
use dom::bindings::codegen::Bindings::CustomElementRegistryBinding::ElementDefinitionOptions;
|
||||||
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
||||||
|
@ -193,7 +194,11 @@ unsafe fn get_callback(
|
||||||
impl CustomElementRegistryMethods for CustomElementRegistry {
|
impl CustomElementRegistryMethods for CustomElementRegistry {
|
||||||
#[allow(unsafe_code, unrooted_must_root)]
|
#[allow(unsafe_code, unrooted_must_root)]
|
||||||
/// <https://html.spec.whatwg.org/multipage/#dom-customelementregistry-define>
|
/// <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();
|
let cx = self.window.get_cx();
|
||||||
rooted!(in(cx) let constructor = constructor_.callback());
|
rooted!(in(cx) let constructor = constructor_.callback());
|
||||||
let name = LocalName::from(&*name);
|
let name = LocalName::from(&*name);
|
||||||
|
@ -402,7 +407,7 @@ pub struct CustomElementDefinition {
|
||||||
pub local_name: LocalName,
|
pub local_name: LocalName,
|
||||||
|
|
||||||
#[ignore_malloc_size_of = "Rc"]
|
#[ignore_malloc_size_of = "Rc"]
|
||||||
pub constructor: Rc<Function>,
|
pub constructor: Rc<CustomElementConstructor>,
|
||||||
|
|
||||||
pub observed_attributes: Vec<DOMString>,
|
pub observed_attributes: Vec<DOMString>,
|
||||||
|
|
||||||
|
@ -414,7 +419,7 @@ pub struct CustomElementDefinition {
|
||||||
impl CustomElementDefinition {
|
impl CustomElementDefinition {
|
||||||
fn new(name: LocalName,
|
fn new(name: LocalName,
|
||||||
local_name: LocalName,
|
local_name: LocalName,
|
||||||
constructor: Rc<Function>,
|
constructor: Rc<CustomElementConstructor>,
|
||||||
observed_attributes: Vec<DOMString>,
|
observed_attributes: Vec<DOMString>,
|
||||||
callbacks: LifecycleCallbacks)
|
callbacks: LifecycleCallbacks)
|
||||||
-> CustomElementDefinition {
|
-> CustomElementDefinition {
|
||||||
|
@ -543,7 +548,7 @@ pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Elemen
|
||||||
/// <https://html.spec.whatwg.org/multipage/#concept-upgrade-an-element>
|
/// <https://html.spec.whatwg.org/multipage/#concept-upgrade-an-element>
|
||||||
/// Steps 7.1-7.2
|
/// Steps 7.1-7.2
|
||||||
#[allow(unsafe_code)]
|
#[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 window = window_from_node(element);
|
||||||
let cx = window.get_cx();
|
let cx = window.get_cx();
|
||||||
rooted!(in(cx) let constructor_val = ObjectValue(constructor.callback()));
|
rooted!(in(cx) let constructor_val = ObjectValue(constructor.callback()));
|
||||||
|
|
|
@ -6,13 +6,15 @@
|
||||||
[Pref="dom.customelements.enabled"]
|
[Pref="dom.customelements.enabled"]
|
||||||
interface CustomElementRegistry {
|
interface CustomElementRegistry {
|
||||||
[Throws, CEReactions]
|
[Throws, CEReactions]
|
||||||
void define(DOMString name, Function constructor_, optional ElementDefinitionOptions options);
|
void define(DOMString name, CustomElementConstructor constructor_, optional ElementDefinitionOptions options);
|
||||||
|
|
||||||
any get(DOMString name);
|
any get(DOMString name);
|
||||||
|
|
||||||
Promise<void> whenDefined(DOMString name);
|
Promise<void> whenDefined(DOMString name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
callback CustomElementConstructor = any();
|
||||||
|
|
||||||
dictionary ElementDefinitionOptions {
|
dictionary ElementDefinitionOptions {
|
||||||
DOMString extends;
|
DOMString extends;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue