| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); | 176 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); |
| 177 if (shared->start_position() == start_position()) { | 177 if (shared->start_position() == start_position()) { |
| 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(Expression* key, Expression* value, |
| 187 AstValueFactory* ast_value_factory, | 187 Kind kind, bool is_static, |
| 188 bool is_computed_name) |
| 189 : key_(key), |
| 190 value_(value), |
| 191 kind_(kind), |
| 192 emit_store_(true), |
| 193 is_static_(is_static), |
| 194 is_computed_name_(is_computed_name) {} |
| 195 |
| 196 |
| 197 ObjectLiteralProperty::ObjectLiteralProperty(AstValueFactory* ast_value_factory, |
| 188 Expression* key, Expression* value, | 198 Expression* key, Expression* value, |
| 189 bool is_static, | 199 bool is_static, |
| 190 bool is_computed_name) | 200 bool is_computed_name) |
| 191 : key_(key), | 201 : key_(key), |
| 192 value_(value), | 202 value_(value), |
| 193 emit_store_(true), | 203 emit_store_(true), |
| 194 is_static_(is_static), | 204 is_static_(is_static), |
| 195 is_computed_name_(is_computed_name) { | 205 is_computed_name_(is_computed_name) { |
| 196 if (!is_computed_name && | 206 if (!is_computed_name && |
| 197 key->AsLiteral()->raw_value()->EqualsString( | 207 key->AsLiteral()->raw_value()->EqualsString( |
| 198 ast_value_factory->proto_string())) { | 208 ast_value_factory->proto_string())) { |
| 199 kind_ = PROTOTYPE; | 209 kind_ = PROTOTYPE; |
| 200 } else if (value_->AsMaterializedLiteral() != NULL) { | 210 } else if (value_->AsMaterializedLiteral() != NULL) { |
| 201 kind_ = MATERIALIZED_LITERAL; | 211 kind_ = MATERIALIZED_LITERAL; |
| 202 } else if (value_->IsLiteral()) { | 212 } else if (value_->IsLiteral()) { |
| 203 kind_ = CONSTANT; | 213 kind_ = CONSTANT; |
| 204 } else { | 214 } else { |
| 205 kind_ = COMPUTED; | 215 kind_ = COMPUTED; |
| 206 } | 216 } |
| 207 } | 217 } |
| 208 | 218 |
| 209 | 219 |
| 210 ObjectLiteralProperty::ObjectLiteralProperty(Zone* zone, bool is_getter, | |
| 211 Expression* key, | |
| 212 FunctionLiteral* value, | |
| 213 bool is_static, | |
| 214 bool is_computed_name) | |
| 215 : key_(key), | |
| 216 value_(value), | |
| 217 kind_(is_getter ? GETTER : SETTER), | |
| 218 emit_store_(true), | |
| 219 is_static_(is_static), | |
| 220 is_computed_name_(is_computed_name) {} | |
| 221 | |
| 222 | |
| 223 bool ObjectLiteral::Property::IsCompileTimeValue() { | 220 bool ObjectLiteral::Property::IsCompileTimeValue() { |
| 224 return kind_ == CONSTANT || | 221 return kind_ == CONSTANT || |
| 225 (kind_ == MATERIALIZED_LITERAL && | 222 (kind_ == MATERIALIZED_LITERAL && |
| 226 CompileTimeValue::IsCompileTimeValue(value_)); | 223 CompileTimeValue::IsCompileTimeValue(value_)); |
| 227 } | 224 } |
| 228 | 225 |
| 229 | 226 |
| 230 void ObjectLiteral::Property::set_emit_store(bool emit_store) { | 227 void ObjectLiteral::Property::set_emit_store(bool emit_store) { |
| 231 emit_store_ = emit_store; | 228 emit_store_ = emit_store; |
| 232 } | 229 } |
| 233 | 230 |
| 234 | 231 |
| 235 bool ObjectLiteral::Property::emit_store() { | 232 bool ObjectLiteral::Property::emit_store() { |
| 236 return emit_store_; | 233 return emit_store_; |
| 237 } | 234 } |
| 238 | 235 |
| 239 | 236 |
| 240 void ObjectLiteral::CalculateEmitStore(Zone* zone) { | 237 void ObjectLiteral::CalculateEmitStore(Zone* zone) { |
| 241 ZoneAllocationPolicy allocator(zone); | 238 ZoneAllocationPolicy allocator(zone); |
| 242 | 239 |
| 243 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, | 240 ZoneHashMap table(Literal::Match, ZoneHashMap::kDefaultHashMapCapacity, |
| 244 allocator); | 241 allocator); |
| 242 bool seen_prototype = false; |
| 245 for (int i = properties()->length() - 1; i >= 0; i--) { | 243 for (int i = properties()->length() - 1; i >= 0; i--) { |
| 246 ObjectLiteral::Property* property = properties()->at(i); | 244 ObjectLiteral::Property* property = properties()->at(i); |
| 247 if (property->is_computed_name()) continue; | 245 if (property->is_computed_name()) continue; |
| 248 Literal* literal = property->key()->AsLiteral(); | 246 Literal* literal = property->key()->AsLiteral(); |
| 249 if (literal->value()->IsNull()) continue; | 247 if (literal->value()->IsNull()) continue; |
| 250 uint32_t hash = literal->Hash(); | 248 uint32_t hash = literal->Hash(); |
| 251 // If the key of a computed property value is in the table, do not emit | 249 // If the key of a computed property value is in the table, do not emit |
| 252 // a store for the property later. | 250 // a store for the property later. |
| 253 if ((property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL || | 251 if ((property->kind() == ObjectLiteral::Property::MATERIALIZED_LITERAL || |
| 254 property->kind() == ObjectLiteral::Property::COMPUTED) && | 252 property->kind() == ObjectLiteral::Property::COMPUTED) && |
| 255 table.Lookup(literal, hash, false, allocator) != NULL) { | 253 table.Lookup(literal, hash, false, allocator) != NULL) { |
| 256 property->set_emit_store(false); | 254 property->set_emit_store(false); |
| 255 } else if (property->kind() == ObjectLiteral::Property::PROTOTYPE) { |
| 256 // Only emit a store for the last prototype property. Make sure we do not |
| 257 // clobber the "__proto__" name for instance properties (using method or |
| 258 // literal shorthand syntax). |
| 259 property->set_emit_store(!seen_prototype); |
| 260 seen_prototype = true; |
| 257 } else { | 261 } else { |
| 258 // Add key to the table. | 262 // Add key to the table. |
| 259 table.Lookup(literal, hash, true, allocator); | 263 table.Lookup(literal, hash, true, allocator); |
| 260 } | 264 } |
| 261 } | 265 } |
| 262 } | 266 } |
| 263 | 267 |
| 264 | 268 |
| 265 bool ObjectLiteral::IsBoilerplateProperty(ObjectLiteral::Property* property) { | 269 bool ObjectLiteral::IsBoilerplateProperty(ObjectLiteral::Property* property) { |
| 266 return property != NULL && | 270 return property != NULL && |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 // static | 1036 // static |
| 1033 bool Literal::Match(void* literal1, void* literal2) { | 1037 bool Literal::Match(void* literal1, void* literal2) { |
| 1034 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); | 1038 const AstValue* x = static_cast<Literal*>(literal1)->raw_value(); |
| 1035 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); | 1039 const AstValue* y = static_cast<Literal*>(literal2)->raw_value(); |
| 1036 return (x->IsString() && y->IsString() && *x->AsString() == *y->AsString()) || | 1040 return (x->IsString() && y->IsString() && *x->AsString() == *y->AsString()) || |
| 1037 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); | 1041 (x->IsNumber() && y->IsNumber() && x->AsNumber() == y->AsNumber()); |
| 1038 } | 1042 } |
| 1039 | 1043 |
| 1040 | 1044 |
| 1041 } } // namespace v8::internal | 1045 } } // namespace v8::internal |
| OLD | NEW |