| 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 7433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7444 if (shared_info->optimization_disabled()) return false; | 7444 if (shared_info->optimization_disabled()) return false; |
| 7445 Code* code = shared_info->code(); | 7445 Code* code = shared_info->code(); |
| 7446 if (code->kind() == Code::OPTIMIZED_FUNCTION) return true; | 7446 if (code->kind() == Code::OPTIMIZED_FUNCTION) return true; |
| 7447 // If we never ran this (unlikely) then lets try to optimize it. | 7447 // If we never ran this (unlikely) then lets try to optimize it. |
| 7448 if (code->kind() != Code::FUNCTION) return true; | 7448 if (code->kind() != Code::FUNCTION) return true; |
| 7449 return code->optimizable(); | 7449 return code->optimizable(); |
| 7450 } | 7450 } |
| 7451 | 7451 |
| 7452 | 7452 |
| 7453 MaybeObject* JSFunction::SetInstancePrototype(Object* value) { | 7453 MaybeObject* JSFunction::SetInstancePrototype(Object* value) { |
| 7454 ASSERT(value->IsJSObject()); | 7454 ASSERT(value->IsJSReceiver()); |
| 7455 Heap* heap = GetHeap(); | 7455 Heap* heap = GetHeap(); |
| 7456 if (has_initial_map()) { | 7456 if (has_initial_map()) { |
| 7457 // If the function has allocated the initial map | 7457 // If the function has allocated the initial map |
| 7458 // replace it with a copy containing the new prototype. | 7458 // replace it with a copy containing the new prototype. |
| 7459 Map* new_map; | 7459 Map* new_map; |
| 7460 MaybeObject* maybe_new_map = initial_map()->CopyDropTransitions(); | 7460 MaybeObject* maybe_new_map = initial_map()->CopyDropTransitions(); |
| 7461 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | 7461 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
| 7462 new_map->set_prototype(value); | 7462 new_map->set_prototype(value); |
| 7463 MaybeObject* maybe_object = | 7463 MaybeObject* maybe_object = |
| 7464 set_initial_map_and_cache_transitions(new_map); | 7464 set_initial_map_and_cache_transitions(new_map); |
| 7465 if (maybe_object->IsFailure()) return maybe_object; | 7465 if (maybe_object->IsFailure()) return maybe_object; |
| 7466 } else { | 7466 } else { |
| 7467 // Put the value in the initial map field until an initial map is | 7467 // Put the value in the initial map field until an initial map is |
| 7468 // needed. At that point, a new initial map is created and the | 7468 // needed. At that point, a new initial map is created and the |
| 7469 // prototype is put into the initial map where it belongs. | 7469 // prototype is put into the initial map where it belongs. |
| 7470 set_prototype_or_initial_map(value); | 7470 set_prototype_or_initial_map(value); |
| 7471 } | 7471 } |
| 7472 heap->ClearInstanceofCache(); | 7472 heap->ClearInstanceofCache(); |
| 7473 return value; | 7473 return value; |
| 7474 } | 7474 } |
| 7475 | 7475 |
| 7476 | 7476 |
| 7477 MaybeObject* JSFunction::SetPrototype(Object* value) { | 7477 MaybeObject* JSFunction::SetPrototype(Object* value) { |
| 7478 ASSERT(should_have_prototype()); | 7478 ASSERT(should_have_prototype()); |
| 7479 Object* construct_prototype = value; | 7479 Object* construct_prototype = value; |
| 7480 | 7480 |
| 7481 // If the value is not a JSObject, store the value in the map's | 7481 // If the value is not a JSReceiver, store the value in the map's |
| 7482 // constructor field so it can be accessed. Also, set the prototype | 7482 // constructor field so it can be accessed. Also, set the prototype |
| 7483 // used for constructing objects to the original object prototype. | 7483 // used for constructing objects to the original object prototype. |
| 7484 // See ECMA-262 13.2.2. | 7484 // See ECMA-262 13.2.2. |
| 7485 if (!value->IsJSObject()) { | 7485 if (!value->IsJSReceiver()) { |
| 7486 // Copy the map so this does not affect unrelated functions. | 7486 // Copy the map so this does not affect unrelated functions. |
| 7487 // Remove map transitions because they point to maps with a | 7487 // Remove map transitions because they point to maps with a |
| 7488 // different prototype. | 7488 // different prototype. |
| 7489 Map* new_map; | 7489 Map* new_map; |
| 7490 { MaybeObject* maybe_new_map = map()->CopyDropTransitions(); | 7490 { MaybeObject* maybe_new_map = map()->CopyDropTransitions(); |
| 7491 if (!maybe_new_map->To(&new_map)) return maybe_new_map; | 7491 if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
| 7492 } | 7492 } |
| 7493 Heap* heap = new_map->GetHeap(); | 7493 Heap* heap = new_map->GetHeap(); |
| 7494 set_map(new_map); | 7494 set_map(new_map); |
| 7495 new_map->set_constructor(value); | 7495 new_map->set_constructor(value); |
| (...skipping 5443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12939 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 12939 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
| 12940 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 12940 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
| 12941 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 12941 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
| 12942 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 12942 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
| 12943 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 12943 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
| 12944 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 12944 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
| 12945 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 12945 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
| 12946 } | 12946 } |
| 12947 | 12947 |
| 12948 } } // namespace v8::internal | 12948 } } // namespace v8::internal |
| OLD | NEW |