Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(817)

Issue 2329703002: Private fields

Created:
4 years, 3 months ago by bakkot
Modified:
4 years, 3 months ago
Reviewers:
Dan Ehrenberg, adamk
CC:
Michael Hablich, rmcilroy, v8-reviews_googlegroups.com
Target Ref:
refs/pending/heads/master
Project:
v8
Visibility:
Public.

Description

[language] Private fields A WIP implementation of a stage-1 proposal to add private fields to JS classes. The proposal is at https://github.com/tc39/proposal-private-fields Not all errors are implemented, but the remaining semantics are. See design doc for details: https://docs.google.com/document/d/1WRtNm3ZLNJT1WVr8aq4RJuByYgfuAFAhj20LwTW6JVE/edit?ts=57db03c2# The feature is staged behind --harmony-private-class-fields The implementation is purely in the parser plus a single runtime function. Code like `this.#x` is desugared into approximately `this[#x]`, where `#x` is the name of a variable in the class's scope which holds a private symbol. Initialization is performed via the same mechanism as public fields. BUG=v8:5368

Patch Set 1 #

Total comments: 21

Patch Set 2 : comments #

Total comments: 2

Patch Set 3 : proxy support and test #

Total comments: 9

Patch Set 4 : rebase #

Patch Set 5 : use ConcatString #

Patch Set 6 : some comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+709 lines, -31 lines) Patch
M src/ast/ast-value-factory.h View 1 2 3 4 1 chunk +1 line, -0 lines 0 comments Download
M src/bootstrapper.cc View 2 chunks +2 lines, -0 lines 0 comments Download
M src/flag-definitions.h View 1 chunk +2 lines, -1 line 0 comments Download
M src/messages.h View 1 chunk +1 line, -0 lines 0 comments Download
M src/parsing/parser.h View 1 chunk +1 line, -0 lines 0 comments Download
M src/parsing/parser.cc View 1 2 3 4 12 chunks +164 lines, -9 lines 0 comments Download
M src/parsing/parser-base.h View 1 2 3 9 chunks +38 lines, -8 lines 0 comments Download
M src/parsing/preparser.h View 1 chunk +1 line, -0 lines 0 comments Download
M src/parsing/preparser.cc View 1 2 2 chunks +13 lines, -2 lines 0 comments Download
M src/parsing/scanner.cc View 4 chunks +7 lines, -2 lines 0 comments Download
M src/parsing/token.h View 1 chunk +1 line, -0 lines 0 comments Download
M src/runtime/runtime.h View 1 2 3 1 chunk +1 line, -0 lines 0 comments Download
M src/runtime/runtime-classes.cc View 1 2 3 4 5 1 chunk +21 lines, -0 lines 0 comments Download
M test/cctest/interpreter/bytecode_expectations/ForOf.golden View 4 chunks +4 lines, -4 lines 0 comments Download
M test/cctest/interpreter/bytecode_expectations/Generators.golden View 1 chunk +1 line, -1 line 0 comments Download
M test/cctest/test-parsing.cc View 1 2 3 chunks +99 lines, -0 lines 0 comments Download
A + test/mjsunit/harmony/class-privates-delete.js View 1 chunk +6 lines, -4 lines 0 comments Download
A test/mjsunit/harmony/class-privates-errors.js View 1 2 1 chunk +53 lines, -0 lines 0 comments Download
A test/mjsunit/harmony/class-privates-evaluation-order.js View 1 1 chunk +50 lines, -0 lines 0 comments Download
A test/mjsunit/harmony/class-privates-proxy.js View 1 2 1 chunk +36 lines, -0 lines 0 comments Download
A test/mjsunit/harmony/class-privates-scoping.js View 1 chunk +114 lines, -0 lines 0 comments Download
A test/mjsunit/harmony/class-privates-visibility.js View 1 chunk +93 lines, -0 lines 0 comments Download

Depends on Patchset:

Messages

Total messages: 17 (11 generated)
bakkot
PTAL after class fields. This patch still needs parser tests, but should otherwise be approximately ...
4 years, 3 months ago (2016-09-10 00:25:39 UTC) #2
Dan Ehrenberg
A good start. Does this make sure to throw if the same private field is ...
4 years, 3 months ago (2016-09-10 04:30:29 UTC) #3
bakkot
Addressed some of the comments; I'll address the rest when I add more tests. https://codereview.chromium.org/2329703002/diff/1/src/flag-definitions.h ...
4 years, 3 months ago (2016-09-13 01:05:38 UTC) #4
bakkot
> Does this make sure to throw if the same private field is added to ...
4 years, 3 months ago (2016-09-13 22:05:04 UTC) #5
Dan Ehrenberg
https://codereview.chromium.org/2329703002/diff/20001/src/parsing/parser.cc File src/parsing/parser.cc (right): https://codereview.chromium.org/2329703002/diff/20001/src/parsing/parser.cc#newcode3376 src/parsing/parser.cc:3376: // doesn't matter I'm looking forward to your fix ...
4 years, 3 months ago (2016-09-15 21:26:58 UTC) #10
bakkot
4 years, 3 months ago (2016-09-17 00:11:11 UTC) #11
https://codereview.chromium.org/2329703002/diff/20001/src/parsing/parser.cc
File src/parsing/parser.cc (right):

https://codereview.chromium.org/2329703002/diff/20001/src/parsing/parser.cc#n...
src/parsing/parser.cc:3376: // doesn't matter
On 2016/09/15 at 21:26:58, Dan Ehrenberg wrote:
> I'm looking forward to your fix here.

Done.

https://codereview.chromium.org/2329703002/diff/40001/src/runtime/runtime-cla...
File src/runtime/runtime-classes.cc (right):

https://codereview.chromium.org/2329703002/diff/40001/src/runtime/runtime-cla...
src/runtime/runtime-classes.cc:78:
RUNTIME_FUNCTION(Runtime_ThrowIfMissingPrivateField) {
On 2016/09/15 at 21:26:58, Dan Ehrenberg wrote:
> It'd be nice to have a comment somewhere explaining that this runtime function
needs to return the object because it may be used as an LHS

Done.

https://codereview.chromium.org/2329703002/diff/40001/src/runtime/runtime-cla...
src/runtime/runtime-classes.cc:86: // proxy trap
On 2016/09/15 at 21:26:58, Dan Ehrenberg wrote:
> TODO can be rephrased to say that it in fact doesn't.
> 
> Maybe add a DCHECK to ensure that the Name is a private symbol, though.

Done.

https://codereview.chromium.org/2329703002/diff/40001/src/runtime/runtime-obj...
File src/runtime/runtime-object.cc (right):

https://codereview.chromium.org/2329703002/diff/40001/src/runtime/runtime-obj...
src/runtime/runtime-object.cc:679: RUNTIME_FUNCTION(Runtime_DefineDataProperty)
{
On 2016/09/15 at 21:26:58, Dan Ehrenberg wrote:
> The change to DefineDataProperty, which works on Proxies, should be backported
to one of the earlier public properties patches. They can also end up running on
Proxies. It'd be nice to mention somewhere in this definition that the point of
splitting off from DefineDataPropertyInLiteral is to work on Proxies. Maybe,
rather than making a new runtime function, the prior one should just have that
small generalization applied to it; I bet it wouldn't be a big perf regression.

It has been; it got copied over here by accident. I'm going to leave it as two
functions for the moment.

Powered by Google App Engine
This is Rietveld 408576698