diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2020-01-26 06:07:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-26 06:07:08 -0500 |
commit | e3a9063412bcb453c1eb7d23b48bcc80bd71eea2 (patch) | |
tree | 8aaa0fc037fbe8864b07327b1c6cc1a68b152601 /components/script/dom | |
parent | 0bd266149263cbdcd0ddd677ab3a7eaa0322b660 (diff) | |
parent | 10869f66b57d70ad95117393ee13b45c375a7634 (diff) | |
download | servo-e3a9063412bcb453c1eb7d23b48bcc80bd71eea2.tar.gz servo-e3a9063412bcb453c1eb7d23b48bcc80bd71eea2.zip |
Auto merge of #25575 - pshaughn:celoop, r=jdm
Prevent infinite recursion when upgrading custom elements
<!-- Please describe your changes on the following line: -->
The spec and tests were out of sync when I implemented #25410 and I mentioned I'd have an extra detail to attend to if whatwg/html#5126 landed; it did, and I did, and a couple test cases pass.
---
<!-- 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 two WPT test cases, see test metadata in commit
<!-- Either: -->
- [X] There are tests for these changes
<!-- 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. -->
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/customelementregistry.rs | 22 | ||||
-rw-r--r-- | components/script/dom/element.rs | 4 |
2 files changed, 14 insertions, 12 deletions
diff --git a/components/script/dom/customelementregistry.rs b/components/script/dom/customelementregistry.rs index 12a6e744a5e..77d4e10fa01 100644 --- a/components/script/dom/customelementregistry.rs +++ b/components/script/dom/customelementregistry.rs @@ -595,13 +595,17 @@ impl CustomElementDefinition { /// <https://html.spec.whatwg.org/multipage/#concept-upgrade-an-element> #[allow(unsafe_code)] pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Element) { - // Steps 1-2 + // Step 1 let state = element.get_custom_element_state(); - if state == CustomElementState::Custom || state == CustomElementState::Failed { + if state != CustomElementState::Undefined && state != CustomElementState::Uncustomized { return; } - // Step 3 happens later to save having to undo it in an exception + // Step 2 + element.set_custom_element_definition(Rc::clone(&definition)); + + // Step 3 + element.set_custom_element_state(CustomElementState::Failed); // Step 4 for attr in element.attrs().iter() { @@ -639,14 +643,12 @@ pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Elemen // Step 8 exception handling if let Err(error) = result { // Step 8.exception.1 - element.set_custom_element_state(CustomElementState::Failed); + element.clear_custom_element_definition(); - // Step 8.exception.2 isn't needed since step 3 hasn't happened yet - - // Step 8.exception.3 + // Step 8.exception.2 element.clear_reaction_queue(); - // Step 8.exception.4 + // Step 8.exception.3 let global = GlobalScope::current().expect("No current global"); let cx = global.get_cx(); unsafe { @@ -660,11 +662,7 @@ pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Elemen // TODO Step 9: "If element is a form-associated custom element..." // Step 10 - element.set_custom_element_state(CustomElementState::Custom); - - // Step 3 - element.set_custom_element_definition(definition); } /// <https://html.spec.whatwg.org/multipage/#concept-upgrade-an-element> diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index cb7d339a78e..29bdaf2f3bf 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -342,6 +342,10 @@ impl Element { self.rare_data().as_ref()?.custom_element_definition.clone() } + pub fn clear_custom_element_definition(&self) { + self.ensure_rare_data().custom_element_definition = None; + } + pub fn push_callback_reaction(&self, function: Rc<Function>, args: Box<[Heap<JSVal>]>) { self.ensure_rare_data() .custom_element_reaction_queue |