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