Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify create an element assertion #1338

Open
annevk opened this issue Dec 16, 2024 · 2 comments
Open

Clarify create an element assertion #1338

annevk opened this issue Dec 16, 2024 · 2 comments
Labels
clarification Standard could be clearer topic: nodes

Comments

@annevk
Copy link
Member

annevk commented Dec 16, 2024

@domenic in create an element we have:

Assert: result’s custom element state and custom element definition are initialized.

Can we improve this by saying custom element definition is non-null? And custom element state is "custom"? I think that should hold after a successful constructor call.

@annevk annevk added clarification Standard could be clearer topic: nodes labels Dec 16, 2024
@domenic
Copy link
Member

domenic commented Dec 19, 2024

This is very subtle. I wrote several wrong answers to this question before arriving at the conclusion that, yes, I think this is true.

The case I was concerned about was.

customElements.define("x-y", class extends HTMLElement {
  constructor() {
    // super() intentionally omitted
  }
});

document.createElement("x-y");

In that case the Web IDL "construct" call does nothing to set the custom element state or custom element definition (since no [HTMLConstructor] spec code ran). So I thought the assert would fail. However, what actually happens is that https://webidl.spec.whatwg.org/#construct-a-callback-function step 12 throws, because result is not a platform object and so cannot be converted to HTMLElement.

Inserting a note to this effect would be helpful to future readers, I think.


So yes, if we make it past the construct step, we must have run the [HTMLConstructor] steps to completion. Which I believe means your suggestions hold.

It still might be worth building WebKit with such an assertion and then running the custom-elements/ WPT suite, just to check.

@domenic
Copy link
Member

domenic commented Dec 19, 2024

Actually, what about this case?

<script>
customElements.define("x-y, asBefore);
</script>

<x-y></x-y>

<script>
const failedCE = document.querySelector("x-y"); // upgrade failed so this has state "failed"

customElements.define("x-z", class extends HTMLElement {
  constructor() {
    return failedCE;
  }
});

const failedCE2 = document.createElement("x-z");
</script>

I haven't traced through what this will do all the way, but I'm pretty sure it will make it to the assert line in question with the CE state as "failed", not "custom".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Standard could be clearer topic: nodes
Development

No branches or pull requests

2 participants