-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Normative: Constructor may be more concisely defined. #2055
Comments
Your proposed wording permits objects that have a |
I strongly support this change, but it would be normative unless we did some hijinx, and it would likely require some changes to Proxy, where these slots are observable (forcing it to be normative). |
No, such an object, having no The problem is actually that it doesn't address the question of an object that supports (Of course, this all changes if/when we get the normative change that @michaelficarra and @ljharb have in mind.) |
@jmdyck I was not using the word "permits" as a synonym for "includes". I meant the new text does not prohibit such an object from existing, as the current text does. |
Yup, I just realized that. Sorry for the noise. (Still, the links to old PRs may be useful for the OP.) |
OH so It was actually using "function object" before PR #1187. From what I understood from https://stackoverflow.com/questions/50109554/, that change was identified as an "editorial change" because it only made an implicit assumption explicit?
I'm trying to understand the effects of permitting such object from existing.
Ah, I wasn't aware they could be observable externally. |
A good chunk of the internet relies on I did some testing with |
Yup. (Or, at least, that was my take, and no-one disagreed.)
You are free to imagine that such objects exist "out there", but the spec requires implementations to behave in such a way that you can never observe the existence of such objects, so I'm not sure there's any benefit to imagining that they do exist. |
This is an interesting issue, several days ago someone asked what's "constructor" really mean. In the spec,
--- they creates primitive values not objects. And engines like V8 give the error info "BigInt/Symbol is not a constructor" when |
Yeah, this is an example where the definition in "4.4 Terms and Definitions" conveys the general idea, but doesn't really match the precise definition in the body of the spec.
According to the definition in 6.1.7.2 (which started off this issue), a constructor is an object that supports the [[Construct]] internal method. And the spec definitely refers to Symbol and BigInt as constructors, so that implies they support [[Construct]]. Moreover, in each case, the algorithm says Some other spec wording re [[Construct]] that might be nice to clean up: 10.3 Built-in Function Objects says:
which suggests that every built-in function has both [[Call]] and [[Construct]], though in some cases, the [[Construct]] can't be invoked. That interpretation doesn't really fit with anything else in the spec. Also, 10.3 and 18 ECMAScript Standard Built-in Objects both say:
which is fine, but they both go on to say:
which allows for a function that is not identified as a constructor but nevertheless is specified to implement [[Construct]]. Which is a bit odd. I'm pretty sure there's no such thing in the spec. In fact, I don't even think there's a built-in function that we specifically say implements [[Construct]], regardless of whether we identify it as a constructor. So I'm not sure why that "unless" clause is there. (It dates back to ES6, so maybe made more sense then.) |
In particular, it's super weird that "things you can |
After some research, I noticed that |
Yeah, it's weird, and I guess we can do nothing to "fix" it. Besides
Maybe we can try to advance |
The current spec defined constructor as such:
The bolded part seems to be unnecessarily verbose and complicated.
Can we just simplify the bolded part as below?
I'm more than happy to (figure out how to) send a PR if ppl liked the idea.
The text was updated successfully, but these errors were encountered: