Skip to content

Prevent infinite recursion when upgrading custom elements#5126

Merged
domenic merged 3 commits intomasterfrom
prevent-ce-upgrade-recursion
Jan 22, 2020
Merged

Prevent infinite recursion when upgrading custom elements#5126
domenic merged 3 commits intomasterfrom
prevent-ce-upgrade-recursion

Conversation

@domenic
Copy link
Member

@domenic domenic commented Dec 4, 2019

Fixes #5118.

(See WHATWG Working Mode: Changes for more details.)


@rniwa @smaug---- can you give a quick +1? This is just a bugfix in my opinion.

@mfreed7 can you write tests for this as part of the Chromium fix?


/custom-elements.html ( diff )

@domenic domenic added the topic: custom elements Relates to custom elements (as defined in DOM and HTML) label Dec 4, 2019
@mfreed7
Copy link
Collaborator

mfreed7 commented Dec 6, 2019

@domenic Yes I'll be happy to write a WPT for this with my patch. (Already done.)

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 6, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to kCustom earlier in the process,
so that recursive calls can properly early-out at step #1 (of [2]).

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7

<li><p>Set <var>element</var>'s <span>custom element state</span> to "<code
data-x="">custom</code>".</p></li>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make it so that custom element's state can move from "custom" to "failed". I don't think we currently allow that that would be strange and might pose a problem elsewhere. We may need to introduce a new state like "upgrading", and reject upgrading of an element in such a state instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this would be observable if you do this.matches(":defined") inside the constructor? You want to ensure that keeps being false, I take it?

Copy link

@rniwa rniwa Dec 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. We want to make sure once a custom element has reached :defined, then it never goes back into :undefined state. Since that would be strange & confusing; it could even cause some compatibility issues with existing content that relies on this invariant today.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've reworked this to hold, although I did it by just using the "failed" state instead of introducing a new state.

@mfreed7 can you be sure to capture this .matches(":defined") issue in your test case? And also your review would be appreciated since this deviates a bit from what we discussed in #5118.

@rniwa, does this LGTY?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rniwa Thanks for the suggestion. I can confirm that things work much better with a new "upgrading" state, rather than immediately going to "defined" in step 3. No more test failures, and the two use cases that started the Chromium bug are fixed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@domenic Sorry I missed your comment before posting mine above. I like the new change - saves a bit in node. And it appears to work correctly as you've written it. I added a WPT test for this.matches(":defined") within the constructor. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rniwa LGTY?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the chrome CL is ready, just waiting for this PR to land.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 10, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to kCustom earlier in the process,
so that recursive calls can properly early-out at step #1 (of [2]).

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 10, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to kCustom earlier in the process,
so that recursive calls can properly early-out at step #1 (of [2]).

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 10, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to kCustom earlier in the process,
so that recursive calls can properly early-out at step #1 (of [2]).

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 10, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to kCustom earlier in the process,
so that recursive calls can properly early-out at step #1 (of [2]).

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 11, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to kCustom earlier in the process,
so that recursive calls can properly early-out at step #1 (of [2]).

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 11, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to kCustom earlier in the process,
so that recursive calls can properly early-out at step #1 (of [2]).

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 11, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to a new state called "upgrading"
before the constructor is called. With this change in place,
recursive calls can properly early-out at step #1 (of [2]).

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 12, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to "failed" before the constructor
is called. With this change in place, recursive calls will
early-out at step #2 (of [2]), and avoid the recursion.

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 13, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to "failed" before the constructor
is called. With this change in place, recursive calls will
early-out at step #2 (of [2]), and avoid the recursion.

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
@domenic domenic requested a review from rniwa December 19, 2019 19:11
@rniwa
Copy link

rniwa commented Dec 19, 2019

Sorry, I know I have to review this PR. Hoping to do that in the next few days.

@mfreed7
Copy link
Collaborator

mfreed7 commented Dec 30, 2019

Any objections to me landing this change in Chromium now, prior to this PR landing? It seems rather safe - I doubt anyone was depending on the prior infinite recursion behavior. And if we end up changing the details of exactly how the recursion is prevented, we can land that as a subsequent change in code.

@domenic
Copy link
Member Author

domenic commented Dec 30, 2019

No objections, please land! We need multi-implementer support to land in the spec, which is tricky over the holidays, but that shouldn't block implementations.

@mfreed7
Copy link
Collaborator

mfreed7 commented Dec 31, 2019

Thanks!

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 31, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to "failed" before the constructor
is called. With this change in place, recursive calls will
early-out at step #2 (of [2]), and avoid the recursion.

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931644
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727841}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 31, 2019
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to "failed" before the constructor
is called. With this change in place, recursive calls will
early-out at step #2 (of [2]), and avoid the recursion.

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931644
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727841}
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 1, 2020
Implement CustomElementRegistry.upgrade

