OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 | 1409 |
1410 void JSObject::initialize_elements() { | 1410 void JSObject::initialize_elements() { |
1411 ASSERT(map()->has_fast_smi_or_object_elements() || | 1411 ASSERT(map()->has_fast_smi_or_object_elements() || |
1412 map()->has_fast_double_elements()); | 1412 map()->has_fast_double_elements()); |
1413 ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); | 1413 ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
1414 WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); | 1414 WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); |
1415 } | 1415 } |
1416 | 1416 |
1417 | 1417 |
1418 MaybeObject* JSObject::ResetElements() { | 1418 MaybeObject* JSObject::ResetElements() { |
1419 Object* obj; | 1419 if (map()->is_observed()) { |
| 1420 // Maintain invariant that observed elements are always in dictionary mode. |
| 1421 SeededNumberDictionary* dictionary; |
| 1422 MaybeObject* maybe = SeededNumberDictionary::Allocate(0); |
| 1423 if (!maybe->To(&dictionary)) return maybe; |
| 1424 if (map() == GetHeap()->non_strict_arguments_elements_map()) { |
| 1425 FixedArray::cast(elements())->set(1, dictionary); |
| 1426 } else { |
| 1427 set_elements(dictionary); |
| 1428 } |
| 1429 return this; |
| 1430 } |
| 1431 |
1420 ElementsKind elements_kind = GetInitialFastElementsKind(); | 1432 ElementsKind elements_kind = GetInitialFastElementsKind(); |
1421 if (!FLAG_smi_only_arrays) { | 1433 if (!FLAG_smi_only_arrays) { |
1422 elements_kind = FastSmiToObjectElementsKind(elements_kind); | 1434 elements_kind = FastSmiToObjectElementsKind(elements_kind); |
1423 } | 1435 } |
1424 MaybeObject* maybe_obj = GetElementsTransitionMap(GetIsolate(), | 1436 MaybeObject* maybe = GetElementsTransitionMap(GetIsolate(), elements_kind); |
1425 elements_kind); | 1437 Map* map; |
1426 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 1438 if (!maybe->To(&map)) return maybe; |
1427 set_map(Map::cast(obj)); | 1439 set_map(map); |
1428 initialize_elements(); | 1440 initialize_elements(); |
1429 if (FLAG_harmony_observation && map()->is_observed()) { | 1441 |
1430 // Maintain invariant that observed elements are always in dictionary mode. | |
1431 // For this to work on arrays, we have to make sure to reset length first. | |
1432 if (IsJSArray()) JSArray::cast(this)->set_length(Smi::FromInt(0)); | |
1433 maybe_obj = NormalizeElements(); | |
1434 if (maybe_obj->IsFailure()) return maybe_obj; | |
1435 } | |
1436 return this; | 1442 return this; |
1437 } | 1443 } |
1438 | 1444 |
1439 | 1445 |
1440 MaybeObject* JSObject::AddFastPropertyUsingMap(Map* map) { | 1446 MaybeObject* JSObject::AddFastPropertyUsingMap(Map* map) { |
1441 ASSERT(this->map()->NumberOfOwnDescriptors() + 1 == | 1447 ASSERT(this->map()->NumberOfOwnDescriptors() + 1 == |
1442 map->NumberOfOwnDescriptors()); | 1448 map->NumberOfOwnDescriptors()); |
1443 if (this->map()->unused_property_fields() == 0) { | 1449 if (this->map()->unused_property_fields() == 0) { |
1444 int new_size = properties()->length() + map->unused_property_fields() + 1; | 1450 int new_size = properties()->length() + map->unused_property_fields() + 1; |
1445 FixedArray* new_properties; | 1451 FixedArray* new_properties; |
(...skipping 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3355 set_bit_field3(OwnsDescriptors::update(bit_field3(), is_shared)); | 3361 set_bit_field3(OwnsDescriptors::update(bit_field3(), is_shared)); |
3356 } | 3362 } |
3357 | 3363 |
3358 | 3364 |
3359 bool Map::owns_descriptors() { | 3365 bool Map::owns_descriptors() { |
3360 return OwnsDescriptors::decode(bit_field3()); | 3366 return OwnsDescriptors::decode(bit_field3()); |
3361 } | 3367 } |
3362 | 3368 |
3363 | 3369 |
3364 void Map::set_is_observed(bool is_observed) { | 3370 void Map::set_is_observed(bool is_observed) { |
| 3371 ASSERT(instance_type() < FIRST_JS_OBJECT_TYPE || |
| 3372 instance_type() > LAST_JS_OBJECT_TYPE || |
| 3373 has_slow_elements_kind() || has_external_array_elements()); |
3365 set_bit_field3(IsObserved::update(bit_field3(), is_observed)); | 3374 set_bit_field3(IsObserved::update(bit_field3(), is_observed)); |
3366 } | 3375 } |
3367 | 3376 |
3368 | 3377 |
3369 bool Map::is_observed() { | 3378 bool Map::is_observed() { |
3370 return IsObserved::decode(bit_field3()); | 3379 return IsObserved::decode(bit_field3()); |
3371 } | 3380 } |
3372 | 3381 |
3373 | 3382 |
3374 void Code::set_flags(Code::Flags flags) { | 3383 void Code::set_flags(Code::Flags flags) { |
(...skipping 2370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5745 #undef WRITE_UINT32_FIELD | 5754 #undef WRITE_UINT32_FIELD |
5746 #undef READ_SHORT_FIELD | 5755 #undef READ_SHORT_FIELD |
5747 #undef WRITE_SHORT_FIELD | 5756 #undef WRITE_SHORT_FIELD |
5748 #undef READ_BYTE_FIELD | 5757 #undef READ_BYTE_FIELD |
5749 #undef WRITE_BYTE_FIELD | 5758 #undef WRITE_BYTE_FIELD |
5750 | 5759 |
5751 | 5760 |
5752 } } // namespace v8::internal | 5761 } } // namespace v8::internal |
5753 | 5762 |
5754 #endif // V8_OBJECTS_INL_H_ | 5763 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |