Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: Define default constructors using spec steps #2216
Normative: Define default constructors using spec steps #2216
Changes from all commits
d9e5692
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this wait for #2109 and use an abstract closure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the default constructor doesn’t need to capture any variable from the current scope, so I feel like it’s unnecessary in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Coming from #2608 (comment))
I see why this change was necessary: default constructors that are created using
CreateBuiltinFunction
now are "built-in functions" and have an [[InitialName]] slot; however they should still return the [[SourceText]] from the user's program.But the new spec text does permit implementations to return the [[SourceText]] for basically arbitrary built-in functions now, especially for those that are implemented as ECMAScript function objects. I do not think that change was intentional, I believe that all functions which are not defined by user code (but rather, by the implementation) should have to return a string in
NativeFunction
format. At least this was listed as a goal in the Function.prototype.toString revision proposal.Would it be sensible to rollback this swapping of
Function.prototype.toString
steps, and instead changeCreateBuiltinFunction
to not create an [[InitialName]] slot for default constructors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would implementations be forced to omit source text? An engine should always be free to provide meaningful source text in
.toString
if it so chooses.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's the (not unreasonable) general expectation that native functions can be detected by looking for
[native code]
in thetoString
representation, and this is used in many codebases. See https://davidwalsh.name/detect-native-function or https://stackoverflow.com/questions/6598945/detect-if-function-is-native-to-browser for reference.The Function.prototype.toString revision proposal did mean to "standardise the string representation of built-in functions and host objects". There has gone a lot of thought into this, and there were requests to also ensure proper function name representations and even exact whitespace patterns in the
NativeFunction
syntax.If you want to change this, fine, but it seems this happened without discussion in TC39, likely even by accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is an unreasonable expectation, since
(function () {}).bind()
produces the same toString representation.To my recollection, it was very much not an accident to permit native functions to have any source text they want, as long as it's either valid ecmascript, or, the native code representation.