| OLD | NEW |
| 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 Loading... |
| 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 Expression* key, Expression* value, | 188 Literal* key, Expression* value, |
| 189 bool is_static, | 189 bool is_static) { |
| 190 bool is_computed_name) | 190 emit_store_ = true; |
| 191 : key_(key), | 191 key_ = key; |
| 192 value_(value), | 192 value_ = value; |
| 193 emit_store_(true), | 193 is_static_ = is_static; |
| 194 is_static_(is_static), | 194 if (key->raw_value()->EqualsString(ast_value_factory->proto_string())) { |
| 195 is_computed_name_(is_computed_name) { | |
| 196 if (!is_computed_name && | |
| 197 key->AsLiteral()->raw_value()->EqualsString( | |
| 198 ast_value_factory->proto_string())) { | |
| 199 kind_ = PROTOTYPE; | 195 kind_ = PROTOTYPE; |
| 200 } else if (value_->AsMaterializedLiteral() != NULL) { | 196 } else if (value_->AsMaterializedLiteral() != NULL) { |
| 201 kind_ = MATERIALIZED_LITERAL; | 197 kind_ = MATERIALIZED_LITERAL; |
| 202 } else if (value_->IsLiteral()) { | 198 } else if (value_->IsLiteral()) { |
| 203 kind_ = CONSTANT; | 199 kind_ = CONSTANT; |
| 204 } else { | 200 } else { |
| 205 kind_ = COMPUTED; | 201 kind_ = COMPUTED; |
| 206 } | 202 } |
| 207 } | 203 } |
| 208 | 204 |
| 209 | 205 |
| 210 ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone, bool is_getter, | 206 ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone, bool is_getter, |
| 211 Expression* key, | |
| 212 FunctionLiteral* value, | 207 FunctionLiteral* value, |
| 213 bool is_static, | 208 bool is_static) { |
| 214 bool is_computed_name) | 209 emit_store_ = true; |
| 215 : key_(key), | 210 value_ = value; |
| 216 value_(value), | 211 kind_ = is_getter ? GETTER : SETTER; |
| 217 kind_(is_getter ? GETTER : SETTER), | 212 is_static_ = is_static; |
| 218 emit_store_(true), | 213 } |
| 219 is_static_(is_static), | |
| 220 is_computed_name_(is_computed_name) {} | |
| 221 | 214 |
| 222 | 215 |
| 223 bool ObjectLiteral::Property::IsCompileTimeValue() { | 216 bool ObjectLiteral::Property::IsCompileTimeValue() { |
| 224 return kind_ == CONSTANT || | 217 return kind_ == CONSTANT || |
| 225 (kind_ == MATERIALIZED_LITERAL && | 218 (kind_ == MATERIALIZED_LITERAL && |
| 226 CompileTimeValue::IsCompileTimeValue(value_)); | 219 CompileTimeValue::IsCompileTimeValue(value_)); |
| 227 } | 220 } |
| 228 | 221 |
| 229 | 222 |
| 230 void ObjectLiteral::Property::set_emit_store(bool emit_store) { | 223 void ObjectLiteral::Property::set_emit_store(bool emit_store) { |
| 231 emit_store_ = emit_store; | 224 emit_store_ = emit_store; |
| 232 } | 225 } |
| 233 | 226 |
| 234 | 227 |
| 235 bool ObjectLiteral::Property::emit_store() { | 228 bool ObjectLiteral::Property::emit_store() { |
| 236 return emit_store_; | 229 return emit_store_; |
| 237 } | 230 } |
| 238 | 231 |
| 239 | 232 |
| 240 void ObjectLiteral::CalculateEmitStore(Zone* zone) { | 233 void ObjectLiteral::CalculateEmitStore(Zone* zone) { |
| 241 ZoneAllocationPolicy allocator(zone); | 234 ZoneAllocationPolicy allocator(zone); |
| 242 | 235 |
| 243 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, | 236 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, |
| 244 allocator); | 237 allocator); |
| 245 for (int i = properties()->length() - 1; i >= 0; i--) { | 238 for (int i = properties()->length() - 1; i >= 0; i--) { |
| 246 ObjectLiteral::Property* property = properties()->at(i); | 239 ObjectLiteral::Property* property = properties()->at(i); |
| 247 if (property->is_computed_name()) continue; | 240 Literal* literal = property->key(); |
| 248 Literal* literal = property->key()->AsLiteral(); | |
| 249 if (literal->value()->IsNull()) continue; | 241 if (literal->value()->IsNull()) continue; |
| 250 uint32_t hash = literal->Hash(); | 242 uint32_t hash = literal->Hash(); |
| 251 // If the key of a computed property value is in the table, do not emit | 243 // If the key of a computed property is in the table, do not emit |
| 252 // a store for the property later. | 244 // a store for the property later. |
| 253 if ((property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL || | 245 if ((property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL || |
| 254 property->kind() == ObjectLiteral::Property::COMPUTED) && | 246 property->kind() == ObjectLiteral::Property::COMPUTED) && |
| 255 table.Lookup(literal, hash, false, allocator) != NULL) { | 247 table.Lookup(literal, hash, false, allocator) != NULL) { |
| 256 property->set_emit_store(false); | 248 property->set_emit_store(false); |
| 257 } else { | 249 } else { |
| 258 // Add key to the table. | 250 // Add key to the table. |
| 259 table.Lookup(literal, hash, true, allocator); | 251 table.Lookup(literal, hash, true, allocator); |
| 260 } | 252 } |
| 261 } | 253 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 280 bool is_simple = true; | 272 bool is_simple = true; |
| 281 int depth_acc = 1; | 273 int depth_acc = 1; |
| 282 uint32_t max_element_index = 0; | 274 uint32_t max_element_index = 0; |
| 283 uint32_t elements = 0; | 275 uint32_t elements = 0; |
| 284 for (int i = 0; i < properties()->length(); i++) { | 276 for (int i = 0; i < properties()->length(); i++) { |
| 285 ObjectLiteral::Property* property = properties()->at(i); | 277 ObjectLiteral::Property* property = properties()->at(i); |
| 286 if (!IsBoilerplateProperty(property)) { | 278 if (!IsBoilerplateProperty(property)) { |
| 287 is_simple = false; | 279 is_simple = false; |
| 288 continue; | 280 continue; |
| 289 } | 281 } |
| 290 | |
| 291 if (position == boilerplate_properties_ * 2) { | |
| 292 DCHECK(property->is_computed_name()); | |
| 293 break; | |
| 294 } | |
| 295 DCHECK(!property->is_computed_name()); | |
| 296 | |
| 297 MaterializedLiteral* m_literal = property->value()->AsMaterializedLiteral(); | 282 MaterializedLiteral* m_literal = property->value()->AsMaterializedLiteral(); |
| 298 if (m_literal != NULL) { | 283 if (m_literal != NULL) { |
| 299 m_literal->BuildConstants(isolate); | 284 m_literal->BuildConstants(isolate); |
| 300 if (m_literal->depth() >= depth_acc) depth_acc = m_literal->depth() + 1; | 285 if (m_literal->depth() >= depth_acc) depth_acc = m_literal->depth() + 1; |
| 301 } | 286 } |
| 302 | 287 |
| 303 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined | 288 // Add CONSTANT and COMPUTED properties to boilerplate. Use undefined |
| 304 // value for COMPUTED properties, the real value is filled in at | 289 // value for COMPUTED properties, the real value is filled in at |
| 305 // runtime. The enumeration order is maintained. | 290 // runtime. The enumeration order is maintained. |
| 306 Handle<Object> key = property->key()->AsLiteral()->value(); | 291 Handle<Object> key = property->key()->value(); |
| 307 Handle<Object> value = GetBoilerplateValue(property->value(), isolate); | 292 Handle<Object> value = GetBoilerplateValue(property->value(), isolate); |
| 308 | 293 |
| 309 // Ensure objects that may, at any point in time, contain fields with double | 294 // Ensure objects that may, at any point in time, contain fields with double |
| 310 // representation are always treated as nested objects. This is true for | 295 // representation are always treated as nested objects. This is true for |
| 311 // computed fields (value is undefined), and smi and double literals | 296 // computed fields (value is undefined), and smi and double literals |
| 312 // (value->IsNumber()). | 297 // (value->IsNumber()). |
| 313 // TODO(verwaest): Remove once we can store them inline. | 298 // TODO(verwaest): Remove once we can store them inline. |
| 314 if (FLAG_track_double_fields && | 299 if (FLAG_track_double_fields && |
| 315 (value->IsNumber() || value->IsUninitialized())) { | 300 (value->IsNumber() || value->IsUninitialized())) { |
| 316 may_store_doubles_ = true; | 301 may_store_doubles_ = true; |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 allocation_site_ = | 633 allocation_site_ = |
| 649 oracle->GetCallNewAllocationSite(allocation_site_feedback_slot); | 634 oracle->GetCallNewAllocationSite(allocation_site_feedback_slot); |
| 650 is_monomorphic_ = oracle->CallNewIsMonomorphic(CallNewFeedbackSlot()); | 635 is_monomorphic_ = oracle->CallNewIsMonomorphic(CallNewFeedbackSlot()); |
| 651 if (is_monomorphic_) { | 636 if (is_monomorphic_) { |
| 652 target_ = oracle->GetCallNewTarget(CallNewFeedbackSlot()); | 637 target_ = oracle->GetCallNewTarget(CallNewFeedbackSlot()); |
| 653 } | 638 } |
| 654 } | 639 } |
| 655 | 640 |
| 656 | 641 |
| 657 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { | 642 void ObjectLiteral::Property::RecordTypeFeedback(TypeFeedbackOracle* oracle) { |
| 658 DCHECK(!is_computed_name()); | 643 TypeFeedbackId id = key()->LiteralFeedbackId(); |
| 659 TypeFeedbackId id = key()->AsLiteral()->LiteralFeedbackId(); | |
| 660 SmallMapList maps; | 644 SmallMapList maps; |
| 661 oracle->CollectReceiverTypes(id, &maps); | 645 oracle->CollectReceiverTypes(id, &maps); |
| 662 receiver_type_ = maps.length() == 1 ? maps.at(0) | 646 receiver_type_ = maps.length() == 1 ? maps.at(0) |
| 663 : Handle<Map>::null(); | 647 : Handle<Map>::null(); |
| 664 } | 648 } |
| 665 | 649 |
| 666 | 650 |
| 667 // ---------------------------------------------------------------------------- | 651 // ---------------------------------------------------------------------------- |
| 668 // Implementation of AstVisitor | 652 // Implementation of AstVisitor |
| 669 | 653 |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 // static | 1026 // static |
| 1043 bool Literal::Match(void* literal1, void* literal2) { | 1027 bool Literal::Match(void* literal1, void* literal2) { |
| 1044 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 1028 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
| 1045 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 1029 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
| 1046 return (x->IsString() && y->IsString() && *x->AsString() == *y->AsString()) || | 1030 return (x->IsString() && y->IsString() && *x->AsString() == *y->AsString()) || |
| 1047 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 1031 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
| 1048 } | 1032 } |
| 1049 | 1033 |
| 1050 | 1034 |
| 1051 } } // namespace v8::internal | 1035 } } // namespace v8::internal |
| OLD | NEW |