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

Define "usual constructor steps" #797

Merged
merged 5 commits into from
Sep 24, 2019
Merged

Define "usual constructor steps" #797

merged 5 commits into from
Sep 24, 2019

Conversation

domenic
Copy link
Member

@domenic domenic commented Sep 17, 2019

This is for use in [HTMLConstructor] in whatwg/html#4915.

There are alternative approaches and wordings that might be better, e.g.

  • Say "perform the following steps or any others specified by specs" inline instead of allowing the usual steps to be replaced using a paragraph at the bottom
  • Have an explicit "overridden constructor steps" value for each interface object, which [HTMLConstructor] sets and this algorithm consults

But I thought I'd start here to get the ball rolling, as it's the first thing that occurred to me. Happy to tweak as desired.


Preview | Diff

This is for use in [HTMLConstructor] in whatwg/html#4915.
@Ms2ger
Copy link
Member

Ms2ger commented Sep 17, 2019

I'm not a big fan of this approach, personally; I think it'd be better to have something like

  1. Let steps be [other steps (for interface I)], if they exist, or the [usual constructor steps (for interface I)] otherwise.

Any reason you're referring to the interface object, in particular?

@domenic
Copy link
Member Author

domenic commented Sep 17, 2019

Sounds like my second option, right? Can do.

Any reason you're referring to the interface object, in particular?

Nope, interface makes sense too.

@domenic
Copy link
Member Author

domenic commented Sep 18, 2019

@Ms2ger I pushed a new approach, but I feel like there should be some warning text talking about how these steps are not general-purpose and are only used in special scenarios. Would you be able to help draft such text? I'm having some trouble doing so myself.

An interface may have <dfn export>overridden constructor steps</dfn>, which can
change the behavior of the [=interface object=] when called or constructed. By
default interfaces do not have such steps.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a warning like we have a few already for legacy features, saying something like

In general, constructors are described by defining a [=constructor operation=] and its behavior.
The [=overridden constructor steps=] are used only for more complicated situations.
Editors who wish to use this feature are strongly advised to discuss this by filing an issue before proceeding.

<div algorithm>

The [=interface object=] for a given [=interface=] |I|
with [=identifier=] |id| and in [=Realm=] |realm|
is <dfn lt="create an interface object">created</dfn> as follows:

1. Let |steps| be the following steps:
1. Let |steps| be |I|'s [=overriden constructor steps=] if they exist, or
the following steps otherwise:
1. If |I| was not declared with a [=constructor operation=],
then [=ECMAScript/throw=] a {{ECMAScript/TypeError}}.
1. If {{NewTarget}} is <emu-val>undefined</emu-val>, then
Copy link
Member

Choose a reason for hiding this comment

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

Should we keep the first two steps, even when overriding the rest of the algorithm?

Maybe also the last four steps?

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 that would work for [HTMLConstructor], although it feels cleaner to just have a general primitive that replaces the whole thing.

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'll keep it like this for now, but we can refactor later if you think it's much better.

@domenic domenic merged commit 9c59759 into master Sep 24, 2019
@domenic domenic deleted the usual-constructor-steps branch September 24, 2019 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants