Skip to content

Commit 3762395

Browse files
author
bors-servo
authored
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. -->
2 parents 31eafad + 10869f6 commit 3762395

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

components/script/dom/customelementregistry.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,17 @@ impl CustomElementDefinition {
586586
/// <https://html.spec.whatwg.org/multipage/#concept-upgrade-an-element>
587587
#[allow(unsafe_code)]
588588
pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Element) {
589-
// Steps 1-2
589+
// Step 1
590590
let state = element.get_custom_element_state();
591-
if state == CustomElementState::Custom || state == CustomElementState::Failed {
591+
if state != CustomElementState::Undefined && state != CustomElementState::Uncustomized {
592592
return;
593593
}
594594

595-
// Step 3 happens later to save having to undo it in an exception
595+
// Step 2
596+
element.set_custom_element_definition(Rc::clone(&definition));
597+
598+
// Step 3
599+
element.set_custom_element_state(CustomElementState::Failed);
596600

597601
// Step 4
598602
for attr in element.attrs().iter() {
@@ -630,14 +634,12 @@ pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Elemen
630634
// Step 8 exception handling
631635
if let Err(error) = result {
632636
// Step 8.exception.1
633-
element.set_custom_element_state(CustomElementState::Failed);
637+
element.clear_custom_element_definition();
634638

635-
// Step 8.exception.2 isn't needed since step 3 hasn't happened yet
636-
637-
// Step 8.exception.3
639+
// Step 8.exception.2
638640
element.clear_reaction_queue();
639641

640-
// Step 8.exception.4
642+
// Step 8.exception.3
641643
let global = GlobalScope::current().expect("No current global");
642644
let cx = global.get_cx();
643645
unsafe {
@@ -651,11 +653,7 @@ pub fn upgrade_element(definition: Rc<CustomElementDefinition>, element: &Elemen
651653
// TODO Step 9: "If element is a form-associated custom element..."
652654

653655
// Step 10
654-
655656
element.set_custom_element_state(CustomElementState::Custom);
656-
657-
// Step 3
658-
element.set_custom_element_definition(definition);
659657
}
660658

661659
/// <https://html.spec.whatwg.org/multipage/#concept-upgrade-an-element>

components/script/dom/element.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ impl Element {
342342
self.rare_data().as_ref()?.custom_element_definition.clone()
343343
}
344344

345+
pub fn clear_custom_element_definition(&self) {
346+
self.ensure_rare_data().custom_element_definition = None;
347+
}
348+
345349
pub fn push_callback_reaction(&self, function: Rc<Function>, args: Box<[Heap<JSVal>]>) {
346350
self.ensure_rare_data()
347351
.custom_element_reaction_queue

tests/wpt/metadata/custom-elements/upgrading.html.ini

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,3 @@
44

55
[If definition's disable shadow is true and element's shadow root is non-null, then throw a "NotSupportedError" DOMException.]
66
expected: FAIL
7-
8-
[Infinite constructor recursion with upgrade(this) should not be possible]
9-
expected: FAIL
10-
11-
[Infinite constructor recursion with appendChild should not be possible]
12-
expected: FAIL
13-

0 commit comments

Comments
 (0)