This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Normative: End this
TDZ before running initializers
#92
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, the TDZ of `this` in a subclass constructor ended when the `super()` call was entirely finished. However, `this` is visible as not being in TDZ running initializers. For example: { let f; class A extends (class {}) { x = (this, f()); constructor() { f = () => this; super(); } }; new A; } Previously, `f()` would lead to a ReferenceError in this case, while `this` would evaluate to the new instance under construction. This patch tweaks the TDZ to end a little bit sooner, so that `this` is defined inside of the constructor's scope *before* the initializers are run. In the above example, there would be no ReferenceError under the semantics in this patch. Thanks to Caitlin Potter, Kevin Gibbons and Jordan Harband for contributing to the discussion that led to this change.
bakkot
approved these changes
Apr 6, 2018
ljharb
approved these changes
Apr 6, 2018
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.
LGTM!
lgtm |
Wow, what a quick review! Thanks. Would anyone be interested in writing test262 tests for this change? |
@littledan Sure, give me a minute. |
lgtm |
Tests merged tc39/test262#1507 I'm going to spend a little more time with the tests and these changes to verify coverage. |
kisg
pushed a commit
to paul99/v8mips
that referenced
this pull request
Apr 17, 2018
Class fields needs to be initialized after `this` is bound, as per the new spec change: tc39/proposal-class-fields#92 This CL moves the initialization of `this` from parser desugaring to the bytecode generator. Bug: v8:7647 Change-Id: I20f749403e5a4d2f06a39726cf39012ceb541987 Reviewed-on: https://chromium-review.googlesource.com/1014383 Reviewed-by: Mythri Alle <[email protected]> Commit-Queue: Sathya Gunasekaran <[email protected]> Cr-Commit-Position: refs/heads/master@{#52646}
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Previously, the TDZ of
this
in a subclass constructor ended whenthe
super()
call was entirely finished. However,this
is visibleas not being in TDZ running initializers. For example:
Previously,
f()
would lead to a ReferenceError in this case, whilethis
would evaluate to the new instance under construction.This patch tweaks the TDZ to end a little bit sooner, so that
this
is defined inside of the constructor's scope before the initializers
are run. In the above example, there would be no ReferenceError
under the semantics in this patch.
Thanks to Caitlin Potter, Kevin Gibbons and Jordan Harband for
contributing to the discussion that led to this change.