-
Notifications
You must be signed in to change notification settings - Fork 370
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
HTML element constructors need to Get(newTarget, "Prototype") #560
Comments
There was a consensus to store callbacks because other implementors didn't want to detect when the presence of callbacks change over time to avoid enqueuing custom element reactions when not necessary as necessary optimizations but this would not be a thing for the prototype internal slot since we always need to get it when constructing an element. |
not sure if relevant but when I've written about the super (and transpilers) problem, since we discussed this on twitter (where you seem to be disappeared) I've noticed that in Canary it's possible to create custom elements without even extending. // no extend
class MyElement {}
// definition
customElements.define('my-element', MyElement);
// here we go
const me = Reflect.construct(
HTMLElement,
[],
MyElement
); Surprisingly this doesn't throw. I'm not sure it's a Apologies if off topic. |
That's not supposed to throw. That's one of those |
So the first thing to figure out is when these two behaviors could possibly be distinguishable. They can't if you use class syntax, because in that case The other thing to consider is consistency with other constructors, as you point out. An example makes it clear that as you say, it's the current value of the Another way of looking at this is, if we were to think about "self-hosting" built-in elements with custom elements, or even just making built-in elements constructible, what would their behavior be? I'd like to think that overwriting All this together indicates to me that @rniwa's instincts are right and we should change the spec to use @dominiccooney @kojiishi, would you be able to change Blink's implementation to do the Now, let's work on the details here. In particular, what should happen if |
I haven't tried to implement this yet, but this basically sounds fine. We'd like to know what to do if the prototype property is "invalid" in some way. (Is prototype ever configurable? Could it throw, too?) |
It's not configurable but writable in regular function but it could do anything because you can create a Proxy that traps customElements.define('bad-element', new Proxy(class extends HTMLElement {}, {
get: function (target, name) {
if (name == 'prototype')
throw 'stuff';
}
})); |
Yeah, so if it throws, we should rethrow. (That also matches ES.) But what if it returns a non-object? To match ES it should fall back to the [HTMLConstructor] currently executing, I think. Does that sound reasonable to implement? Following https://tc39.github.io/ecma262/#sec-getprototypefromconstructor exactly, the logic is:
(Using [] to denote links to spec terms in IDL/ES.) Note that in the last step realm can be different from [the current Realm record], which is even more subtle fun. I'll be sure to write some test cases. |
This changes the prototype used when constructing a custom element instance from being the one saved at element definition time, to the one derived from NewTarget (with fallback semantics similar to JavaScript when new.target.prototype is not an object). Fixes WICG/webcomponents#560.
This changes the prototype used when constructing a custom element instance from being the one saved at element definition time, to the one derived from NewTarget (with fallback semantics similar to JavaScript when new.target.prototype is not an object). Fixes WICG/webcomponents#560.
This changes the prototype used when constructing a custom element instance from being the one saved at element definition time, to the one derived from NewTarget (with fallback semantics similar to JavaScript when new.target.prototype is not an object). Fixes WICG/webcomponents#560.
This changes the prototype used when constructing a custom element instance from being the one saved at element definition time, to the one derived from NewTarget (with fallback semantics similar to JavaScript when new.target.prototype is not an object). Fixes WICG/webcomponents#560.
The current spec says HTMLElement constructor needs to use the prototype stored by
customElements.define
.This is not the way regular constructor works in a
super()
call. Furthermore, this semantics is really cumbersome to implement in WebKit / JSC due to the way our engine's abstractions are designed.The text was updated successfully, but these errors were encountered: