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

Unified Diff: src/ast.cc

Issue 807173002: ES6 computed property names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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
Index: src/ast.cc
diff --git a/src/ast.cc b/src/ast.cc
index 6329371faa5f01736b49d7f8686ad7f4ceaa373b..298cd23c5b992e9d8661223607bea7168f392a61 100644
--- a/src/ast.cc
+++ b/src/ast.cc
@@ -185,13 +185,17 @@ void FunctionLiteral::InitializeSharedInfo(
ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone,
AstValueFactory* ast_value_factory,
- Literal* key, Expression* value,
- bool is_static) {
- emit_store_ = true;
- key_ = key;
- value_ = value;
- is_static_ = is_static;
- if (key->raw_value()->EqualsString(ast_value_factory->proto_string())) {
+ Expression* key, Expression* value,
+ bool is_static,
+ bool is_computed_name)
+ : key_(key),
+ value_(value),
+ emit_store_(true),
+ is_static_(is_static),
+ is_computed_name_(is_computed_name) {
+ if (!is_computed_name &&
+ key->AsLiteral()->raw_value()->EqualsString(
+ ast_value_factory->proto_string())) {
kind_ = PROTOTYPE;
} else if (value_->AsMaterializedLiteral() != NULL) {
kind_ = MATERIALIZED_LITERAL;
@@ -204,13 +208,16 @@ ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone,
ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone, bool is_getter,
+ Expression* key,
FunctionLiteral* value,
- bool is_static) {
- emit_store_ = true;
- value_ = value;
- kind_ = is_getter ? GETTER : SETTER;
- is_static_ = is_static;
-}
+ bool is_static,
+ bool is_computed_name)
+ : key_(key),
+ value_(value),
+ kind_(is_getter ? GETTER : SETTER),
+ emit_store_(true),
+ is_static_(is_static),
+ is_computed_name_(is_computed_name) {}
bool ObjectLiteral::Property::IsCompileTimeValue() {
@@ -237,10 +244,11 @@ void ObjectLiteral::CalculateEmitStore(Zone* zone) {
allocator);
for (int i = properties()->length() - 1; i >= 0; i--) {
ObjectLiteral::Property* property = properties()->at(i);
- Literal* literal = property->key();
+ if (property->is_computed_name()) continue;
+ Literal* literal = property->key()->AsLiteral();
if (literal->value()->IsNull()) continue;
uint32_t hash = literal->Hash();
- // If the key of a computed property is in the table, do not emit
+ // If the key of a computed property value is in the table, do not emit
// a store for the property later.
if ((property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL ||
property->kind() == ObjectLiteral::Property::COMPUTED) &&
@@ -279,6 +287,13 @@ void ObjectLiteral::BuildConstantProperties(Isolate* isolate) {
is_simple = false;
continue;
}
+
+ if (position == boilerplate_properties_ * 2) {
+ DCHECK(property->is_computed_name());
+ break;
+ }
+ DCHECK(!property->is_computed_name());
+
MaterializedLiteral* m_literal = property->value()->AsMaterializedLiteral();
if (m_literal != NULL) {
m_literal->BuildConstants(isolate);
@@ -288,7 +303,7 @@ void ObjectLiteral::BuildConstantProperties(Isolate* isolate) {
// Add CONSTANT and COMPUTED properties to boilerplate. Use undefined
// value for COMPUTED properties, the real value is filled in at
// runtime. The enumeration order is maintained.
- Handle<Object> key = property->key()->value();
+ Handle<Object> key = property->key()->AsLiteral()->value();
Handle<Object> value = GetBoilerplateValue(property->value(), isolate);
// Ensure objects that may, at any point in time, contain fields with double
@@ -640,7 +655,8 @@ void CallNew::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
- TypeFeedbackId id = key()->LiteralFeedbackId();
+ DCHECK(!is_computed_name());
+ TypeFeedbackId id = key()->AsLiteral()->LiteralFeedbackId();
SmallMapList maps;
oracle->CollectReceiverTypes(id, &maps);
receiver_type_ = maps.length() == 1 ? maps.at(0)
« no previous file with comments | « src/ast.h ('k') | src/ast-numbering.cc » ('j') | src/ia32/full-codegen-ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698