Re: [WICG/webcomponents] [scoped-registries] Interaction with HTML element's overridden constructor steps (Issue #969)

Now (I think) I finally understand how the [construction stack](https://html.spec.whatwg.org/multipage/custom-elements.html#concept-custom-element-definition-construction-stack) works, so it's a pretty natrual idea to adapt it for this issue:
- Move the construction stack from definition to constructor
- Each stack entry is augmented into either an `(element, definition)` pair, or an already-constructed marker
- At the beginning of the [overridden constructor steps](https://html.spec.whatwg.org/multipage/dom.html#html-element-constructors), we get the defintion from the `NewTarget` by:
  - If there's a non-empty construction stack on `NewTarget` and the last entry is not the already-constructed marker, use the definition in that entry
  - Otherwise, try to find a definition from the global registry

There's also some detail that I need to verify:

The construction stack actually always throws if there's a recursive constructor call, regardless of whether it's before or after `super()`:
- If it's before `super()`, later the outer `super()` will see an already-constructed marker and throw
- If it's after `super()`, then the inner `super()` will see an already-constructed marker and throw
You can see the behavior in test case https://jsfiddle.net/gu81kdw5/

I'm not sure if this matches the intention of the spec, which only says before-super calls are bad. But I guess it doesn't matter, because there's no real use of constructor recursion. If it doesn't match the original intention, then we can just change the intention and recognize the current behavior.

(I've also put up an [implementation patch](https://chromium-review.googlesource.com/c/chromium/src/+/4144367), which will land if everything above looks fine to you)

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/969#issuecomment-1463077010
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/969/1463077010@github.com>

Received on Friday, 10 March 2023 01:33:53 UTC