| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 446 |
| 447 | 447 |
| 448 Object* LoadIC::Load(State state, Handle<Object> object, Handle<String> name) { | 448 Object* LoadIC::Load(State state, Handle<Object> object, Handle<String> name) { |
| 449 // If the object is undefined or null it's illegal to try to get any | 449 // If the object is undefined or null it's illegal to try to get any |
| 450 // of its properties; throw a TypeError in that case. | 450 // of its properties; throw a TypeError in that case. |
| 451 if (object->IsUndefined() || object->IsNull()) { | 451 if (object->IsUndefined() || object->IsNull()) { |
| 452 return TypeError("non_object_property_load", object, name); | 452 return TypeError("non_object_property_load", object, name); |
| 453 } | 453 } |
| 454 | 454 |
| 455 if (FLAG_use_ic) { | 455 if (FLAG_use_ic) { |
| 456 // Use specialized code for getting the length of strings. | 456 // Use specialized code for getting the length of strings and |
| 457 if (object->IsString() && name->Equals(Heap::length_symbol())) { | 457 // string wrapper objects. The length property of string wrapper |
| 458 // objects is read-only and therefore always returns the length of |
| 459 // the underlying string value. See ECMA-262 15.5.5.1. |
| 460 if ((object->IsString() || object->IsStringWrapper()) && |
| 461 name->Equals(Heap::length_symbol())) { |
| 462 HandleScope scope; |
| 463 // Get the string if we have a string wrapper object. |
| 464 if (object->IsJSValue()) { |
| 465 object = Handle<Object>(Handle<JSValue>::cast(object)->value()); |
| 466 } |
| 458 #ifdef DEBUG | 467 #ifdef DEBUG |
| 459 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /string]\n"); | 468 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /string]\n"); |
| 460 #endif | 469 #endif |
| 461 Code* target = NULL; | 470 Code* target = NULL; |
| 462 if (object->IsShortString()) { | 471 target = Builtins::builtin(Builtins::LoadIC_StringLength); |
| 463 target = Builtins::builtin(Builtins::LoadIC_ShortStringLength); | |
| 464 } else if (object->IsMediumString()) { | |
| 465 target = Builtins::builtin(Builtins::LoadIC_MediumStringLength); | |
| 466 } else { | |
| 467 ASSERT(object->IsLongString()); | |
| 468 target = Builtins::builtin(Builtins::LoadIC_LongStringLength); | |
| 469 } | |
| 470 set_target(target); | 472 set_target(target); |
| 471 StubCache::Set(*name, HeapObject::cast(*object)->map(), target); | 473 StubCache::Set(*name, HeapObject::cast(*object)->map(), target); |
| 472 return Smi::FromInt(String::cast(*object)->length()); | 474 return Smi::FromInt(String::cast(*object)->length()); |
| 473 } | 475 } |
| 474 | 476 |
| 475 // Use specialized code for getting the length of arrays. | 477 // Use specialized code for getting the length of arrays. |
| 476 if (object->IsJSArray() && name->Equals(Heap::length_symbol())) { | 478 if (object->IsJSArray() && name->Equals(Heap::length_symbol())) { |
| 477 #ifdef DEBUG | 479 #ifdef DEBUG |
| 478 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /array]\n"); | 480 if (FLAG_trace_ic) PrintF("[LoadIC : +#length /array]\n"); |
| 479 #endif | 481 #endif |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 // of its properties; throw a TypeError in that case. | 632 // of its properties; throw a TypeError in that case. |
| 631 if (object->IsUndefined() || object->IsNull()) { | 633 if (object->IsUndefined() || object->IsNull()) { |
| 632 return TypeError("non_object_property_load", object, name); | 634 return TypeError("non_object_property_load", object, name); |
| 633 } | 635 } |
| 634 | 636 |
| 635 if (FLAG_use_ic) { | 637 if (FLAG_use_ic) { |
| 636 // Use specialized code for getting the length of strings. | 638 // Use specialized code for getting the length of strings. |
| 637 if (object->IsString() && name->Equals(Heap::length_symbol())) { | 639 if (object->IsString() && name->Equals(Heap::length_symbol())) { |
| 638 Handle<String> string = Handle<String>::cast(object); | 640 Handle<String> string = Handle<String>::cast(object); |
| 639 Object* code = NULL; | 641 Object* code = NULL; |
| 640 if (string->IsShortString()) { | 642 code = StubCache::ComputeKeyedLoadStringLength(*name, *string); |
| 641 code = StubCache::ComputeKeyedLoadShortStringLength(*name, *string); | |
| 642 } else if (string->IsMediumString()) { | |
| 643 code = | |
| 644 StubCache::ComputeKeyedLoadMediumStringLength(*name, *string); | |
| 645 } else { | |
| 646 ASSERT(string->IsLongString()); | |
| 647 code = StubCache::ComputeKeyedLoadLongStringLength(*name, *string); | |
| 648 } | |
| 649 if (code->IsFailure()) return code; | 643 if (code->IsFailure()) return code; |
| 650 set_target(Code::cast(code)); | 644 set_target(Code::cast(code)); |
| 651 #ifdef DEBUG | 645 #ifdef DEBUG |
| 652 TraceIC("KeyedLoadIC", name, state, target()); | 646 TraceIC("KeyedLoadIC", name, state, target()); |
| 653 #endif | 647 #endif |
| 654 return Smi::FromInt(string->length()); | 648 return Smi::FromInt(string->length()); |
| 655 } | 649 } |
| 656 | 650 |
| 657 // Use specialized code for getting the length of arrays. | 651 // Use specialized code for getting the length of arrays. |
| 658 if (object->IsJSArray() && name->Equals(Heap::length_symbol())) { | 652 if (object->IsJSArray() && name->Equals(Heap::length_symbol())) { |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 #undef ADDR | 1186 #undef ADDR |
| 1193 }; | 1187 }; |
| 1194 | 1188 |
| 1195 | 1189 |
| 1196 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 1190 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
| 1197 return IC_utilities[id]; | 1191 return IC_utilities[id]; |
| 1198 } | 1192 } |
| 1199 | 1193 |
| 1200 | 1194 |
| 1201 } } // namespace v8::internal | 1195 } } // namespace v8::internal |
| OLD | NEW |