| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 240 |
| 241 Handle<Object> args[] = { receiver, name }; | 241 Handle<Object> args[] = { receiver, name }; |
| 242 Handle<Object> result = CallTrap( | 242 Handle<Object> result = CallTrap( |
| 243 "get", isolate->derived_get_trap(), ARRAY_SIZE(args), args); | 243 "get", isolate->derived_get_trap(), ARRAY_SIZE(args), args); |
| 244 if (isolate->has_pending_exception()) return Failure::Exception(); | 244 if (isolate->has_pending_exception()) return Failure::Exception(); |
| 245 | 245 |
| 246 return *result; | 246 return *result; |
| 247 } | 247 } |
| 248 | 248 |
| 249 | 249 |
| 250 Handle<Object> Object::GetProperty(Handle<Object> object, Handle<String> name) { |
| 251 // TODO(rossberg): The index test should not be here but in the GetProperty |
| 252 // method (or somewhere else entirely). Needs more global clean-up. |
| 253 uint32_t index; |
| 254 if (name->AsArrayIndex(&index)) return GetElement(object, index); |
| 255 Isolate* isolate = object->IsHeapObject() |
| 256 ? Handle<HeapObject>::cast(object)->GetIsolate() |
| 257 : Isolate::Current(); |
| 258 CALL_HEAP_FUNCTION(isolate, object->GetProperty(*name), Object); |
| 259 } |
| 260 |
| 261 |
| 250 Handle<Object> Object::GetElement(Handle<Object> object, uint32_t index) { | 262 Handle<Object> Object::GetElement(Handle<Object> object, uint32_t index) { |
| 251 Isolate* isolate = object->IsHeapObject() | 263 Isolate* isolate = object->IsHeapObject() |
| 252 ? Handle<HeapObject>::cast(object)->GetIsolate() | 264 ? Handle<HeapObject>::cast(object)->GetIsolate() |
| 253 : Isolate::Current(); | 265 : Isolate::Current(); |
| 254 CALL_HEAP_FUNCTION(isolate, object->GetElement(index), Object); | 266 CALL_HEAP_FUNCTION(isolate, object->GetElement(index), Object); |
| 255 } | 267 } |
| 256 | 268 |
| 257 | 269 |
| 258 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver, | 270 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver, |
| 259 uint32_t index) { | 271 uint32_t index) { |
| (...skipping 3063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3323 ASSERT(proto->IsJSGlobalObject()); | 3335 ASSERT(proto->IsJSGlobalObject()); |
| 3324 return JSObject::cast(proto)->GetElementAttributeWithReceiver( | 3336 return JSObject::cast(proto)->GetElementAttributeWithReceiver( |
| 3325 receiver, index, continue_search); | 3337 receiver, index, continue_search); |
| 3326 } | 3338 } |
| 3327 | 3339 |
| 3328 // Check for lookup interceptor except when bootstrapping. | 3340 // Check for lookup interceptor except when bootstrapping. |
| 3329 if (HasIndexedInterceptor() && !isolate->bootstrapper()->IsActive()) { | 3341 if (HasIndexedInterceptor() && !isolate->bootstrapper()->IsActive()) { |
| 3330 return GetElementAttributeWithInterceptor(receiver, index, continue_search); | 3342 return GetElementAttributeWithInterceptor(receiver, index, continue_search); |
| 3331 } | 3343 } |
| 3332 | 3344 |
| 3345 // Handle [] on String objects. |
| 3346 if (this->IsStringObjectWithCharacterAt(index)) { |
| 3347 return static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 3348 } |
| 3349 |
| 3333 return GetElementAttributeWithoutInterceptor( | 3350 return GetElementAttributeWithoutInterceptor( |
| 3334 receiver, index, continue_search); | 3351 receiver, index, continue_search); |
| 3335 } | 3352 } |
| 3336 | 3353 |
| 3337 | 3354 |
| 3338 PropertyAttributes JSObject::GetElementAttributeWithInterceptor( | 3355 PropertyAttributes JSObject::GetElementAttributeWithInterceptor( |
| 3339 JSReceiver* receiver, uint32_t index, bool continue_search) { | 3356 JSReceiver* receiver, uint32_t index, bool continue_search) { |
| 3340 Isolate* isolate = GetIsolate(); | 3357 Isolate* isolate = GetIsolate(); |
| 3341 // Make sure that the top context does not change when doing | 3358 // Make sure that the top context does not change when doing |
| 3342 // callbacks or interceptor calls. | 3359 // callbacks or interceptor calls. |
| (...skipping 6274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9617 PropertyType JSObject::GetLocalElementType(uint32_t index) { | 9634 PropertyType JSObject::GetLocalElementType(uint32_t index) { |
| 9618 return GetElementsAccessor()->GetType(this, this, index); | 9635 return GetElementsAccessor()->GetType(this, this, index); |
| 9619 } | 9636 } |
| 9620 | 9637 |
| 9621 | 9638 |
| 9622 AccessorPair* JSObject::GetLocalPropertyAccessorPair(String* name) { | 9639 AccessorPair* JSObject::GetLocalPropertyAccessorPair(String* name) { |
| 9623 uint32_t index = 0; | 9640 uint32_t index = 0; |
| 9624 if (name->AsArrayIndex(&index)) { | 9641 if (name->AsArrayIndex(&index)) { |
| 9625 return GetLocalElementAccessorPair(index); | 9642 return GetLocalElementAccessorPair(index); |
| 9626 } | 9643 } |
| 9644 |
| 9627 LookupResult lookup(GetIsolate()); | 9645 LookupResult lookup(GetIsolate()); |
| 9628 LocalLookup(name, &lookup); | 9646 LocalLookupRealNamedProperty(name, &lookup); |
| 9647 |
| 9629 if (lookup.IsPropertyCallbacks() && | 9648 if (lookup.IsPropertyCallbacks() && |
| 9630 lookup.GetCallbackObject()->IsAccessorPair()) { | 9649 lookup.GetCallbackObject()->IsAccessorPair()) { |
| 9631 return AccessorPair::cast(lookup.GetCallbackObject()); | 9650 return AccessorPair::cast(lookup.GetCallbackObject()); |
| 9632 } | 9651 } |
| 9633 return NULL; | 9652 return NULL; |
| 9634 } | 9653 } |
| 9635 | 9654 |
| 9636 | 9655 |
| 9637 AccessorPair* JSObject::GetLocalElementAccessorPair(uint32_t index) { | 9656 AccessorPair* JSObject::GetLocalElementAccessorPair(uint32_t index) { |
| 9657 if (IsJSGlobalProxy()) { |
| 9658 Object* proto = GetPrototype(); |
| 9659 if (proto->IsNull()) return NULL; |
| 9660 ASSERT(proto->IsJSGlobalObject()); |
| 9661 return JSObject::cast(proto)->GetLocalElementAccessorPair(index); |
| 9662 } |
| 9663 |
| 9664 // Check for lookup interceptor. |
| 9665 if (HasIndexedInterceptor()) return NULL; |
| 9666 |
| 9638 return GetElementsAccessor()->GetAccessorPair(this, this, index); | 9667 return GetElementsAccessor()->GetAccessorPair(this, this, index); |
| 9639 } | 9668 } |
| 9640 | 9669 |
| 9641 | 9670 |
| 9642 JSObject::LocalElementKind JSObject::GetLocalElementKind(uint32_t index) { | |
| 9643 // Check access rights if needed. | |
| 9644 if (IsAccessCheckNeeded()) { | |
| 9645 Heap* heap = GetHeap(); | |
| 9646 if (!heap->isolate()->MayIndexedAccess(this, index, v8::ACCESS_HAS)) { | |
| 9647 heap->isolate()->ReportFailedAccessCheck(this, v8::ACCESS_HAS); | |
| 9648 return UNDEFINED_ELEMENT; | |
| 9649 } | |
| 9650 } | |
| 9651 | |
| 9652 if (IsJSGlobalProxy()) { | |
| 9653 Object* proto = GetPrototype(); | |
| 9654 if (proto->IsNull()) return UNDEFINED_ELEMENT; | |
| 9655 ASSERT(proto->IsJSGlobalObject()); | |
| 9656 return JSObject::cast(proto)->GetLocalElementKind(index); | |
| 9657 } | |
| 9658 | |
| 9659 // Check for lookup interceptor | |
| 9660 if (HasIndexedInterceptor()) { | |
| 9661 return GetElementAttributeWithInterceptor(this, index, false) != ABSENT | |
| 9662 ? INTERCEPTED_ELEMENT : UNDEFINED_ELEMENT; | |
| 9663 } | |
| 9664 | |
| 9665 // Handle [] on String objects. | |
| 9666 if (this->IsStringObjectWithCharacterAt(index)) { | |
| 9667 return STRING_CHARACTER_ELEMENT; | |
| 9668 } | |
| 9669 | |
| 9670 switch (GetElementsKind()) { | |
| 9671 case FAST_SMI_ELEMENTS: | |
| 9672 case FAST_ELEMENTS: | |
| 9673 case FAST_HOLEY_SMI_ELEMENTS: | |
| 9674 case FAST_HOLEY_ELEMENTS: { | |
| 9675 uint32_t length = IsJSArray() ? | |
| 9676 static_cast<uint32_t> | |
| 9677 (Smi::cast(JSArray::cast(this)->length())->value()) : | |
| 9678 static_cast<uint32_t>(FixedArray::cast(elements())->length()); | |
| 9679 if ((index < length) && | |
| 9680 !FixedArray::cast(elements())->get(index)->IsTheHole()) { | |
| 9681 return FAST_ELEMENT; | |
| 9682 } | |
| 9683 break; | |
| 9684 } | |
| 9685 case FAST_DOUBLE_ELEMENTS: | |
| 9686 case FAST_HOLEY_DOUBLE_ELEMENTS: { | |
| 9687 uint32_t length = IsJSArray() ? | |
| 9688 static_cast<uint32_t> | |
| 9689 (Smi::cast(JSArray::cast(this)->length())->value()) : | |
| 9690 static_cast<uint32_t>(FixedDoubleArray::cast(elements())->length()); | |
| 9691 if ((index < length) && | |
| 9692 !FixedDoubleArray::cast(elements())->is_the_hole(index)) { | |
| 9693 return FAST_ELEMENT; | |
| 9694 } | |
| 9695 break; | |
| 9696 } | |
| 9697 case EXTERNAL_PIXEL_ELEMENTS: { | |
| 9698 ExternalPixelArray* pixels = ExternalPixelArray::cast(elements()); | |
| 9699 if (index < static_cast<uint32_t>(pixels->length())) return FAST_ELEMENT; | |
| 9700 break; | |
| 9701 } | |
| 9702 case EXTERNAL_BYTE_ELEMENTS: | |
| 9703 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | |
| 9704 case EXTERNAL_SHORT_ELEMENTS: | |
| 9705 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | |
| 9706 case EXTERNAL_INT_ELEMENTS: | |
| 9707 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | |
| 9708 case EXTERNAL_FLOAT_ELEMENTS: | |
| 9709 case EXTERNAL_DOUBLE_ELEMENTS: { | |
| 9710 ExternalArray* array = ExternalArray::cast(elements()); | |
| 9711 if (index < static_cast<uint32_t>(array->length())) return FAST_ELEMENT; | |
| 9712 break; | |
| 9713 } | |
| 9714 case DICTIONARY_ELEMENTS: { | |
| 9715 if (element_dictionary()->FindEntry(index) != | |
| 9716 SeededNumberDictionary::kNotFound) { | |
| 9717 return DICTIONARY_ELEMENT; | |
| 9718 } | |
| 9719 break; | |
| 9720 } | |
| 9721 case NON_STRICT_ARGUMENTS_ELEMENTS: { | |
| 9722 // Aliased parameters and non-aliased elements in a fast backing store | |
| 9723 // behave as FAST_ELEMENT. Non-aliased elements in a dictionary | |
| 9724 // backing store behave as DICTIONARY_ELEMENT. | |
| 9725 FixedArray* parameter_map = FixedArray::cast(elements()); | |
| 9726 uint32_t length = parameter_map->length(); | |
| 9727 Object* probe = | |
| 9728 index < (length - 2) ? parameter_map->get(index + 2) : NULL; | |
| 9729 if (probe != NULL && !probe->IsTheHole()) return FAST_ELEMENT; | |
| 9730 // If not aliased, check the arguments. | |
| 9731 FixedArray* arguments = FixedArray::cast(parameter_map->get(1)); | |
| 9732 if (arguments->IsDictionary()) { | |
| 9733 SeededNumberDictionary* dictionary = | |
| 9734 SeededNumberDictionary::cast(arguments); | |
| 9735 if (dictionary->FindEntry(index) != SeededNumberDictionary::kNotFound) { | |
| 9736 return DICTIONARY_ELEMENT; | |
| 9737 } | |
| 9738 } else { | |
| 9739 length = arguments->length(); | |
| 9740 probe = (index < length) ? arguments->get(index) : NULL; | |
| 9741 if (probe != NULL && !probe->IsTheHole()) return FAST_ELEMENT; | |
| 9742 } | |
| 9743 break; | |
| 9744 } | |
| 9745 } | |
| 9746 | |
| 9747 return UNDEFINED_ELEMENT; | |
| 9748 } | |
| 9749 | |
| 9750 | |
| 9751 MaybeObject* JSObject::SetElementWithInterceptor(uint32_t index, | 9671 MaybeObject* JSObject::SetElementWithInterceptor(uint32_t index, |
| 9752 Object* value, | 9672 Object* value, |
| 9753 PropertyAttributes attributes, | 9673 PropertyAttributes attributes, |
| 9754 StrictModeFlag strict_mode, | 9674 StrictModeFlag strict_mode, |
| 9755 bool check_prototype, | 9675 bool check_prototype, |
| 9756 SetPropertyMode set_mode) { | 9676 SetPropertyMode set_mode) { |
| 9757 Isolate* isolate = GetIsolate(); | 9677 Isolate* isolate = GetIsolate(); |
| 9758 // Make sure that the top context does not change when doing | 9678 // Make sure that the top context does not change when doing |
| 9759 // callbacks or interceptor calls. | 9679 // callbacks or interceptor calls. |
| 9760 AssertNoContextChange ncc; | 9680 AssertNoContextChange ncc; |
| (...skipping 4182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13943 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13863 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
| 13944 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13864 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
| 13945 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13865 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
| 13946 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13866 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
| 13947 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13867 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
| 13948 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13868 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
| 13949 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13869 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
| 13950 } | 13870 } |
| 13951 | 13871 |
| 13952 } } // namespace v8::internal | 13872 } } // namespace v8::internal |
| OLD | NEW |