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

Side by Side Diff: src/ast.cc

Issue 798243004: ES6 computed property names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Disable test on windows 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 unified diff | Download patch
« no previous file with comments | « src/ast.h ('k') | src/ast-numbering.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ast.h" 5 #include "src/ast.h"
6 6
7 #include <cmath> // For isfinite. 7 #include <cmath> // For isfinite.
8 #include "src/builtins.h" 8 #include "src/builtins.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/contexts.h" 10 #include "src/contexts.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 shared_info_ = Handle<SharedFunctionInfo>(shared); 178 shared_info_ = Handle<SharedFunctionInfo>(shared);
179 break; 179 break;
180 } 180 }
181 } 181 }
182 } 182 }
183 } 183 }
184 184
185 185
186 ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone, 186 ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone,
187 AstValueFactory* ast_value_factory, 187 AstValueFactory* ast_value_factory,
188 Literal* key, Expression* value, 188 Expression* key, Expression* value,
189 bool is_static) { 189 bool is_static,
190 emit_store_ = true; 190 bool is_computed_name)
191 key_ = key; 191 : key_(key),
192 value_ = value; 192 value_(value),
193 is_static_ = is_static; 193 emit_store_(true),
194 if (key->raw_value()->EqualsString(ast_value_factory->proto_string())) { 194 is_static_(is_static),
195 is_computed_name_(is_computed_name) {
196 if (!is_computed_name &&
197 key->AsLiteral()->raw_value()->EqualsString(
198 ast_value_factory->proto_string())) {
195 kind_ = PROTOTYPE; 199 kind_ = PROTOTYPE;
196 } else if (value_->AsMaterializedLiteral() != NULL) { 200 } else if (value_->AsMaterializedLiteral() != NULL) {
197 kind_ = MATERIALIZED_LITERAL; 201 kind_ = MATERIALIZED_LITERAL;
198 } else if (value_->IsLiteral()) { 202 } else if (value_->IsLiteral()) {
199 kind_ = CONSTANT; 203 kind_ = CONSTANT;
200 } else { 204 } else {
201 kind_ = COMPUTED; 205 kind_ = COMPUTED;
202 } 206 }
203 } 207 }
204 208
205 209
206 ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone, bool is_getter, 210 ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone, bool is_getter,
211 Expression* key,
207 FunctionLiteral* value, 212 FunctionLiteral* value,
208 bool is_static) { 213 bool is_static,
209 emit_store_ = true; 214 bool is_computed_name)
210 value_ = value; 215 : key_(key),
211 kind_ = is_getter ? GETTER : SETTER; 216 value_(value),
212 is_static_ = is_static; 217 kind_(is_getter ? GETTER : SETTER),
213 } 218 emit_store_(true),
219 is_static_(is_static),
220 is_computed_name_(is_computed_name) {}
214 221
215 222
216 bool ObjectLiteral::Property::IsCompileTimeValue() { 223 bool ObjectLiteral::Property::IsCompileTimeValue() {
217 return kind_ == CONSTANT || 224 return kind_ == CONSTANT ||
218 (kind_ == MATERIALIZED_LITERAL && 225 (kind_ == MATERIALIZED_LITERAL &&
219 CompileTimeValue::IsCompileTimeValue(value_)); 226 CompileTimeValue::IsCompileTimeValue(value_));
220 } 227 }
221 228
222 229
223 void ObjectLiteral::Property::set_emit_store(bool emit_store) { 230 void ObjectLiteral::Property::set_emit_store(bool emit_store) {
224 emit_store_ = emit_store; 231 emit_store_ = emit_store;
225 } 232 }
226 233
227 234
228 bool ObjectLiteral::Property::emit_store() { 235 bool ObjectLiteral::Property::emit_store() {
229 return emit_store_; 236 return emit_store_;
230 } 237 }
231 238
232 239
233 void ObjectLiteral::CalculateEmitStore(Zone* zone) { 240 void ObjectLiteral::CalculateEmitStore(Zone* zone) {
234 ZoneAllocationPolicy allocator(zone); 241 ZoneAllocationPolicy allocator(zone);
235 242
236 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, 243 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity,
237 allocator); 244 allocator);
238 for (int i = properties()->length() - 1; i >= 0; i--) { 245 for (int i = properties()->length() - 1; i >= 0; i--) {
239 ObjectLiteral::Property* property = properties()->at(i); 246 ObjectLiteral::Property* property = properties()->at(i);
240 Literal* literal = property->key(); 247 if (property->is_computed_name()) continue;
248 Literal* literal = property->key()->AsLiteral();
241 if (literal->value()->IsNull()) continue; 249 if (literal->value()->IsNull()) continue;
242 uint32_t hash = literal->Hash(); 250 uint32_t hash = literal->Hash();
243 // If the key of a computed property is in the table, do not emit 251 // If the key of a computed property value is in the table, do not emit
244 // a store for the property later. 252 // a store for the property later.
245 if ((property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL || 253 if ((property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL ||
246 property->kind() == ObjectLiteral::Property::COMPUTED) && 254 property->kind() == ObjectLiteral::Property::COMPUTED) &&
247 table.Lookup(literal, hash, false, allocator) != NULL) { 255 table.Lookup(literal, hash, false, allocator) != NULL) {
248 property->set_emit_store(false); 256 property->set_emit_store(false);
249 } else { 257 } else {
250 // Add key to the table. 258 // Add key to the table.
251 table.Lookup(literal, hash, true, allocator); 259 table.Lookup(literal, hash, true, allocator);
252 } 260 }
253 } 261 }
(...skipping 18 matching lines...) Expand all
272 bool is_simple = true; 280 bool is_simple = true;
273 int depth_acc = 1; 281 int depth_acc = 1;
274 uint32_t max_element_index = 0; 282 uint32_t max_element_index = 0;
275 uint32_t elements = 0; 283 uint32_t elements = 0;
276 for (int i = 0; i < properties()->length(); i++) { 284 for (int i = 0; i < properties()->length(); i++) {
277 ObjectLiteral::Property* property = properties()->at(i); 285 ObjectLiteral::Property* property = properties()->at(i);
278 if (!IsBoilerplateProperty(property)) { 286 if (!IsBoilerplateProperty(property)) {
279 is_simple = false; 287 is_simple = false;
280 continue; 288 continue;
281 } 289 }
290
291 if (position == boilerplate_properties_ * 2) {
292 DCHECK(property->is_computed_name());
293 break;
294 }
295 DCHECK(!property->is_computed_name());
296
282 MaterializedLiteral* m_literal = property->value()->AsMaterializedLiteral(); 297 MaterializedLiteral* m_literal = property->value()->AsMaterializedLiteral();
283 if (m_literal != NULL) { 298 if (m_literal != NULL) {
284 m_literal->BuildConstants(isolate); 299 m_literal->BuildConstants(isolate);
285 if (m_literal->depth() >= depth_acc) depth_acc = m_literal->depth() + 1; 300 if (m_literal->depth() >= depth_acc) depth_acc = m_literal->depth() + 1;
286 } 301 }
287 302
288 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined 303 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined
289 // value for COMPUTED properties, the real value is filled in at 304 // value for COMPUTED properties, the real value is filled in at
290 // runtime. The enumeration order is maintained. 305 // runtime. The enumeration order is maintained.
291 Handle<Object> key = property->key()->value(); 306 Handle<Object> key = property->key()->AsLiteral()->value();
292 Handle<Object> value = GetBoilerplateValue(property->value(), isolate); 307 Handle<Object> value = GetBoilerplateValue(property->value(), isolate);
293 308
294 // Ensure objects that may, at any point in time, contain fields with double 309 // Ensure objects that may, at any point in time, contain fields with double
295 // representation are always treated as nested objects. This is true for 310 // representation are always treated as nested objects. This is true for
296 // computed fields (value is undefined), and smi and double literals 311 // computed fields (value is undefined), and smi and double literals
297 // (value->IsNumber()). 312 // (value->IsNumber()).
298 // TODO(verwaest): Remove once we can store them inline. 313 // TODO(verwaest): Remove once we can store them inline.
299 if (FLAG_track_double_fields && 314 if (FLAG_track_double_fields &&
300 (value->IsNumber() || value->IsUninitialized())) { 315 (value->IsNumber() || value->IsUninitialized())) {
301 may_store_doubles_ = true; 316 may_store_doubles_ = true;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 allocation_site_ = 648 allocation_site_ =
634 oracle->GetCallNewAllocationSite(allocation_site_feedback_slot); 649 oracle->GetCallNewAllocationSite(allocation_site_feedback_slot);
635 is_monomorphic_ = oracle->CallNewIsMonomorphic(CallNewFeedbackSlot()); 650 is_monomorphic_ = oracle->CallNewIsMonomorphic(CallNewFeedbackSlot());
636 if (is_monomorphic_) { 651 if (is_monomorphic_) {
637 target_ = oracle->GetCallNewTarget(CallNewFeedbackSlot()); 652 target_ = oracle->GetCallNewTarget(CallNewFeedbackSlot());
638 } 653 }
639 } 654 }
640 655
641 656
642 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { 657 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) {
643 TypeFeedbackId id = key()->LiteralFeedbackId(); 658 DCHECK(!is_computed_name());
659 TypeFeedbackId id = key()->AsLiteral()->LiteralFeedbackId();
644 SmallMapList maps; 660 SmallMapList maps;
645 oracle->CollectReceiverTypes(id, &maps); 661 oracle->CollectReceiverTypes(id, &maps);
646 receiver_type_ = maps.length() == 1 ? maps.at(0) 662 receiver_type_ = maps.length() == 1 ? maps.at(0)
647 : Handle<Map>::null(); 663 : Handle<Map>::null();
648 } 664 }
649 665
650 666
651 // ---------------------------------------------------------------------------- 667 // ----------------------------------------------------------------------------
652 // Implementation of AstVisitor 668 // Implementation of AstVisitor
653 669
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 // static 1042 // static
1027 bool Literal::Match(void* literal1, void* literal2) { 1043 bool Literal::Match(void* literal1, void* literal2) {
1028 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); 1044 const AstValue* x = static_cast<Literal*>(literal1)->raw_value();
1029 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); 1045 const AstValue* y = static_cast<Literal*>(literal2)->raw_value();
1030 return (x->IsString() && y->IsString() && *x->AsString() == *y->AsString()) || 1046 return (x->IsString() && y->IsString() && *x->AsString() == *y->AsString()) ||
1031 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); 1047 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber());
1032 } 1048 }
1033 1049
1034 1050
1035 } } // namespace v8::internal 1051 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/ast-numbering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698