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 uint32_t index; | |
252 if (name->AsArrayIndex(&index)) return GetElement(object, index); | |
Michael Starzinger
2012/11/15 21:45:37
See comment in objects-inl.h about that.
With thi
rossberg
2012/11/16 12:50:02
As discussed offline, I put this here mainly for p
Michael Starzinger
2012/11/16 13:18:51
Together with the TODO I can live with this. And t
| |
253 Isolate* isolate = object->IsHeapObject() | |
254 ? Handle<HeapObject>::cast(object)->GetIsolate() | |
255 : Isolate::Current(); | |
256 CALL_HEAP_FUNCTION(isolate, object->GetProperty(*name), Object); | |
257 } | |
258 | |
259 | |
250 Handle<Object> Object::GetElement(Handle<Object> object, uint32_t index) { | 260 Handle<Object> Object::GetElement(Handle<Object> object, uint32_t index) { |
251 Isolate* isolate = object->IsHeapObject() | 261 Isolate* isolate = object->IsHeapObject() |
252 ? Handle<HeapObject>::cast(object)->GetIsolate() | 262 ? Handle<HeapObject>::cast(object)->GetIsolate() |
253 : Isolate::Current(); | 263 : Isolate::Current(); |
254 CALL_HEAP_FUNCTION(isolate, object->GetElement(index), Object); | 264 CALL_HEAP_FUNCTION(isolate, object->GetElement(index), Object); |
255 } | 265 } |
256 | 266 |
257 | 267 |
258 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver, | 268 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver, |
259 uint32_t index) { | 269 uint32_t index) { |
(...skipping 3063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3323 ASSERT(proto->IsJSGlobalObject()); | 3333 ASSERT(proto->IsJSGlobalObject()); |
3324 return JSObject::cast(proto)->GetElementAttributeWithReceiver( | 3334 return JSObject::cast(proto)->GetElementAttributeWithReceiver( |
3325 receiver, index, continue_search); | 3335 receiver, index, continue_search); |
3326 } | 3336 } |
3327 | 3337 |
3328 // Check for lookup interceptor except when bootstrapping. | 3338 // Check for lookup interceptor except when bootstrapping. |
3329 if (HasIndexedInterceptor() && !isolate->bootstrapper()->IsActive()) { | 3339 if (HasIndexedInterceptor() && !isolate->bootstrapper()->IsActive()) { |
3330 return GetElementAttributeWithInterceptor(receiver, index, continue_search); | 3340 return GetElementAttributeWithInterceptor(receiver, index, continue_search); |
3331 } | 3341 } |
3332 | 3342 |
3343 // Handle [] on String objects. | |
3344 if (this->IsStringObjectWithCharacterAt(index)) { | |
3345 return static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | |
3346 } | |
3347 | |
3333 return GetElementAttributeWithoutInterceptor( | 3348 return GetElementAttributeWithoutInterceptor( |
3334 receiver, index, continue_search); | 3349 receiver, index, continue_search); |
3335 } | 3350 } |
3336 | 3351 |
3337 | 3352 |
3338 PropertyAttributes JSObject::GetElementAttributeWithInterceptor( | 3353 PropertyAttributes JSObject::GetElementAttributeWithInterceptor( |
3339 JSReceiver* receiver, uint32_t index, bool continue_search) { | 3354 JSReceiver* receiver, uint32_t index, bool continue_search) { |
3340 Isolate* isolate = GetIsolate(); | 3355 Isolate* isolate = GetIsolate(); |
3341 // Make sure that the top context does not change when doing | 3356 // Make sure that the top context does not change when doing |
3342 // callbacks or interceptor calls. | 3357 // callbacks or interceptor calls. |
(...skipping 6274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9617 PropertyType JSObject::GetLocalElementType(uint32_t index) { | 9632 PropertyType JSObject::GetLocalElementType(uint32_t index) { |
9618 return GetElementsAccessor()->GetType(this, this, index); | 9633 return GetElementsAccessor()->GetType(this, this, index); |
9619 } | 9634 } |
9620 | 9635 |
9621 | 9636 |
9622 AccessorPair* JSObject::GetLocalPropertyAccessorPair(String* name) { | 9637 AccessorPair* JSObject::GetLocalPropertyAccessorPair(String* name) { |
9623 uint32_t index = 0; | 9638 uint32_t index = 0; |
9624 if (name->AsArrayIndex(&index)) { | 9639 if (name->AsArrayIndex(&index)) { |
9625 return GetLocalElementAccessorPair(index); | 9640 return GetLocalElementAccessorPair(index); |
9626 } | 9641 } |
9642 | |
9627 LookupResult lookup(GetIsolate()); | 9643 LookupResult lookup(GetIsolate()); |
9628 LocalLookup(name, &lookup); | 9644 LocalLookupRealNamedProperty(name, &lookup); |
9645 | |
9629 if (lookup.IsPropertyCallbacks() && | 9646 if (lookup.IsPropertyCallbacks() && |
9630 lookup.GetCallbackObject()->IsAccessorPair()) { | 9647 lookup.GetCallbackObject()->IsAccessorPair()) { |
9631 return AccessorPair::cast(lookup.GetCallbackObject()); | 9648 return AccessorPair::cast(lookup.GetCallbackObject()); |
9632 } | 9649 } |
9633 return NULL; | 9650 return NULL; |
9634 } | 9651 } |
9635 | 9652 |
9636 | 9653 |
9637 AccessorPair* JSObject::GetLocalElementAccessorPair(uint32_t index) { | 9654 AccessorPair* JSObject::GetLocalElementAccessorPair(uint32_t index) { |
9655 if (IsJSGlobalProxy()) { | |
9656 Object* proto = GetPrototype(); | |
9657 if (proto->IsNull()) return NULL; | |
9658 ASSERT(proto->IsJSGlobalObject()); | |
9659 return JSObject::cast(proto)->GetLocalElementAccessorPair(index); | |
9660 } | |
9661 | |
9662 // Check for lookup interceptor. | |
9663 if (HasIndexedInterceptor()) return NULL; | |
9664 | |
9638 return GetElementsAccessor()->GetAccessorPair(this, this, index); | 9665 return GetElementsAccessor()->GetAccessorPair(this, this, index); |
9639 } | 9666 } |
9640 | 9667 |
9641 | 9668 |
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, | 9669 MaybeObject* JSObject::SetElementWithInterceptor(uint32_t index, |
9752 Object* value, | 9670 Object* value, |
9753 PropertyAttributes attributes, | 9671 PropertyAttributes attributes, |
9754 StrictModeFlag strict_mode, | 9672 StrictModeFlag strict_mode, |
9755 bool check_prototype, | 9673 bool check_prototype, |
9756 SetPropertyMode set_mode) { | 9674 SetPropertyMode set_mode) { |
9757 Isolate* isolate = GetIsolate(); | 9675 Isolate* isolate = GetIsolate(); |
9758 // Make sure that the top context does not change when doing | 9676 // Make sure that the top context does not change when doing |
9759 // callbacks or interceptor calls. | 9677 // callbacks or interceptor calls. |
9760 AssertNoContextChange ncc; | 9678 AssertNoContextChange ncc; |
(...skipping 4182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13943 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13861 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13944 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13862 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13945 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13863 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13946 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13864 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13947 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13865 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13948 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13866 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13949 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13867 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13950 } | 13868 } |
13951 | 13869 |
13952 } } // namespace v8::internal | 13870 } } // namespace v8::internal |
OLD | NEW |