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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 JSObject* holder, | 417 JSObject* holder, |
418 uint32_t key, | 418 uint32_t key, |
419 FixedArrayBase* backing_store) { | 419 FixedArrayBase* backing_store) { |
420 if (backing_store == NULL) { | 420 if (backing_store == NULL) { |
421 backing_store = holder->elements(); | 421 backing_store = holder->elements(); |
422 } | 422 } |
423 return ElementsAccessorSubclass::HasElementImpl( | 423 return ElementsAccessorSubclass::HasElementImpl( |
424 receiver, holder, key, BackingStore::cast(backing_store)); | 424 receiver, holder, key, BackingStore::cast(backing_store)); |
425 } | 425 } |
426 | 426 |
427 virtual MaybeObject* Get(Object* receiver, | 427 MUST_USE_RESULT virtual MaybeObject* Get(Object* receiver, |
428 JSObject* holder, | 428 JSObject* holder, |
429 uint32_t key, | 429 uint32_t key, |
430 FixedArrayBase* backing_store) { | 430 FixedArrayBase* backing_store) { |
431 if (backing_store == NULL) { | 431 if (backing_store == NULL) { |
432 backing_store = holder->elements(); | 432 backing_store = holder->elements(); |
433 } | 433 } |
434 return ElementsAccessorSubclass::GetImpl( | 434 return ElementsAccessorSubclass::GetImpl( |
435 receiver, holder, key, BackingStore::cast(backing_store)); | 435 receiver, holder, key, BackingStore::cast(backing_store)); |
436 } | 436 } |
437 | 437 |
438 static MaybeObject* GetImpl(Object* receiver, | 438 MUST_USE_RESULT static MaybeObject* GetImpl(Object* receiver, |
439 JSObject* obj, | 439 JSObject* obj, |
440 uint32_t key, | 440 uint32_t key, |
441 BackingStore* backing_store) { | 441 BackingStore* backing_store) { |
442 return (key < ElementsAccessorSubclass::GetCapacityImpl(backing_store)) | 442 return (key < ElementsAccessorSubclass::GetCapacityImpl(backing_store)) |
443 ? backing_store->get(key) | 443 ? backing_store->get(key) |
444 : backing_store->GetHeap()->the_hole_value(); | 444 : backing_store->GetHeap()->the_hole_value(); |
445 } | 445 } |
446 | 446 |
447 virtual MaybeObject* SetLength(JSArray* array, | 447 MUST_USE_RESULT virtual MaybeObject* SetLength(JSArray* array, |
448 Object* length) { | 448 Object* length) { |
449 return ElementsAccessorSubclass::SetLengthImpl( | 449 return ElementsAccessorSubclass::SetLengthImpl( |
450 array, length, BackingStore::cast(array->elements())); | 450 array, length, BackingStore::cast(array->elements())); |
451 } | 451 } |
452 | 452 |
453 static MaybeObject* SetLengthImpl(JSObject* obj, | 453 MUST_USE_RESULT static MaybeObject* SetLengthImpl( |
454 Object* length, | 454 JSObject* obj, |
455 BackingStore* backing_store); | 455 Object* length, |
| 456 BackingStore* backing_store); |
456 | 457 |
457 virtual MaybeObject* SetCapacityAndLength(JSArray* array, | 458 MUST_USE_RESULT virtual MaybeObject* SetCapacityAndLength(JSArray* array, |
458 int capacity, | 459 int capacity, |
459 int length) { | 460 int length) { |
460 return ElementsAccessorSubclass::SetFastElementsCapacityAndLength( | 461 return ElementsAccessorSubclass::SetFastElementsCapacityAndLength( |
461 array, | 462 array, |
462 capacity, | 463 capacity, |
463 length); | 464 length); |
464 } | 465 } |
465 | 466 |
466 static MaybeObject* SetFastElementsCapacityAndLength(JSObject* obj, | 467 MUST_USE_RESULT static MaybeObject* SetFastElementsCapacityAndLength( |
467 int capacity, | 468 JSObject* obj, |
468 int length) { | 469 int capacity, |
| 470 int length) { |
469 UNIMPLEMENTED(); | 471 UNIMPLEMENTED(); |
470 return obj; | 472 return obj; |
471 } | 473 } |
472 | 474 |
473 virtual MaybeObject* Delete(JSObject* obj, | 475 MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* obj, |
474 uint32_t key, | 476 uint32_t key, |
475 JSReceiver::DeleteMode mode) = 0; | 477 JSReceiver::DeleteMode mode) = 0; |
476 | 478 |
477 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 479 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
478 uint32_t from_start, | 480 uint32_t from_start, |
479 FixedArrayBase* to, | 481 FixedArrayBase* to, |
480 ElementsKind to_kind, | 482 ElementsKind to_kind, |
481 uint32_t to_start, | 483 uint32_t to_start, |
482 int copy_size) { | 484 int copy_size) { |
483 UNREACHABLE(); | 485 UNREACHABLE(); |
484 return NULL; | 486 return NULL; |
485 } | 487 } |
486 | 488 |
487 virtual MaybeObject* CopyElements(JSObject* from_holder, | 489 MUST_USE_RESULT virtual MaybeObject* CopyElements(JSObject* from_holder, |
488 uint32_t from_start, | 490 uint32_t from_start, |
489 FixedArrayBase* to, | 491 FixedArrayBase* to, |
490 ElementsKind to_kind, | 492 ElementsKind to_kind, |
491 uint32_t to_start, | 493 uint32_t to_start, |
492 int copy_size, | 494 int copy_size, |
493 FixedArrayBase* from) { | 495 FixedArrayBase* from) { |
494 if (from == NULL) { | 496 if (from == NULL) { |
495 from = from_holder->elements(); | 497 from = from_holder->elements(); |
496 } | 498 } |
497 if (from->length() == 0) { | 499 if (from->length() == 0) { |
498 return from; | 500 return from; |
499 } | 501 } |
500 return ElementsAccessorSubclass::CopyElementsImpl( | 502 return ElementsAccessorSubclass::CopyElementsImpl( |
501 from, from_start, to, to_kind, to_start, copy_size); | 503 from, from_start, to, to_kind, to_start, copy_size); |
502 } | 504 } |
503 | 505 |
504 virtual MaybeObject* AddElementsToFixedArray(Object* receiver, | 506 MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray( |
505 JSObject* holder, | 507 Object* receiver, |
506 FixedArray* to, | 508 JSObject* holder, |
507 FixedArrayBase* from) { | 509 FixedArray* to, |
| 510 FixedArrayBase* from) { |
508 int len0 = to->length(); | 511 int len0 = to->length(); |
509 #ifdef DEBUG | 512 #ifdef DEBUG |
510 if (FLAG_enable_slow_asserts) { | 513 if (FLAG_enable_slow_asserts) { |
511 for (int i = 0; i < len0; i++) { | 514 for (int i = 0; i < len0; i++) { |
512 ASSERT(!to->get(i)->IsTheHole()); | 515 ASSERT(!to->get(i)->IsTheHole()); |
513 } | 516 } |
514 } | 517 } |
515 #endif | 518 #endif |
516 if (from == NULL) { | 519 if (from == NULL) { |
517 from = holder->elements(); | 520 from = holder->elements(); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 explicit ExternalElementsAccessor(const char* name) | 862 explicit ExternalElementsAccessor(const char* name) |
860 : ElementsAccessorBase<ExternalElementsAccessorSubclass, | 863 : ElementsAccessorBase<ExternalElementsAccessorSubclass, |
861 ElementsKindTraits<Kind> >(name) {} | 864 ElementsKindTraits<Kind> >(name) {} |
862 | 865 |
863 protected: | 866 protected: |
864 typedef typename ElementsKindTraits<Kind>::BackingStore BackingStore; | 867 typedef typename ElementsKindTraits<Kind>::BackingStore BackingStore; |
865 | 868 |
866 friend class ElementsAccessorBase<ExternalElementsAccessorSubclass, | 869 friend class ElementsAccessorBase<ExternalElementsAccessorSubclass, |
867 ElementsKindTraits<Kind> >; | 870 ElementsKindTraits<Kind> >; |
868 | 871 |
869 static MaybeObject* GetImpl(Object* receiver, | 872 MUST_USE_RESULT static MaybeObject* GetImpl(Object* receiver, |
870 JSObject* obj, | 873 JSObject* obj, |
871 uint32_t key, | 874 uint32_t key, |
872 BackingStore* backing_store) { | 875 BackingStore* backing_store) { |
873 return | 876 return |
874 key < ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store) | 877 key < ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store) |
875 ? backing_store->get(key) | 878 ? backing_store->get(key) |
876 : backing_store->GetHeap()->undefined_value(); | 879 : backing_store->GetHeap()->undefined_value(); |
877 } | 880 } |
878 | 881 |
879 static MaybeObject* SetLengthImpl(JSObject* obj, | 882 MUST_USE_RESULT static MaybeObject* SetLengthImpl( |
880 Object* length, | 883 JSObject* obj, |
881 BackingStore* backing_store) { | 884 Object* length, |
| 885 BackingStore* backing_store) { |
882 // External arrays do not support changing their length. | 886 // External arrays do not support changing their length. |
883 UNREACHABLE(); | 887 UNREACHABLE(); |
884 return obj; | 888 return obj; |
885 } | 889 } |
886 | 890 |
887 virtual MaybeObject* Delete(JSObject* obj, | 891 MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* obj, |
888 uint32_t key, | 892 uint32_t key, |
889 JSReceiver::DeleteMode mode) { | 893 JSReceiver::DeleteMode mode) { |
890 // External arrays always ignore deletes. | 894 // External arrays always ignore deletes. |
891 return obj->GetHeap()->true_value(); | 895 return obj->GetHeap()->true_value(); |
892 } | 896 } |
893 | 897 |
894 static bool HasElementImpl(Object* receiver, | 898 static bool HasElementImpl(Object* receiver, |
895 JSObject* holder, | 899 JSObject* holder, |
896 uint32_t key, | 900 uint32_t key, |
897 BackingStore* backing_store) { | 901 BackingStore* backing_store) { |
898 uint32_t capacity = | 902 uint32_t capacity = |
899 ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store); | 903 ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 class DictionaryElementsAccessor | 999 class DictionaryElementsAccessor |
996 : public ElementsAccessorBase<DictionaryElementsAccessor, | 1000 : public ElementsAccessorBase<DictionaryElementsAccessor, |
997 ElementsKindTraits<DICTIONARY_ELEMENTS> > { | 1001 ElementsKindTraits<DICTIONARY_ELEMENTS> > { |
998 public: | 1002 public: |
999 explicit DictionaryElementsAccessor(const char* name) | 1003 explicit DictionaryElementsAccessor(const char* name) |
1000 : ElementsAccessorBase<DictionaryElementsAccessor, | 1004 : ElementsAccessorBase<DictionaryElementsAccessor, |
1001 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} | 1005 ElementsKindTraits<DICTIONARY_ELEMENTS> >(name) {} |
1002 | 1006 |
1003 // Adjusts the length of the dictionary backing store and returns the new | 1007 // Adjusts the length of the dictionary backing store and returns the new |
1004 // length according to ES5 section 15.4.5.2 behavior. | 1008 // length according to ES5 section 15.4.5.2 behavior. |
1005 static MaybeObject* SetLengthWithoutNormalize(SeededNumberDictionary* dict, | 1009 MUST_USE_RESULT static MaybeObject* SetLengthWithoutNormalize( |
1006 JSArray* array, | 1010 SeededNumberDictionary* dict, |
1007 Object* length_object, | 1011 JSArray* array, |
1008 uint32_t length) { | 1012 Object* length_object, |
| 1013 uint32_t length) { |
1009 if (length == 0) { | 1014 if (length == 0) { |
1010 // If the length of a slow array is reset to zero, we clear | 1015 // If the length of a slow array is reset to zero, we clear |
1011 // the array and flush backing storage. This has the added | 1016 // the array and flush backing storage. This has the added |
1012 // benefit that the array returns to fast mode. | 1017 // benefit that the array returns to fast mode. |
1013 Object* obj; | 1018 Object* obj; |
1014 MaybeObject* maybe_obj = array->ResetElements(); | 1019 MaybeObject* maybe_obj = array->ResetElements(); |
1015 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 1020 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
1016 } else { | 1021 } else { |
1017 uint32_t new_length = length; | 1022 uint32_t new_length = length; |
1018 uint32_t old_length = static_cast<uint32_t>(array->length()->Number()); | 1023 uint32_t old_length = static_cast<uint32_t>(array->length()->Number()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 } | 1055 } |
1051 } | 1056 } |
1052 | 1057 |
1053 // Update the number of elements. | 1058 // Update the number of elements. |
1054 dict->ElementsRemoved(removed_entries); | 1059 dict->ElementsRemoved(removed_entries); |
1055 } | 1060 } |
1056 } | 1061 } |
1057 return length_object; | 1062 return length_object; |
1058 } | 1063 } |
1059 | 1064 |
1060 static MaybeObject* DeleteCommon(JSObject* obj, | 1065 MUST_USE_RESULT static MaybeObject* DeleteCommon( |
1061 uint32_t key, | 1066 JSObject* obj, |
1062 JSReceiver::DeleteMode mode) { | 1067 uint32_t key, |
| 1068 JSReceiver::DeleteMode mode) { |
1063 Isolate* isolate = obj->GetIsolate(); | 1069 Isolate* isolate = obj->GetIsolate(); |
1064 Heap* heap = isolate->heap(); | 1070 Heap* heap = isolate->heap(); |
1065 FixedArray* backing_store = FixedArray::cast(obj->elements()); | 1071 FixedArray* backing_store = FixedArray::cast(obj->elements()); |
1066 bool is_arguments = | 1072 bool is_arguments = |
1067 (obj->GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS); | 1073 (obj->GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS); |
1068 if (is_arguments) { | 1074 if (is_arguments) { |
1069 backing_store = FixedArray::cast(backing_store->get(1)); | 1075 backing_store = FixedArray::cast(backing_store->get(1)); |
1070 } | 1076 } |
1071 SeededNumberDictionary* dictionary = | 1077 SeededNumberDictionary* dictionary = |
1072 SeededNumberDictionary::cast(backing_store); | 1078 SeededNumberDictionary::cast(backing_store); |
(...skipping 22 matching lines...) Expand all Loading... |
1095 Handle<Object> args[2] = { name, holder }; | 1101 Handle<Object> args[2] = { name, holder }; |
1096 Handle<Object> error = | 1102 Handle<Object> error = |
1097 isolate->factory()->NewTypeError("strict_delete_property", | 1103 isolate->factory()->NewTypeError("strict_delete_property", |
1098 HandleVector(args, 2)); | 1104 HandleVector(args, 2)); |
1099 return isolate->Throw(*error); | 1105 return isolate->Throw(*error); |
1100 } | 1106 } |
1101 } | 1107 } |
1102 return heap->true_value(); | 1108 return heap->true_value(); |
1103 } | 1109 } |
1104 | 1110 |
1105 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 1111 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
1106 uint32_t from_start, | 1112 uint32_t from_start, |
1107 FixedArrayBase* to, | 1113 FixedArrayBase* to, |
1108 ElementsKind to_kind, | 1114 ElementsKind to_kind, |
1109 uint32_t to_start, | 1115 uint32_t to_start, |
1110 int copy_size) { | 1116 int copy_size) { |
1111 switch (to_kind) { | 1117 switch (to_kind) { |
1112 case FAST_SMI_ONLY_ELEMENTS: | 1118 case FAST_SMI_ONLY_ELEMENTS: |
1113 case FAST_ELEMENTS: | 1119 case FAST_ELEMENTS: |
1114 CopyDictionaryToObjectElements( | 1120 CopyDictionaryToObjectElements( |
1115 SeededNumberDictionary::cast(from), from_start, | 1121 SeededNumberDictionary::cast(from), from_start, |
1116 FixedArray::cast(to), to_kind, to_start, copy_size); | 1122 FixedArray::cast(to), to_kind, to_start, copy_size); |
1117 return from; | 1123 return from; |
1118 case FAST_DOUBLE_ELEMENTS: | 1124 case FAST_DOUBLE_ELEMENTS: |
1119 CopyDictionaryToDoubleElements( | 1125 CopyDictionaryToDoubleElements( |
1120 SeededNumberDictionary::cast(from), from_start, | 1126 SeededNumberDictionary::cast(from), from_start, |
1121 FixedDoubleArray::cast(to), to_start, copy_size); | 1127 FixedDoubleArray::cast(to), to_start, copy_size); |
1122 return from; | 1128 return from; |
1123 default: | 1129 default: |
1124 UNREACHABLE(); | 1130 UNREACHABLE(); |
1125 } | 1131 } |
1126 return to->GetHeap()->undefined_value(); | 1132 return to->GetHeap()->undefined_value(); |
1127 } | 1133 } |
1128 | 1134 |
1129 | 1135 |
1130 protected: | 1136 protected: |
1131 friend class ElementsAccessorBase<DictionaryElementsAccessor, | 1137 friend class ElementsAccessorBase<DictionaryElementsAccessor, |
1132 ElementsKindTraits<DICTIONARY_ELEMENTS> >; | 1138 ElementsKindTraits<DICTIONARY_ELEMENTS> >; |
1133 | 1139 |
1134 virtual MaybeObject* Delete(JSObject* obj, | 1140 MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* obj, |
1135 uint32_t key, | 1141 uint32_t key, |
1136 JSReceiver::DeleteMode mode) { | 1142 JSReceiver::DeleteMode mode) { |
1137 return DeleteCommon(obj, key, mode); | 1143 return DeleteCommon(obj, key, mode); |
1138 } | 1144 } |
1139 | 1145 |
1140 static MaybeObject* GetImpl(Object* receiver, | 1146 MUST_USE_RESULT static MaybeObject* GetImpl( |
1141 JSObject* obj, | 1147 Object* receiver, |
1142 uint32_t key, | 1148 JSObject* obj, |
1143 SeededNumberDictionary* backing_store) { | 1149 uint32_t key, |
| 1150 SeededNumberDictionary* backing_store) { |
1144 int entry = backing_store->FindEntry(key); | 1151 int entry = backing_store->FindEntry(key); |
1145 if (entry != SeededNumberDictionary::kNotFound) { | 1152 if (entry != SeededNumberDictionary::kNotFound) { |
1146 Object* element = backing_store->ValueAt(entry); | 1153 Object* element = backing_store->ValueAt(entry); |
1147 PropertyDetails details = backing_store->DetailsAt(entry); | 1154 PropertyDetails details = backing_store->DetailsAt(entry); |
1148 if (details.type() == CALLBACKS) { | 1155 if (details.type() == CALLBACKS) { |
1149 return obj->GetElementWithCallback(receiver, | 1156 return obj->GetElementWithCallback(receiver, |
1150 element, | 1157 element, |
1151 key, | 1158 key, |
1152 obj); | 1159 obj); |
1153 } else { | 1160 } else { |
(...skipping 25 matching lines...) Expand all Loading... |
1179 public: | 1186 public: |
1180 explicit NonStrictArgumentsElementsAccessor(const char* name) | 1187 explicit NonStrictArgumentsElementsAccessor(const char* name) |
1181 : ElementsAccessorBase< | 1188 : ElementsAccessorBase< |
1182 NonStrictArgumentsElementsAccessor, | 1189 NonStrictArgumentsElementsAccessor, |
1183 ElementsKindTraits<NON_STRICT_ARGUMENTS_ELEMENTS> >(name) {} | 1190 ElementsKindTraits<NON_STRICT_ARGUMENTS_ELEMENTS> >(name) {} |
1184 protected: | 1191 protected: |
1185 friend class ElementsAccessorBase< | 1192 friend class ElementsAccessorBase< |
1186 NonStrictArgumentsElementsAccessor, | 1193 NonStrictArgumentsElementsAccessor, |
1187 ElementsKindTraits<NON_STRICT_ARGUMENTS_ELEMENTS> >; | 1194 ElementsKindTraits<NON_STRICT_ARGUMENTS_ELEMENTS> >; |
1188 | 1195 |
1189 static MaybeObject* GetImpl(Object* receiver, | 1196 MUST_USE_RESULT static MaybeObject* GetImpl(Object* receiver, |
1190 JSObject* obj, | 1197 JSObject* obj, |
1191 uint32_t key, | 1198 uint32_t key, |
1192 FixedArray* parameter_map) { | 1199 FixedArray* parameter_map) { |
1193 Object* probe = GetParameterMapArg(obj, parameter_map, key); | 1200 Object* probe = GetParameterMapArg(obj, parameter_map, key); |
1194 if (!probe->IsTheHole()) { | 1201 if (!probe->IsTheHole()) { |
1195 Context* context = Context::cast(parameter_map->get(0)); | 1202 Context* context = Context::cast(parameter_map->get(0)); |
1196 int context_index = Smi::cast(probe)->value(); | 1203 int context_index = Smi::cast(probe)->value(); |
1197 ASSERT(!context->get(context_index)->IsTheHole()); | 1204 ASSERT(!context->get(context_index)->IsTheHole()); |
1198 return context->get(context_index); | 1205 return context->get(context_index); |
1199 } else { | 1206 } else { |
1200 // Object is not mapped, defer to the arguments. | 1207 // Object is not mapped, defer to the arguments. |
1201 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); | 1208 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); |
1202 MaybeObject* maybe_result = ElementsAccessor::ForArray(arguments)->Get( | 1209 MaybeObject* maybe_result = ElementsAccessor::ForArray(arguments)->Get( |
1203 receiver, obj, key, arguments); | 1210 receiver, obj, key, arguments); |
1204 Object* result; | 1211 Object* result; |
1205 if (!maybe_result->ToObject(&result)) return maybe_result; | 1212 if (!maybe_result->ToObject(&result)) return maybe_result; |
1206 // Elements of the arguments object in slow mode might be slow aliases. | 1213 // Elements of the arguments object in slow mode might be slow aliases. |
1207 if (result->IsAliasedArgumentsEntry()) { | 1214 if (result->IsAliasedArgumentsEntry()) { |
1208 AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(result); | 1215 AliasedArgumentsEntry* entry = AliasedArgumentsEntry::cast(result); |
1209 Context* context = Context::cast(parameter_map->get(0)); | 1216 Context* context = Context::cast(parameter_map->get(0)); |
1210 int context_index = entry->aliased_context_slot(); | 1217 int context_index = entry->aliased_context_slot(); |
1211 ASSERT(!context->get(context_index)->IsTheHole()); | 1218 ASSERT(!context->get(context_index)->IsTheHole()); |
1212 return context->get(context_index); | 1219 return context->get(context_index); |
1213 } else { | 1220 } else { |
1214 return result; | 1221 return result; |
1215 } | 1222 } |
1216 } | 1223 } |
1217 } | 1224 } |
1218 | 1225 |
1219 static MaybeObject* SetLengthImpl(JSObject* obj, | 1226 MUST_USE_RESULT static MaybeObject* SetLengthImpl( |
1220 Object* length, | 1227 JSObject* obj, |
1221 FixedArray* parameter_map) { | 1228 Object* length, |
| 1229 FixedArray* parameter_map) { |
1222 // TODO(mstarzinger): This was never implemented but will be used once we | 1230 // TODO(mstarzinger): This was never implemented but will be used once we |
1223 // correctly implement [[DefineOwnProperty]] on arrays. | 1231 // correctly implement [[DefineOwnProperty]] on arrays. |
1224 UNIMPLEMENTED(); | 1232 UNIMPLEMENTED(); |
1225 return obj; | 1233 return obj; |
1226 } | 1234 } |
1227 | 1235 |
1228 virtual MaybeObject* Delete(JSObject* obj, | 1236 MUST_USE_RESULT virtual MaybeObject* Delete(JSObject* obj, |
1229 uint32_t key, | 1237 uint32_t key, |
1230 JSReceiver::DeleteMode mode) { | 1238 JSReceiver::DeleteMode mode) { |
1231 FixedArray* parameter_map = FixedArray::cast(obj->elements()); | 1239 FixedArray* parameter_map = FixedArray::cast(obj->elements()); |
1232 Object* probe = GetParameterMapArg(obj, parameter_map, key); | 1240 Object* probe = GetParameterMapArg(obj, parameter_map, key); |
1233 if (!probe->IsTheHole()) { | 1241 if (!probe->IsTheHole()) { |
1234 // TODO(kmillikin): We could check if this was the last aliased | 1242 // TODO(kmillikin): We could check if this was the last aliased |
1235 // parameter, and revert to normal elements in that case. That | 1243 // parameter, and revert to normal elements in that case. That |
1236 // would enable GC of the context. | 1244 // would enable GC of the context. |
1237 parameter_map->set_the_hole(key + 2); | 1245 parameter_map->set_the_hole(key + 2); |
1238 } else { | 1246 } else { |
1239 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); | 1247 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); |
1240 if (arguments->IsDictionary()) { | 1248 if (arguments->IsDictionary()) { |
1241 return DictionaryElementsAccessor::DeleteCommon(obj, key, mode); | 1249 return DictionaryElementsAccessor::DeleteCommon(obj, key, mode); |
1242 } else { | 1250 } else { |
1243 return FastObjectElementsAccessor::DeleteCommon(obj, key); | 1251 return FastObjectElementsAccessor::DeleteCommon(obj, key); |
1244 } | 1252 } |
1245 } | 1253 } |
1246 return obj->GetHeap()->true_value(); | 1254 return obj->GetHeap()->true_value(); |
1247 } | 1255 } |
1248 | 1256 |
1249 static MaybeObject* CopyElementsImpl(FixedArrayBase* from, | 1257 MUST_USE_RESULT static MaybeObject* CopyElementsImpl(FixedArrayBase* from, |
1250 uint32_t from_start, | 1258 uint32_t from_start, |
1251 FixedArrayBase* to, | 1259 FixedArrayBase* to, |
1252 ElementsKind to_kind, | 1260 ElementsKind to_kind, |
1253 uint32_t to_start, | 1261 uint32_t to_start, |
1254 int copy_size) { | 1262 int copy_size) { |
1255 FixedArray* parameter_map = FixedArray::cast(from); | 1263 FixedArray* parameter_map = FixedArray::cast(from); |
1256 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); | 1264 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); |
1257 ElementsAccessor* accessor = ElementsAccessor::ForArray(arguments); | 1265 ElementsAccessor* accessor = ElementsAccessor::ForArray(arguments); |
1258 return accessor->CopyElements(NULL, from_start, to, to_kind, | 1266 return accessor->CopyElements(NULL, from_start, to, to_kind, |
1259 to_start, copy_size, arguments); | 1267 to_start, copy_size, arguments); |
1260 } | 1268 } |
1261 | 1269 |
1262 static uint32_t GetCapacityImpl(FixedArray* parameter_map) { | 1270 static uint32_t GetCapacityImpl(FixedArray* parameter_map) { |
1263 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); | 1271 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); |
1264 return Max(static_cast<uint32_t>(parameter_map->length() - 2), | 1272 return Max(static_cast<uint32_t>(parameter_map->length() - 2), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 | 1355 |
1348 void ElementsAccessor::TearDown() { | 1356 void ElementsAccessor::TearDown() { |
1349 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind]; | 1357 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind]; |
1350 ELEMENTS_LIST(ACCESSOR_DELETE) | 1358 ELEMENTS_LIST(ACCESSOR_DELETE) |
1351 #undef ACCESSOR_DELETE | 1359 #undef ACCESSOR_DELETE |
1352 elements_accessors_ = NULL; | 1360 elements_accessors_ = NULL; |
1353 } | 1361 } |
1354 | 1362 |
1355 | 1363 |
1356 template <typename ElementsAccessorSubclass, typename ElementsKindTraits> | 1364 template <typename ElementsAccessorSubclass, typename ElementsKindTraits> |
1357 MaybeObject* ElementsAccessorBase<ElementsAccessorSubclass, | 1365 MUST_USE_RESULT MaybeObject* ElementsAccessorBase<ElementsAccessorSubclass, |
1358 ElementsKindTraits>:: | 1366 ElementsKindTraits>:: |
1359 SetLengthImpl(JSObject* obj, | 1367 SetLengthImpl(JSObject* obj, |
1360 Object* length, | 1368 Object* length, |
1361 typename ElementsKindTraits::BackingStore* backing_store) { | 1369 typename ElementsKindTraits::BackingStore* backing_store) { |
1362 JSArray* array = JSArray::cast(obj); | 1370 JSArray* array = JSArray::cast(obj); |
1363 | 1371 |
1364 // Fast case: The new length fits into a Smi. | 1372 // Fast case: The new length fits into a Smi. |
1365 MaybeObject* maybe_smi_length = length->ToSmi(); | 1373 MaybeObject* maybe_smi_length = length->ToSmi(); |
1366 Object* smi_length = Smi::FromInt(0); | 1374 Object* smi_length = Smi::FromInt(0); |
1367 if (maybe_smi_length->ToObject(&smi_length) && smi_length->IsSmi()) { | 1375 if (maybe_smi_length->ToObject(&smi_length) && smi_length->IsSmi()) { |
1368 const int value = Smi::cast(smi_length)->value(); | 1376 const int value = Smi::cast(smi_length)->value(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; | 1416 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; |
1409 new_backing_store->set(0, length); | 1417 new_backing_store->set(0, length); |
1410 { MaybeObject* result = array->SetContent(new_backing_store); | 1418 { MaybeObject* result = array->SetContent(new_backing_store); |
1411 if (result->IsFailure()) return result; | 1419 if (result->IsFailure()) return result; |
1412 } | 1420 } |
1413 return array; | 1421 return array; |
1414 } | 1422 } |
1415 | 1423 |
1416 | 1424 |
1417 } } // namespace v8::internal | 1425 } } // namespace v8::internal |
OLD | NEW |