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 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 | 1594 |
1595 FixedArray* values = NULL; | 1595 FixedArray* values = NULL; |
1596 | 1596 |
1597 if (map()->unused_property_fields() == 0) { | 1597 if (map()->unused_property_fields() == 0) { |
1598 // Make room for the new value | 1598 // Make room for the new value |
1599 MaybeObject* maybe_values = | 1599 MaybeObject* maybe_values = |
1600 properties()->CopySize(properties()->length() + kFieldsAdded); | 1600 properties()->CopySize(properties()->length() + kFieldsAdded); |
1601 if (!maybe_values->To(&values)) return maybe_values; | 1601 if (!maybe_values->To(&values)) return maybe_values; |
1602 } | 1602 } |
1603 | 1603 |
1604 // Only allow map transition if the object isn't the global object. | 1604 TransitionFlag flag = INSERT_TRANSITION; |
1605 TransitionFlag flag = isolate->empty_object_map() != map() | |
1606 ? INSERT_TRANSITION | |
1607 : OMIT_TRANSITION; | |
1608 | 1605 |
1609 Map* new_map; | 1606 Map* new_map; |
1610 MaybeObject* maybe_new_map = map()->CopyAddDescriptor(&new_field, flag); | 1607 MaybeObject* maybe_new_map = map()->CopyAddDescriptor(&new_field, flag); |
1611 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | 1608 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
1612 | 1609 |
1613 if (map()->unused_property_fields() == 0) { | 1610 if (map()->unused_property_fields() == 0) { |
1614 ASSERT(values != NULL); | 1611 ASSERT(values != NULL); |
1615 set_properties(values); | 1612 set_properties(values); |
1616 new_map->set_unused_property_fields(kFieldsAdded - 1); | 1613 new_map->set_unused_property_fields(kFieldsAdded - 1); |
1617 } else { | 1614 } else { |
1618 new_map->set_unused_property_fields(map()->unused_property_fields() - 1); | 1615 new_map->set_unused_property_fields(map()->unused_property_fields() - 1); |
1619 } | 1616 } |
1620 | 1617 |
1621 set_map(new_map); | 1618 set_map(new_map); |
1622 return FastPropertyAtPut(index, value); | 1619 return FastPropertyAtPut(index, value); |
1623 } | 1620 } |
1624 | 1621 |
1625 | 1622 |
1626 MaybeObject* JSObject::AddConstantFunctionProperty( | 1623 MaybeObject* JSObject::AddConstantFunctionProperty( |
1627 String* name, | 1624 String* name, |
1628 JSFunction* function, | 1625 JSFunction* function, |
1629 PropertyAttributes attributes) { | 1626 PropertyAttributes attributes) { |
1630 // Allocate new instance descriptors with (name, function) added | 1627 // Allocate new instance descriptors with (name, function) added |
1631 ConstantFunctionDescriptor d(name, function, attributes, 0); | 1628 ConstantFunctionDescriptor d(name, function, attributes, 0); |
1632 | 1629 |
1633 Heap* heap = GetHeap(); | |
1634 TransitionFlag flag = | 1630 TransitionFlag flag = |
1635 // Do not add transitions to the empty object map (map of "new Object()"), | 1631 // Do not add transitions to global objects. |
1636 // nor to global objects. | 1632 (IsGlobalObject() || |
1637 (map() == heap->isolate()->empty_object_map() || IsGlobalObject() || | |
1638 // Don't add transitions to special properties with non-trivial | 1633 // Don't add transitions to special properties with non-trivial |
1639 // attributes. | 1634 // attributes. |
1640 // TODO(verwaest): Once we support attribute changes, these transitions | |
1641 // should be kept as well. | |
1642 attributes != NONE) | 1635 attributes != NONE) |
1643 ? OMIT_TRANSITION | 1636 ? OMIT_TRANSITION |
1644 : INSERT_TRANSITION; | 1637 : INSERT_TRANSITION; |
1645 | 1638 |
1646 Map* new_map; | 1639 Map* new_map; |
1647 MaybeObject* maybe_new_map = map()->CopyAddDescriptor(&d, flag); | 1640 MaybeObject* maybe_new_map = map()->CopyAddDescriptor(&d, flag); |
1648 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | 1641 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
1649 | 1642 |
1650 set_map(new_map); | 1643 set_map(new_map); |
1651 return function; | 1644 return function; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 Map* old_map = map(); | 1827 Map* old_map = map(); |
1835 Map* old_target = old_map->GetTransition(transition_index); | 1828 Map* old_target = old_map->GetTransition(transition_index); |
1836 Object* result; | 1829 Object* result; |
1837 | 1830 |
1838 MaybeObject* maybe_result = | 1831 MaybeObject* maybe_result = |
1839 ConvertDescriptorToField(name, new_value, attributes); | 1832 ConvertDescriptorToField(name, new_value, attributes); |
1840 if (!maybe_result->To(&result)) return maybe_result; | 1833 if (!maybe_result->To(&result)) return maybe_result; |
1841 | 1834 |
1842 if (!HasFastProperties()) return result; | 1835 if (!HasFastProperties()) return result; |
1843 | 1836 |
1844 // This method should only be used to convert existing transitions. Objects | 1837 // This method should only be used to convert existing transitions. |
1845 // with the map of "new Object()" cannot have transitions in the first place. | |
1846 Map* new_map = map(); | 1838 Map* new_map = map(); |
1847 ASSERT(new_map != GetIsolate()->empty_object_map()); | |
1848 | 1839 |
1849 // TODO(verwaest): From here on we lose existing map transitions, causing | 1840 // TODO(verwaest): From here on we lose existing map transitions, causing |
1850 // invalid back pointers. This will change once we can store multiple | 1841 // invalid back pointers. This will change once we can store multiple |
1851 // transitions with the same key. | 1842 // transitions with the same key. |
1852 | 1843 |
1853 bool owned_descriptors = old_map->owns_descriptors(); | 1844 bool owned_descriptors = old_map->owns_descriptors(); |
1854 if (owned_descriptors || | 1845 if (owned_descriptors || |
1855 old_target->instance_descriptors() == old_map->instance_descriptors()) { | 1846 old_target->instance_descriptors() == old_map->instance_descriptors()) { |
1856 // Since the conversion above generated a new fast map with an additional | 1847 // Since the conversion above generated a new fast map with an additional |
1857 // property which can be shared as well, install this descriptor pointer | 1848 // property which can be shared as well, install this descriptor pointer |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2408 | 2399 |
2409 MaybeObject* JSObject::GetElementsTransitionMapSlow(ElementsKind to_kind) { | 2400 MaybeObject* JSObject::GetElementsTransitionMapSlow(ElementsKind to_kind) { |
2410 Map* start_map = map(); | 2401 Map* start_map = map(); |
2411 ElementsKind from_kind = start_map->elements_kind(); | 2402 ElementsKind from_kind = start_map->elements_kind(); |
2412 | 2403 |
2413 if (from_kind == to_kind) { | 2404 if (from_kind == to_kind) { |
2414 return start_map; | 2405 return start_map; |
2415 } | 2406 } |
2416 | 2407 |
2417 bool allow_store_transition = | 2408 bool allow_store_transition = |
2418 // Only remember the map transition if the object's map is NOT equal to | 2409 // Only remember the map transition if there is not an already existing |
2419 // the global object_function's map and there is not an already existing | |
2420 // non-matching element transition. | 2410 // non-matching element transition. |
2421 (GetIsolate()->empty_object_map() != map()) && | |
2422 !start_map->IsUndefined() && !start_map->is_shared() && | 2411 !start_map->IsUndefined() && !start_map->is_shared() && |
2423 IsFastElementsKind(from_kind); | 2412 IsFastElementsKind(from_kind); |
2424 | 2413 |
2425 // Only store fast element maps in ascending generality. | 2414 // Only store fast element maps in ascending generality. |
2426 if (IsFastElementsKind(to_kind)) { | 2415 if (IsFastElementsKind(to_kind)) { |
2427 allow_store_transition &= | 2416 allow_store_transition &= |
2428 IsTransitionableFastElementsKind(from_kind) && | 2417 IsTransitionableFastElementsKind(from_kind) && |
2429 IsMoreGeneralElementsKindTransition(from_kind, to_kind); | 2418 IsMoreGeneralElementsKindTransition(from_kind, to_kind); |
2430 } | 2419 } |
2431 | 2420 |
(...skipping 11423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13855 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13844 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13856 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13845 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13857 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13846 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13858 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13847 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13859 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13848 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13860 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13849 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13861 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13850 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13862 } | 13851 } |
13863 | 13852 |
13864 } } // namespace v8::internal | 13853 } } // namespace v8::internal |
OLD | NEW |