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 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1481 FixedArray* new_properties; | 1481 FixedArray* new_properties; |
1482 MaybeObject* maybe_properties = properties()->CopySize(new_size); | 1482 MaybeObject* maybe_properties = properties()->CopySize(new_size); |
1483 if (!maybe_properties->To(&new_properties)) return maybe_properties; | 1483 if (!maybe_properties->To(&new_properties)) return maybe_properties; |
1484 set_properties(new_properties); | 1484 set_properties(new_properties); |
1485 } | 1485 } |
1486 set_map(map); | 1486 set_map(map); |
1487 return this; | 1487 return this; |
1488 } | 1488 } |
1489 | 1489 |
1490 | 1490 |
1491 bool JSObject::TryTransitionToField(Handle<JSObject> object, | 1491 MaybeObject* JSObject::TransitionToMap(Map* map) { |
1492 Handle<Name> key) { | 1492 ASSERT(this->map()->inobject_properties() == map->inobject_properties()); |
1493 if (!object->map()->HasTransitionArray()) return false; | 1493 ElementsKind expected_kind = this->map()->elements_kind(); |
1494 Handle<Map> target; | 1494 if (map->elements_kind() != expected_kind) { |
1495 { | 1495 MaybeObject* maybe_map = map->AsElementsKind(expected_kind); |
1496 AssertNoAllocation no_allocation; | 1496 if (!maybe_map->To(&map)) return maybe_map; |
1497 TransitionArray* transitions = object->map()->transitions(); | |
1498 int transition = transitions->Search(*key); | |
1499 if (transition == TransitionArray::kNotFound) return false; | |
1500 PropertyDetails target_details = transitions->GetTargetDetails(transition); | |
1501 if (target_details.type() != FIELD) return false; | |
1502 if (target_details.attributes() != NONE) return false; | |
1503 target = Handle<Map>(transitions->GetTarget(transition)); | |
1504 } | 1497 } |
1505 JSObject::AddFastPropertyUsingMap(object, target); | 1498 int total_size = |
1506 return true; | 1499 map->NumberOfOwnDescriptors() + map->unused_property_fields(); |
1500 int out_of_object = total_size - map->inobject_properties(); | |
1501 if (out_of_object != properties()->length()) { | |
1502 FixedArray* new_properties; | |
1503 MaybeObject* maybe_properties = properties()->CopySize(out_of_object); | |
1504 if (!maybe_properties->To(&new_properties)) return maybe_properties; | |
1505 set_properties(new_properties); | |
1506 } | |
1507 set_map(map); | |
1508 return this; | |
1507 } | 1509 } |
1508 | 1510 |
1509 | 1511 |
1512 Handle<String> JSObject::ExpectedTransitionKey(Handle<Map> map) { | |
1513 AssertNoAllocation no_gc; | |
1514 if (!map->HasTransitionArray()) return Handle<String>::null(); | |
1515 TransitionArray* transitions = map->transitions(); | |
1516 if (!transitions->IsSimpleTransition()) return Handle<String>::null(); | |
1517 int transition = TransitionArray::kSimpleTransitionIndex; | |
1518 PropertyDetails details = transitions->GetTargetDetails(transition); | |
1519 Name* name = transitions->GetKey(transition); | |
1520 if (details.type() != FIELD) return Handle<String>::null(); | |
1521 if (details.attributes() != NONE) return Handle<String>::null(); | |
1522 if (!name->IsString()) return Handle<String>::null(); | |
1523 return Handle<String>(String::cast(name)); | |
1524 } | |
1525 | |
1526 | |
1527 Handle<Map> JSObject::ExpectedTransitionTarget(Handle<Map> map) { | |
Yang
2013/04/09 15:47:00
Maybe add an assert that this can only follow afte
Toon Verwaest
2013/04/09 16:47:59
Done.
| |
1528 return Handle<Map>(map->transitions()->GetTarget( | |
1529 TransitionArray::kSimpleTransitionIndex)); | |
1530 } | |
1531 | |
1532 | |
1533 Handle<Map> JSObject::FindTransitionToField(Handle<Map> map, Handle<Name> key) { | |
1534 AssertNoAllocation no_allocation; | |
1535 if (!map->HasTransitionArray()) return Handle<Map>::null(); | |
1536 TransitionArray* transitions = map->transitions(); | |
1537 int transition = transitions->Search(*key); | |
1538 if (transition == TransitionArray::kNotFound) return Handle<Map>::null(); | |
1539 PropertyDetails target_details = transitions->GetTargetDetails(transition); | |
1540 if (target_details.type() != FIELD) return Handle<Map>::null(); | |
1541 if (target_details.attributes() != NONE) return Handle<Map>::null(); | |
1542 return Handle<Map>(transitions->GetTarget(transition)); | |
1543 } | |
1544 | |
1545 | |
1510 int JSObject::LastAddedFieldIndex() { | 1546 int JSObject::LastAddedFieldIndex() { |
1511 Map* map = this->map(); | 1547 Map* map = this->map(); |
1512 int last_added = map->LastAdded(); | 1548 int last_added = map->LastAdded(); |
1513 return map->instance_descriptors()->GetFieldIndex(last_added); | 1549 return map->instance_descriptors()->GetFieldIndex(last_added); |
1514 } | 1550 } |
1515 | 1551 |
1516 | 1552 |
1517 ACCESSORS(Oddball, to_string, String, kToStringOffset) | 1553 ACCESSORS(Oddball, to_string, String, kToStringOffset) |
1518 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) | 1554 ACCESSORS(Oddball, to_number, Object, kToNumberOffset) |
1519 | 1555 |
(...skipping 4525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6045 #undef WRITE_UINT32_FIELD | 6081 #undef WRITE_UINT32_FIELD |
6046 #undef READ_SHORT_FIELD | 6082 #undef READ_SHORT_FIELD |
6047 #undef WRITE_SHORT_FIELD | 6083 #undef WRITE_SHORT_FIELD |
6048 #undef READ_BYTE_FIELD | 6084 #undef READ_BYTE_FIELD |
6049 #undef WRITE_BYTE_FIELD | 6085 #undef WRITE_BYTE_FIELD |
6050 | 6086 |
6051 | 6087 |
6052 } } // namespace v8::internal | 6088 } } // namespace v8::internal |
6053 | 6089 |
6054 #endif // V8_OBJECTS_INL_H_ | 6090 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |