| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 case TRANSITION: | 955 case TRANSITION: |
| 956 case NONEXISTENT: | 956 case NONEXISTENT: |
| 957 UNREACHABLE(); | 957 UNREACHABLE(); |
| 958 break; | 958 break; |
| 959 } | 959 } |
| 960 UNREACHABLE(); | 960 UNREACHABLE(); |
| 961 return NULL; | 961 return NULL; |
| 962 } | 962 } |
| 963 | 963 |
| 964 | 964 |
| 965 MaybeObject* Object::GetElementWithReceiver(Isolate* isolate, | 965 Handle<Object> Object::GetElementWithReceiver(Isolate* isolate, |
| 966 Object* receiver, | 966 Handle<Object> object, |
| 967 uint32_t index) { | 967 Handle<Object> receiver, |
| 968 Heap* heap = isolate->heap(); | 968 uint32_t index) { |
| 969 Object* holder = this; | 969 Handle<Object> holder; |
| 970 | 970 |
| 971 // Iterate up the prototype chain until an element is found or the null | 971 // Iterate up the prototype chain until an element is found or the null |
| 972 // prototype is encountered. | 972 // prototype is encountered. |
| 973 for (holder = this; | 973 for (holder = object; |
| 974 holder != heap->null_value(); | 974 !holder->IsNull(); |
| 975 holder = holder->GetPrototype(isolate)) { | 975 holder = Handle<Object>(holder->GetPrototype(isolate), isolate)) { |
| 976 if (!holder->IsJSObject()) { | 976 if (!holder->IsJSObject()) { |
| 977 Context* native_context = isolate->context()->native_context(); | 977 Context* native_context = isolate->context()->native_context(); |
| 978 if (holder->IsNumber()) { | 978 if (holder->IsNumber()) { |
| 979 holder = native_context->number_function()->instance_prototype(); | 979 holder = Handle<Object>( |
| 980 native_context->number_function()->instance_prototype(), isolate); |
| 980 } else if (holder->IsString()) { | 981 } else if (holder->IsString()) { |
| 981 holder = native_context->string_function()->instance_prototype(); | 982 holder = Handle<Object>( |
| 983 native_context->string_function()->instance_prototype(), isolate); |
| 982 } else if (holder->IsSymbol()) { | 984 } else if (holder->IsSymbol()) { |
| 983 holder = native_context->symbol_function()->instance_prototype(); | 985 holder = Handle<Object>( |
| 986 native_context->symbol_function()->instance_prototype(), isolate); |
| 984 } else if (holder->IsBoolean()) { | 987 } else if (holder->IsBoolean()) { |
| 985 holder = native_context->boolean_function()->instance_prototype(); | 988 holder = Handle<Object>( |
| 989 native_context->boolean_function()->instance_prototype(), isolate); |
| 986 } else if (holder->IsJSProxy()) { | 990 } else if (holder->IsJSProxy()) { |
| 987 return JSProxy::cast(holder)->GetElementWithHandler(receiver, index); | 991 CALL_HEAP_FUNCTION(isolate, |
| 992 Handle<JSProxy>::cast(holder)->GetElementWithHandler( |
| 993 *receiver, index), |
| 994 Object); |
| 988 } else { | 995 } else { |
| 989 // Undefined and null have no indexed properties. | 996 // Undefined and null have no indexed properties. |
| 990 ASSERT(holder->IsUndefined() || holder->IsNull()); | 997 ASSERT(holder->IsUndefined() || holder->IsNull()); |
| 991 return heap->undefined_value(); | 998 return isolate->factory()->undefined_value(); |
| 992 } | 999 } |
| 993 } | 1000 } |
| 994 | 1001 |
| 995 // Inline the case for JSObjects. Doing so significantly improves the | 1002 // Inline the case for JSObjects. Doing so significantly improves the |
| 996 // performance of fetching elements where checking the prototype chain is | 1003 // performance of fetching elements where checking the prototype chain is |
| 997 // necessary. | 1004 // necessary. |
| 998 JSObject* js_object = JSObject::cast(holder); | 1005 Handle<JSObject> js_object = Handle<JSObject>::cast(holder); |
| 999 | 1006 |
| 1000 // Check access rights if needed. | 1007 // Check access rights if needed. |
| 1001 if (js_object->IsAccessCheckNeeded()) { | 1008 if (js_object->IsAccessCheckNeeded()) { |
| 1002 Isolate* isolate = heap->isolate(); | 1009 if (!isolate->MayIndexedAccessWrapper(js_object, index, v8::ACCESS_GET)) { |
| 1003 if (!isolate->MayIndexedAccess(js_object, index, v8::ACCESS_GET)) { | 1010 isolate->ReportFailedAccessCheckWrapper(js_object, v8::ACCESS_GET); |
| 1004 isolate->ReportFailedAccessCheck(js_object, v8::ACCESS_GET); | 1011 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); |
| 1005 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 1012 return isolate->factory()->undefined_value(); |
| 1006 return heap->undefined_value(); | |
| 1007 } | 1013 } |
| 1008 } | 1014 } |
| 1009 | 1015 |
| 1010 if (js_object->HasIndexedInterceptor()) { | 1016 if (js_object->HasIndexedInterceptor()) { |
| 1011 return js_object->GetElementWithInterceptor(receiver, index); | 1017 return JSObject::GetElementWithInterceptor(js_object, receiver, index); |
| 1012 } | 1018 } |
| 1013 | 1019 |
| 1014 if (js_object->elements() != heap->empty_fixed_array()) { | 1020 if (js_object->elements() != isolate->heap()->empty_fixed_array()) { |
| 1015 MaybeObject* result = js_object->GetElementsAccessor()->Get( | 1021 Handle<Object> result = js_object->GetElementsAccessor()->Get( |
| 1016 receiver, js_object, index); | 1022 receiver, js_object, index); |
| 1017 if (result != heap->the_hole_value()) return result; | 1023 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, result, Handle<Object>()); |
| 1024 if (!result->IsTheHole()) return result; |
| 1018 } | 1025 } |
| 1019 } | 1026 } |
| 1020 | 1027 |
| 1021 return heap->undefined_value(); | 1028 return isolate->factory()->undefined_value(); |
| 1022 } | 1029 } |
| 1023 | 1030 |
| 1024 | 1031 |
| 1025 Object* Object::GetPrototype(Isolate* isolate) { | 1032 Object* Object::GetPrototype(Isolate* isolate) { |
| 1026 if (IsSmi()) { | 1033 if (IsSmi()) { |
| 1027 Context* context = isolate->context()->native_context(); | 1034 Context* context = isolate->context()->native_context(); |
| 1028 return context->number_function()->instance_prototype(); | 1035 return context->number_function()->instance_prototype(); |
| 1029 } | 1036 } |
| 1030 | 1037 |
| 1031 HeapObject* heap_object = HeapObject::cast(this); | 1038 HeapObject* heap_object = HeapObject::cast(this); |
| (...skipping 11883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12915 { MaybeObject* maybe_len = | 12922 { MaybeObject* maybe_len = |
| 12916 GetHeap()->NumberFromDouble(static_cast<double>(index) + 1); | 12923 GetHeap()->NumberFromDouble(static_cast<double>(index) + 1); |
| 12917 if (!maybe_len->ToObject(&len)) return maybe_len; | 12924 if (!maybe_len->ToObject(&len)) return maybe_len; |
| 12918 } | 12925 } |
| 12919 set_length(len); | 12926 set_length(len); |
| 12920 } | 12927 } |
| 12921 return value; | 12928 return value; |
| 12922 } | 12929 } |
| 12923 | 12930 |
| 12924 | 12931 |
| 12925 MaybeObject* JSObject::GetElementWithInterceptor(Object* receiver, | 12932 Handle<Object> JSObject::GetElementWithInterceptor(Handle<JSObject> object, |
| 12926 uint32_t index) { | 12933 Handle<Object> receiver, |
| 12927 Isolate* isolate = GetIsolate(); | 12934 uint32_t index) { |
| 12928 HandleScope scope(isolate); | 12935 Isolate* isolate = object->GetIsolate(); |
| 12929 | 12936 |
| 12930 // Make sure that the top context does not change when doing | 12937 // Make sure that the top context does not change when doing |
| 12931 // callbacks or interceptor calls. | 12938 // callbacks or interceptor calls. |
| 12932 AssertNoContextChange ncc(isolate); | 12939 AssertNoContextChange ncc(isolate); |
| 12933 | 12940 |
| 12934 Handle<InterceptorInfo> interceptor(GetIndexedInterceptor(), isolate); | 12941 Handle<InterceptorInfo> interceptor(object->GetIndexedInterceptor(), isolate); |
| 12935 Handle<Object> this_handle(receiver, isolate); | |
| 12936 Handle<JSObject> holder_handle(this, isolate); | |
| 12937 if (!interceptor->getter()->IsUndefined()) { | 12942 if (!interceptor->getter()->IsUndefined()) { |
| 12938 v8::IndexedPropertyGetterCallback getter = | 12943 v8::IndexedPropertyGetterCallback getter = |
| 12939 v8::ToCData<v8::IndexedPropertyGetterCallback>(interceptor->getter()); | 12944 v8::ToCData<v8::IndexedPropertyGetterCallback>(interceptor->getter()); |
| 12940 LOG(isolate, | 12945 LOG(isolate, |
| 12941 ApiIndexedPropertyAccess("interceptor-indexed-get", this, index)); | 12946 ApiIndexedPropertyAccess("interceptor-indexed-get", *object, index)); |
| 12942 PropertyCallbackArguments | 12947 PropertyCallbackArguments |
| 12943 args(isolate, interceptor->data(), receiver, this); | 12948 args(isolate, interceptor->data(), *receiver, *object); |
| 12944 v8::Handle<v8::Value> result = args.Call(getter, index); | 12949 v8::Handle<v8::Value> result = args.Call(getter, index); |
| 12945 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 12950 RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object); |
| 12946 if (!result.IsEmpty()) { | 12951 if (!result.IsEmpty()) { |
| 12947 Handle<Object> result_internal = v8::Utils::OpenHandle(*result); | 12952 Handle<Object> result_internal = v8::Utils::OpenHandle(*result); |
| 12948 result_internal->VerifyApiCallResultType(); | 12953 result_internal->VerifyApiCallResultType(); |
| 12949 return *result_internal; | 12954 // Rebox handle before return. |
| 12955 return Handle<Object>(*result_internal, isolate); |
| 12950 } | 12956 } |
| 12951 } | 12957 } |
| 12952 | 12958 |
| 12953 Heap* heap = holder_handle->GetHeap(); | 12959 ElementsAccessor* handler = object->GetElementsAccessor(); |
| 12954 ElementsAccessor* handler = holder_handle->GetElementsAccessor(); | 12960 Handle<Object> result = handler->Get(receiver, object, index); |
| 12955 MaybeObject* raw_result = handler->Get(*this_handle, | 12961 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, result, Handle<Object>()); |
| 12956 *holder_handle, | 12962 if (!result->IsTheHole()) return result; |
| 12957 index); | |
| 12958 if (raw_result != heap->the_hole_value()) return raw_result; | |
| 12959 | 12963 |
| 12960 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 12964 Handle<Object> proto(object->GetPrototype(), isolate); |
| 12961 | 12965 if (proto->IsNull()) return isolate->factory()->undefined_value(); |
| 12962 Object* pt = holder_handle->GetPrototype(); | 12966 return Object::GetElementWithReceiver(isolate, proto, receiver, index); |
| 12963 if (pt == heap->null_value()) return heap->undefined_value(); | |
| 12964 return pt->GetElementWithReceiver(isolate, *this_handle, index); | |
| 12965 } | 12967 } |
| 12966 | 12968 |
| 12967 | 12969 |
| 12968 bool JSObject::HasDenseElements() { | 12970 bool JSObject::HasDenseElements() { |
| 12969 int capacity = 0; | 12971 int capacity = 0; |
| 12970 int used = 0; | 12972 int used = 0; |
| 12971 GetElementsCapacityAndUsage(&capacity, &used); | 12973 GetElementsCapacityAndUsage(&capacity, &used); |
| 12972 return (capacity == 0) || (used > (capacity / 2)); | 12974 return (capacity == 0) || (used > (capacity / 2)); |
| 12973 } | 12975 } |
| 12974 | 12976 |
| (...skipping 3444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16419 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16421 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16420 static const char* error_messages_[] = { | 16422 static const char* error_messages_[] = { |
| 16421 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16423 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16422 }; | 16424 }; |
| 16423 #undef ERROR_MESSAGES_TEXTS | 16425 #undef ERROR_MESSAGES_TEXTS |
| 16424 return error_messages_[reason]; | 16426 return error_messages_[reason]; |
| 16425 } | 16427 } |
| 16426 | 16428 |
| 16427 | 16429 |
| 16428 } } // namespace v8::internal | 16430 } } // namespace v8::internal |
| OLD | NEW |