<!-- Please describe your changes on the following line: -->
An additional small change will be needed if whatwg/html#5126 lands, which will pass an infinite recursion test this is currently failing in custom-elements/upgrading.html (right now the test is asking for behavior that isn't in the spec).
The remaining test in custom-elements/custom-element-registry/upgrade.html is because it needs shadow DOM.

---
<!-- 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 #24989

<!-- 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. -->
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 3, 2020
Implement CustomElementRegistry.upgrade

<!-- Please describe your changes on the following line: -->
An additional small change will be needed if whatwg/html#5126 lands, which will pass an infinite recursion test this is currently failing in custom-elements/upgrading.html (right now the test is asking for behavior that isn't in the spec).
The remaining test in custom-elements/custom-element-registry/upgrade.html is because it needs shadow DOM.

---
<!-- 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 #24989

<!-- 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. -->
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jan 3, 2020
…uctions, a=testonly

Automatic update from web-platform-tests
Disallow recursive custom element constructions

With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to "failed" before the constructor
is called. With this change in place, recursive calls will
early-out at step #2 (of [2]), and avoid the recursion.

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931644
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727841}

--

wpt-commits: 4f24cabbe1f503f3daf8cf0834f4fb1a032f31bc
wpt-pr: 20465
xeonchen pushed a commit to xeonchen/gecko that referenced this pull request Jan 3, 2020
…uctions, a=testonly

Automatic update from web-platform-tests
Disallow recursive custom element constructions

With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to "failed" before the constructor
is called. With this change in place, recursive calls will
early-out at step mykmelez#2 (of [2]), and avoid the recursion.

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931644
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727841}

--

wpt-commits: 4f24cabbe1f503f3daf8cf0834f4fb1a032f31bc
wpt-pr: 20465
@EdgarChen
Copy link
Member

@domenic domenic requested a review from annevk January 21, 2020 20:49
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editorially this looks good to me, but left some optional suggestions.

</ol>

<p class="note">If the above steps threw an exception, then <var>element</var>'s <span>custom
element state</span> will remain "<code data-x="">failed</code>".</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this an assert.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this more as a note, as it's more just reassuring you that nothing changed, instead of asserting something...

return.</p>
<li id="concept-upgrade-an-element-early-exit">
<p>If <var>element</var>'s <span>custom element state</span> is not "<code
data-x="">undefined</code>" or "<code data-x="">uncustomized</code>", then return.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, any reason not to go with the positive check here (failed or custom)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember waffling on this a few times, especially when I was considering adding a new state. I'm still not sure what is best, but I guess the current PR feels a little better, because it's basically saying "If you're not in an upgradable state, then fail". The positive check is more like "If you are in an un-upgradable state, then fail", which communicates the intent slightly less well, in my opinion.

@domenic domenic merged commit 2793ee4 into master Jan 22, 2020
@domenic domenic deleted the prevent-ce-upgrade-recursion branch January 22, 2020 19:39
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 25, 2020
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. -->
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 25, 2020
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. -->
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 25, 2020
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. -->
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 26, 2020
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. -->
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 26, 2020
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. -->
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 26, 2020
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. -->
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 26, 2020
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. -->
xeonchen pushed a commit to xeonchen/gecko that referenced this pull request Jan 28, 2020
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jan 28, 2020
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Jan 28, 2020
…ts; r=smaug

See whatwg/html#5126.

Differential Revision: https://phabricator.services.mozilla.com/D60848

UltraBlame original commit: 687c61a5b2642d36bc7e6461bbc846fea5479e30
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Jan 28, 2020
…ts; r=smaug

See whatwg/html#5126.

Differential Revision: https://phabricator.services.mozilla.com/D60848

UltraBlame original commit: 687c61a5b2642d36bc7e6461bbc846fea5479e30
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 15, 2020
…changed during upgrading

In https://dom.spec.whatwg.org/#handle-attribute-changes, the attributeChangedCallback
reaction is enqueued only if the custom-element-state is customized.

And the assumption of "custom-element-definition is only available on the element whose
custom-element-state is customized" is no longer true after bug 1610054 along with the
spec changings in whatwg/html#5126.

Differential Revision: https://phabricator.services.mozilla.com/D71027

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1629761
gecko-commit: a8129abc4c2d5efca1c694803ea43550f39fd7a0
gecko-integration-branch: autoland
gecko-reviewers: smaug
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Apr 15, 2020
…ibute that is changed during upgrading; r=smaug

