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

Unified Diff: src/ast.cc

Issue 858673002: Fix issue with __proto__ when using ES6 object literals (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: git rebase Created 5 years, 11 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/ast.h ('k') | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast.cc
diff --git a/src/ast.cc b/src/ast.cc
index 1e1e22482149547f2abca554f7bb502d6f17242c..7369e75ea1558c7d5b5d2a692b97d2f263ecd5c7 100644
--- a/src/ast.cc
+++ b/src/ast.cc
@@ -183,8 +183,18 @@ void FunctionLiteral::InitializeSharedInfo(
}
-ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone,
- AstValueFactory* ast_value_factory,
+ObjectLiteralProperty::ObjectLiteralProperty(Expression* key, Expression* value,
+ Kind kind, bool is_static,
+ bool is_computed_name)
+ : key_(key),
+ value_(value),
+ kind_(kind),
+ emit_store_(true),
+ is_static_(is_static),
+ is_computed_name_(is_computed_name) {}
+
+
+ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory,
Expression* key, Expression* value,
bool is_static,
bool is_computed_name)
@@ -207,19 +217,6 @@ ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone,
}
-ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone, bool is_getter,
- Expression* key,
- FunctionLiteral* value,
- 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() {
return kind_ == CONSTANT ||
(kind_ == MATERIALIZED_LITERAL &&
@@ -242,6 +239,7 @@ void ObjectLiteral::CalculateEmitStore(Zone* zone) {
ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity,
allocator);
+ bool seen_prototype = false;
for (int i = properties()->length() - 1; i >= 0; i--) {
ObjectLiteral::Property* property = properties()->at(i);
if (property->is_computed_name()) continue;
@@ -254,6 +252,12 @@ void ObjectLiteral::CalculateEmitStore(Zone* zone) {
property->kind() == ObjectLiteral::Property::COMPUTED) &&
table.Lookup(literal, hash, false, allocator) != NULL) {
property->set_emit_store(false);
+ } else if (property->kind() == ObjectLiteral::Property::PROTOTYPE) {
+ // Only emit a store for the last prototype property. Make sure we do not
+ // clobber the "__proto__" name for instance properties (using method or
+ // literal shorthand syntax).
+ property->set_emit_store(!seen_prototype);
+ seen_prototype = true;
} else {
// Add key to the table.
table.Lookup(literal, hash, true, allocator);
« no previous file with comments | « src/ast.h ('k') | src/compiler/ast-graph-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698