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

Unified Diff: src/interpreter/bytecode-generator.cc

Issue 2330473002: Class fields, part 3 (backends)
Patch Set: bytecode test Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/full-codegen/x87/full-codegen-x87.cc ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index 53ef7d95ff187ea6dd69dd4775f526c23d788ba3..cd566c3acbf9f43f52d9cf09ed152efeffce76ca 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -1492,6 +1492,21 @@ void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) {
.LoadNamedProperty(literal, prototype_string(), feedback_index(slot))
.StoreAccumulatorInRegister(prototype);
+ // The below proxy exists to allow static field initializers to have the
+ // correct home object and receiver. It's only necessary if the initializers
+ // are called as a part of class definition instead of immediately after it,
+ // in which case they could simply refer to the class just constructed. The
+ // latter is actually what's currently specified, and this will need to be
+ // changed if that behavior is settled upon. See also
+ // https://github.com/tc39/proposal-class-public-fields/issues/50
+ VariableProxy* static_initializer_proxy = expr->static_initializer_proxy();
+ if (static_initializer_proxy != nullptr) {
+ Variable* variable = static_initializer_proxy->var();
+ builder()->LoadAccumulatorWithRegister(literal);
+ VisitVariableAssignment(variable, Token::INIT,
+ FeedbackVectorSlot::Invalid());
+ }
+
VisitClassLiteralProperties(expr, literal, prototype);
builder()->CallRuntime(Runtime::kToFastProperties, literal, 1);
// Assign to class variable.
@@ -1546,6 +1561,29 @@ void BytecodeGenerator::VisitClassLiteralProperties(ClassLiteral* expr,
for (int i = 0; i < expr->properties()->length(); i++) {
ClassLiteral::Property* property = expr->properties()->at(i);
+ if (property->kind() == ClassLiteral::Property::FIELD &&
+ !property->is_static()) {
+ // Non-static properties produced by the parser have as their 'key' an
+ // expression producing their name and as their 'value' a variable which
+ // is refered to by the synthetic initializer function in order to
+ // determine the name during class instantiation. This is necessary
+ // because computed names must only be evaluated once, at class definition
+ // time.
+ // That is, code which looks like `class C { [f()] = 1; }` is desugared
+ // into something like
+ // class C { constructor(){ this.[.class-field-0-name] = 1; } };
+ // let .class-field-0-name = f();
+ // except that the assignment to .class-field-name-0 occurs interleaved
+ // with the rest of the class body; it is performed by the block in which
+ // this comment appears.
+ DCHECK(property->value()->IsVariableProxy());
+ Variable* variable = property->value()->AsVariableProxy()->var();
+ VisitForAccumulatorValue(property->key());
+ VisitVariableAssignment(variable, Token::INIT,
+ FeedbackVectorSlot::Invalid());
+ continue;
+ }
+
// Set-up receiver.
Register new_receiver = property->is_static() ? literal : prototype;
if (new_receiver != old_receiver) {
@@ -1594,7 +1632,12 @@ void BytecodeGenerator::VisitClassLiteralProperties(ClassLiteral* expr,
break;
}
case ClassLiteral::Property::FIELD: {
- UNREACHABLE();
+ DCHECK(property->is_static());
+ builder()
+ ->LoadLiteral(Smi::FromInt(property->NeedsSetFunctionName()))
+ .StoreAccumulatorInRegister(set_function_name);
+ builder()->CallRuntime(Runtime::kDefineDataPropertyInLiteral, receiver,
+ 5);
break;
}
}
« no previous file with comments | « src/full-codegen/x87/full-codegen-x87.cc ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698