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 7681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7692 // so they remain fast. | 7692 // so they remain fast. |
7693 if (!HasFastProperties()) { | 7693 if (!HasFastProperties()) { |
7694 MaybeObject* new_proto = TransformToFastProperties(0); | 7694 MaybeObject* new_proto = TransformToFastProperties(0); |
7695 if (new_proto->IsFailure()) return new_proto; | 7695 if (new_proto->IsFailure()) return new_proto; |
7696 ASSERT(new_proto == this); | 7696 ASSERT(new_proto == this); |
7697 } | 7697 } |
7698 return this; | 7698 return this; |
7699 } | 7699 } |
7700 | 7700 |
7701 | 7701 |
| 7702 MUST_USE_RESULT static MaybeObject* CacheInitialJSArrayMaps( |
| 7703 Context* native_context, Map* initial_map) { |
| 7704 // Replace all of the cached initial array maps in the native context with |
| 7705 // the appropriate transitioned elements kind maps. |
| 7706 Heap* heap = native_context->GetHeap(); |
| 7707 MaybeObject* maybe_maps = |
| 7708 heap->AllocateFixedArrayWithHoles(kElementsKindCount); |
| 7709 FixedArray* maps; |
| 7710 if (!maybe_maps->To(&maps)) return maybe_maps; |
| 7711 |
| 7712 Map* current_map = initial_map; |
| 7713 ElementsKind kind = current_map->elements_kind(); |
| 7714 ASSERT(kind == GetInitialFastElementsKind()); |
| 7715 maps->set(kind, current_map); |
| 7716 for (int i = GetSequenceIndexFromFastElementsKind(kind) + 1; |
| 7717 i < kFastElementsKindCount; ++i) { |
| 7718 Map* new_map; |
| 7719 ElementsKind next_kind = GetFastElementsKindFromSequenceIndex(i); |
| 7720 MaybeObject* maybe_new_map = |
| 7721 current_map->CopyAsElementsKind(next_kind, INSERT_TRANSITION); |
| 7722 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
| 7723 maps->set(next_kind, new_map); |
| 7724 current_map = new_map; |
| 7725 } |
| 7726 native_context->set_js_array_maps(maps); |
| 7727 return initial_map; |
| 7728 } |
| 7729 |
| 7730 |
7702 MaybeObject* JSFunction::SetInstancePrototype(Object* value) { | 7731 MaybeObject* JSFunction::SetInstancePrototype(Object* value) { |
7703 ASSERT(value->IsJSReceiver()); | 7732 ASSERT(value->IsJSReceiver()); |
7704 Heap* heap = GetHeap(); | 7733 Heap* heap = GetHeap(); |
7705 | 7734 |
7706 // First some logic for the map of the prototype to make sure it is in fast | 7735 // First some logic for the map of the prototype to make sure it is in fast |
7707 // mode. | 7736 // mode. |
7708 if (value->IsJSObject()) { | 7737 if (value->IsJSObject()) { |
7709 MaybeObject* ok = JSObject::cast(value)->OptimizeAsPrototype(); | 7738 MaybeObject* ok = JSObject::cast(value)->OptimizeAsPrototype(); |
7710 if (ok->IsFailure()) return ok; | 7739 if (ok->IsFailure()) return ok; |
7711 } | 7740 } |
7712 | 7741 |
7713 // Now some logic for the maps of the objects that are created by using this | 7742 // Now some logic for the maps of the objects that are created by using this |
7714 // function as a constructor. | 7743 // function as a constructor. |
7715 if (has_initial_map()) { | 7744 if (has_initial_map()) { |
7716 // If the function has allocated the initial map | 7745 // If the function has allocated the initial map replace it with a |
7717 // replace it with a copy containing the new prototype. | 7746 // copy containing the new prototype. Also complete any in-object |
| 7747 // slack tracking that is in progress at this point because it is |
| 7748 // still tracking the old copy. |
| 7749 if (shared()->IsInobjectSlackTrackingInProgress()) { |
| 7750 shared()->CompleteInobjectSlackTracking(); |
| 7751 } |
7718 Map* new_map; | 7752 Map* new_map; |
7719 MaybeObject* maybe_new_map = initial_map()->Copy(); | 7753 MaybeObject* maybe_object = initial_map()->Copy(); |
7720 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | 7754 if (!maybe_object->To(&new_map)) return maybe_object; |
7721 new_map->set_prototype(value); | 7755 new_map->set_prototype(value); |
7722 MaybeObject* maybe_object = set_initial_map_and_cache_transitions(new_map); | 7756 |
7723 if (maybe_object->IsFailure()) return maybe_object; | 7757 // If the function is used as the global Array function, cache the |
| 7758 // initial map (and transitioned versions) in the native context. |
| 7759 Context* native_context = context()->native_context(); |
| 7760 Object* array_function = native_context->get(Context::ARRAY_FUNCTION_INDEX); |
| 7761 if (array_function->IsJSFunction() && |
| 7762 this == JSFunction::cast(array_function)) { |
| 7763 MaybeObject* ok = CacheInitialJSArrayMaps(native_context, new_map); |
| 7764 if (ok->IsFailure()) return ok; |
| 7765 } |
| 7766 |
| 7767 set_initial_map(new_map); |
7724 } else { | 7768 } else { |
7725 // Put the value in the initial map field until an initial map is | 7769 // Put the value in the initial map field until an initial map is |
7726 // needed. At that point, a new initial map is created and the | 7770 // needed. At that point, a new initial map is created and the |
7727 // prototype is put into the initial map where it belongs. | 7771 // prototype is put into the initial map where it belongs. |
7728 set_prototype_or_initial_map(value); | 7772 set_prototype_or_initial_map(value); |
7729 } | 7773 } |
7730 heap->ClearInstanceofCache(); | 7774 heap->ClearInstanceofCache(); |
7731 return value; | 7775 return value; |
7732 } | 7776 } |
7733 | 7777 |
(...skipping 5739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13473 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13517 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13474 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13518 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13475 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13519 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13476 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13520 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13477 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13521 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13478 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13522 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13479 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13523 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13480 } | 13524 } |
13481 | 13525 |
13482 } } // namespace v8::internal | 13526 } } // namespace v8::internal |
OLD | NEW |