| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 9514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9525 | 9525 |
| 9526 | 9526 |
| 9527 Handle<Object> CacheInitialJSArrayMaps(Handle<Context> native_context, | 9527 Handle<Object> CacheInitialJSArrayMaps(Handle<Context> native_context, |
| 9528 Handle<Map> initial_map) { | 9528 Handle<Map> initial_map) { |
| 9529 CALL_HEAP_FUNCTION(native_context->GetIsolate(), | 9529 CALL_HEAP_FUNCTION(native_context->GetIsolate(), |
| 9530 CacheInitialJSArrayMaps(*native_context, *initial_map), | 9530 CacheInitialJSArrayMaps(*native_context, *initial_map), |
| 9531 Object); | 9531 Object); |
| 9532 } | 9532 } |
| 9533 | 9533 |
| 9534 | 9534 |
| 9535 MaybeObject* JSFunction::SetInstancePrototype(Object* value) { | 9535 void JSFunction::SetInstancePrototype(Handle<JSFunction> function, |
| 9536 Handle<Object> value) { |
| 9536 ASSERT(value->IsJSReceiver()); | 9537 ASSERT(value->IsJSReceiver()); |
| 9537 Heap* heap = GetHeap(); | |
| 9538 | 9538 |
| 9539 // First some logic for the map of the prototype to make sure it is in fast | 9539 // First some logic for the map of the prototype to make sure it is in fast |
| 9540 // mode. | 9540 // mode. |
| 9541 if (value->IsJSObject()) { | 9541 if (value->IsJSObject()) { |
| 9542 MaybeObject* ok = JSObject::cast(value)->OptimizeAsPrototype(); | 9542 JSObject::OptimizeAsPrototype(Handle<JSObject>::cast(value)); |
| 9543 if (ok->IsFailure()) return ok; | |
| 9544 } | 9543 } |
| 9545 | 9544 |
| 9546 // Now some logic for the maps of the objects that are created by using this | 9545 // Now some logic for the maps of the objects that are created by using this |
| 9547 // function as a constructor. | 9546 // function as a constructor. |
| 9548 if (has_initial_map()) { | 9547 if (function->has_initial_map()) { |
| 9549 // If the function has allocated the initial map replace it with a | 9548 // If the function has allocated the initial map replace it with a |
| 9550 // copy containing the new prototype. Also complete any in-object | 9549 // copy containing the new prototype. Also complete any in-object |
| 9551 // slack tracking that is in progress at this point because it is | 9550 // slack tracking that is in progress at this point because it is |
| 9552 // still tracking the old copy. | 9551 // still tracking the old copy. |
| 9553 if (shared()->IsInobjectSlackTrackingInProgress()) { | 9552 if (function->shared()->IsInobjectSlackTrackingInProgress()) { |
| 9554 shared()->CompleteInobjectSlackTracking(); | 9553 function->shared()->CompleteInobjectSlackTracking(); |
| 9555 } | 9554 } |
| 9556 Map* new_map; | 9555 Handle<Map> new_map = Map::Copy(handle(function->initial_map())); |
| 9557 MaybeObject* maybe_object = initial_map()->Copy(); | 9556 new_map->set_prototype(*value); |
| 9558 if (!maybe_object->To(&new_map)) return maybe_object; | |
| 9559 new_map->set_prototype(value); | |
| 9560 | 9557 |
| 9561 // If the function is used as the global Array function, cache the | 9558 // If the function is used as the global Array function, cache the |
| 9562 // initial map (and transitioned versions) in the native context. | 9559 // initial map (and transitioned versions) in the native context. |
| 9563 Context* native_context = context()->native_context(); | 9560 Context* native_context = function->context()->native_context(); |
| 9564 Object* array_function = native_context->get(Context::ARRAY_FUNCTION_INDEX); | 9561 Object* array_function = native_context->get(Context::ARRAY_FUNCTION_INDEX); |
| 9565 if (array_function->IsJSFunction() && | 9562 if (array_function->IsJSFunction() && |
| 9566 this == JSFunction::cast(array_function)) { | 9563 *function == JSFunction::cast(array_function)) { |
| 9567 MaybeObject* ok = CacheInitialJSArrayMaps(native_context, new_map); | 9564 CacheInitialJSArrayMaps(handle(native_context), new_map); |
| 9568 if (ok->IsFailure()) return ok; | |
| 9569 } | 9565 } |
| 9570 | 9566 |
| 9571 set_initial_map(new_map); | 9567 function->set_initial_map(*new_map); |
| 9572 } else { | 9568 } else { |
| 9573 // Put the value in the initial map field until an initial map is | 9569 // Put the value in the initial map field until an initial map is |
| 9574 // needed. At that point, a new initial map is created and the | 9570 // needed. At that point, a new initial map is created and the |
| 9575 // prototype is put into the initial map where it belongs. | 9571 // prototype is put into the initial map where it belongs. |
| 9576 set_prototype_or_initial_map(value); | 9572 function->set_prototype_or_initial_map(*value); |
| 9577 } | 9573 } |
| 9578 heap->ClearInstanceofCache(); | 9574 function->GetHeap()->ClearInstanceofCache(); |
| 9579 return value; | |
| 9580 } | 9575 } |
| 9581 | 9576 |
| 9582 | 9577 |
| 9583 MaybeObject* JSFunction::SetPrototype(Object* value) { | 9578 void JSFunction::SetPrototype(Handle<JSFunction> function, |
| 9584 ASSERT(should_have_prototype()); | 9579 Handle<Object> value) { |
| 9585 Object* construct_prototype = value; | 9580 ASSERT(function->should_have_prototype()); |
| 9581 Handle<Object> construct_prototype = value; |
| 9586 | 9582 |
| 9587 // If the value is not a JSReceiver, store the value in the map's | 9583 // If the value is not a JSReceiver, store the value in the map's |
| 9588 // constructor field so it can be accessed. Also, set the prototype | 9584 // constructor field so it can be accessed. Also, set the prototype |
| 9589 // used for constructing objects to the original object prototype. | 9585 // used for constructing objects to the original object prototype. |
| 9590 // See ECMA-262 13.2.2. | 9586 // See ECMA-262 13.2.2. |
| 9591 if (!value->IsJSReceiver()) { | 9587 if (!value->IsJSReceiver()) { |
| 9592 // Copy the map so this does not affect unrelated functions. | 9588 // Copy the map so this does not affect unrelated functions. |
| 9593 // Remove map transitions because they point to maps with a | 9589 // Remove map transitions because they point to maps with a |
| 9594 // different prototype. | 9590 // different prototype. |
| 9595 Map* new_map; | 9591 Handle<Map> new_map = Map::Copy(handle(function->map())); |
| 9596 MaybeObject* maybe_new_map = map()->Copy(); | |
| 9597 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | |
| 9598 | 9592 |
| 9599 Heap* heap = new_map->GetHeap(); | 9593 function->set_map(*new_map); |
| 9600 set_map(new_map); | 9594 new_map->set_constructor(*value); |
| 9601 new_map->set_constructor(value); | |
| 9602 new_map->set_non_instance_prototype(true); | 9595 new_map->set_non_instance_prototype(true); |
| 9603 construct_prototype = | 9596 Isolate* isolate = new_map->GetIsolate(); |
| 9604 heap->isolate()->context()->native_context()-> | 9597 construct_prototype = handle( |
| 9605 initial_object_prototype(); | 9598 isolate->context()->native_context()->initial_object_prototype(), |
| 9599 isolate); |
| 9606 } else { | 9600 } else { |
| 9607 map()->set_non_instance_prototype(false); | 9601 function->map()->set_non_instance_prototype(false); |
| 9608 } | 9602 } |
| 9609 | 9603 |
| 9610 return SetInstancePrototype(construct_prototype); | 9604 return SetInstancePrototype(function, construct_prototype); |
| 9611 } | 9605 } |
| 9612 | 9606 |
| 9613 | 9607 |
| 9614 void JSFunction::RemovePrototype() { | 9608 void JSFunction::RemovePrototype() { |
| 9615 Context* native_context = context()->native_context(); | 9609 Context* native_context = context()->native_context(); |
| 9616 Map* no_prototype_map = shared()->is_classic_mode() | 9610 Map* no_prototype_map = shared()->is_classic_mode() |
| 9617 ? native_context->function_without_prototype_map() | 9611 ? native_context->function_without_prototype_map() |
| 9618 : native_context->strict_mode_function_without_prototype_map(); | 9612 : native_context->strict_mode_function_without_prototype_map(); |
| 9619 | 9613 |
| 9620 if (map() == no_prototype_map) return; | 9614 if (map() == no_prototype_map) return; |
| (...skipping 6332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15953 | 15947 |
| 15954 void PropertyCell::AddDependentCode(Handle<Code> code) { | 15948 void PropertyCell::AddDependentCode(Handle<Code> code) { |
| 15955 Handle<DependentCode> codes = DependentCode::Insert( | 15949 Handle<DependentCode> codes = DependentCode::Insert( |
| 15956 Handle<DependentCode>(dependent_code()), | 15950 Handle<DependentCode>(dependent_code()), |
| 15957 DependentCode::kPropertyCellChangedGroup, code); | 15951 DependentCode::kPropertyCellChangedGroup, code); |
| 15958 if (*codes != dependent_code()) set_dependent_code(*codes); | 15952 if (*codes != dependent_code()) set_dependent_code(*codes); |
| 15959 } | 15953 } |
| 15960 | 15954 |
| 15961 | 15955 |
| 15962 } } // namespace v8::internal | 15956 } } // namespace v8::internal |
| OLD | NEW |