In https://dom.spec.whatwg.org/#handle-attribute-changes, the attributeChangedCallback
reaction is enqueued only if the custom-element-state is customized.

And the assumption of "custom-element-definition is only available on the element whose
custom-element-state is customized" is no longer true after bug 1610054 along with the
spec changings in whatwg/html#5126.

Differential Revision: https://phabricator.services.mozilla.com/D71027

--HG--
extra : moz-landing-system : lando
xeonchen pushed a commit to xeonchen/gecko that referenced this pull request Apr 16, 2020
…ibute that is changed during upgrading; r=smaug

In https://dom.spec.whatwg.org/#handle-attribute-changes, the attributeChangedCallback
reaction is enqueued only if the custom-element-state is customized.

And the assumption of "custom-element-definition is only available on the element whose
custom-element-state is customized" is no longer true after bug 1610054 along with the
spec changings in whatwg/html#5126.

Differential Revision: https://phabricator.services.mozilla.com/D71027
moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 16, 2020
…changed during upgrading

In https://dom.spec.whatwg.org/#handle-attribute-changes, the attributeChangedCallback
reaction is enqueued only if the custom-element-state is customized.

And the assumption of "custom-element-definition is only available on the element whose
custom-element-state is customized" is no longer true after bug 1610054 along with the
spec changings in whatwg/html#5126.

Differential Revision: https://phabricator.services.mozilla.com/D71027

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1629761
gecko-commit: a8129abc4c2d5efca1c694803ea43550f39fd7a0
gecko-integration-branch: autoland
gecko-reviewers: smaug
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Apr 19, 2020
…ibute that is changed during upgrading; r=smaug a=RyanVM

In https://dom.spec.whatwg.org/#handle-attribute-changes, the attributeChangedCallback
reaction is enqueued only if the custom-element-state is customized.

And the assumption of "custom-element-definition is only available on the element whose
custom-element-state is customized" is no longer true after bug 1610054 along with the
spec changings in whatwg/html#5126.

Differential Revision: https://phabricator.services.mozilla.com/D71027
xeonchen pushed a commit to xeonchen/gecko that referenced this pull request Apr 23, 2020
…ibute that is changed during upgrading; r=smaug a=RyanVM

In https://dom.spec.whatwg.org/#handle-attribute-changes, the attributeChangedCallback
reaction is enqueued only if the custom-element-state is customized.

And the assumption of "custom-element-definition is only available on the element whose
custom-element-state is customized" is no longer true after bug 1610054 along with the
spec changings in whatwg/html#5126.

Differential Revision: https://phabricator.services.mozilla.com/D71027
bhearsum pushed a commit to mozilla-releng/staging-firefox that referenced this pull request May 1, 2025
…uctions, a=testonly

Automatic update from web-platform-tests
Disallow recursive custom element constructions

With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to "failed" before the constructor
is called. With this change in place, recursive calls will
early-out at step #2 (of [2]), and avoid the recursion.

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931644
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727841}

--

wpt-commits: 4f24cabbe1f503f3daf8cf0834f4fb1a032f31bc
wpt-pr: 20465
bhearsum pushed a commit to mozilla-releng/staging-firefox that referenced this pull request May 1, 2025
bhearsum pushed a commit to mozilla-releng/staging-firefox that referenced this pull request May 1, 2025
…ibute that is changed during upgrading; r=smaug

In https://dom.spec.whatwg.org/#handle-attribute-changes, the attributeChangedCallback
reaction is enqueued only if the custom-element-state is customized.

And the assumption of "custom-element-definition is only available on the element whose
custom-element-state is customized" is no longer true after bug 1610054 along with the
spec changings in whatwg/html#5126.

Differential Revision: https://phabricator.services.mozilla.com/D71027
bytes-crafter pushed a commit to openFyde/chromium that referenced this pull request May 28, 2025
With this CL, recursive custom element constructions are no
longer allowed. I.e. this will now only run the constructor once:
  class extends HTMLElement {
    constructor() {
      super();
      customElements.upgrade(this);
    }
  }

Previously, the code and spec had a bug which caused the above
code snippet to infinitely recurse. In [1] the spec has changed,
to set the custom element state to "failed" before the constructor
is called. With this change in place, recursive calls will
early-out at step #2 (of [2]), and avoid the recursion.

[1] whatwg/html#5126
[2] https://html.spec.whatwg.org/multipage/custom-elements.html#upgrades

Bug: 966472
Change-Id: I76e88c0b70132eee2482c304ef9e727ae1fe8fc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931644
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727841}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: custom elements Relates to custom elements (as defined in DOM and HTML)

Development

Successfully merging this pull request may close these issues.

Should infinite recursion of custom element constructors be possible?

5 participants