From a428465819a26f99e4c203d6c5094a23d3db2f49 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Fri, 18 Oct 2013 12:52:07 +0000 Subject: [PATCH] Handlify JSObject::HasReal*Property. R=ulan@chromium.org BUG= Review URL: https://codereview.chromium.org/27518002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17272 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/api.cc | 12 +++++------- src/objects.cc | 50 ++++++++++++++++++++++++++++++-------------------- src/objects.h | 8 +++++--- src/runtime.cc | 21 ++++++++++----------- 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/api.cc b/src/api.cc index e498b438b0..f3bc294609 100644 --- a/src/api.cc +++ b/src/api.cc @@ -3526,9 +3526,8 @@ bool v8::Object::HasRealNamedProperty(Handle key) { i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()", return false); - return Utils::OpenHandle(this)->HasRealNamedProperty( - isolate, - *Utils::OpenHandle(*key)); + return i::JSObject::HasRealNamedProperty(Utils::OpenHandle(this), + Utils::OpenHandle(*key)); } @@ -3536,7 +3535,7 @@ bool v8::Object::HasRealIndexedProperty(uint32_t index) { i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()", return false); - return Utils::OpenHandle(this)->HasRealElementProperty(isolate, index); + return i::JSObject::HasRealElementProperty(Utils::OpenHandle(this), index); } @@ -3546,9 +3545,8 @@ bool v8::Object::HasRealNamedCallbackProperty(Handle key) { "v8::Object::HasRealNamedCallbackProperty()", return false); ENTER_V8(isolate); - return Utils::OpenHandle(this)->HasRealNamedCallbackProperty( - isolate, - *Utils::OpenHandle(*key)); + return i::JSObject::HasRealNamedCallbackProperty(Utils::OpenHandle(this), + Utils::OpenHandle(*key)); } diff --git a/src/objects.cc b/src/objects.cc index 2f84975d6f..743009f6c9 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -6557,7 +6557,7 @@ Handle JSObject::GetAccessor(Handle object, uint32_t index = 0; if (name->AsArrayIndex(&index)) { for (Handle obj = object; - *obj != isolate->heap()->null_value(); + !obj->IsNull(); obj = handle(JSReceiver::cast(*obj)->GetPrototype(), isolate)) { if (obj->IsJSObject() && JSObject::cast(*obj)->HasDictionaryElements()) { JSObject* js_object = JSObject::cast(*obj); @@ -6575,7 +6575,7 @@ Handle JSObject::GetAccessor(Handle object, } } else { for (Handle obj = object; - *obj != isolate->heap()->null_value(); + !obj->IsNull(); obj = handle(JSReceiver::cast(*obj)->GetPrototype(), isolate)) { LookupResult result(isolate); JSReceiver::cast(*obj)->LocalLookup(*name, &result); @@ -13177,52 +13177,62 @@ Handle JSObject::GetPropertyWithInterceptor( } -bool JSObject::HasRealNamedProperty(Isolate* isolate, Name* key) { +bool JSObject::HasRealNamedProperty(Handle object, + Handle key) { + Isolate* isolate = object->GetIsolate(); + SealHandleScope shs(isolate); // Check access rights if needed. - if (IsAccessCheckNeeded()) { - if (!isolate->MayNamedAccess(this, key, v8::ACCESS_HAS)) { - isolate->ReportFailedAccessCheck(this, v8::ACCESS_HAS); + if (object->IsAccessCheckNeeded()) { + if (!isolate->MayNamedAccess(*object, *key, v8::ACCESS_HAS)) { + isolate->ReportFailedAccessCheck(*object, v8::ACCESS_HAS); return false; } } LookupResult result(isolate); - LocalLookupRealNamedProperty(key, &result); + object->LocalLookupRealNamedProperty(*key, &result); return result.IsFound() && !result.IsInterceptor(); } -bool JSObject::HasRealElementProperty(Isolate* isolate, uint32_t index) { +bool JSObject::HasRealElementProperty(Handle object, uint32_t index) { + Isolate* isolate = object->GetIsolate(); + SealHandleScope shs(isolate); // Check access rights if needed. - if (IsAccessCheckNeeded()) { - if (!isolate->MayIndexedAccess(this, index, v8::ACCESS_HAS)) { - isolate->ReportFailedAccessCheck(this, v8::ACCESS_HAS); + if (object->IsAccessCheckNeeded()) { + if (!isolate->MayIndexedAccess(*object, index, v8::ACCESS_HAS)) { + isolate->ReportFailedAccessCheck(*object, v8::ACCESS_HAS); return false; } } - if (IsJSGlobalProxy()) { - Object* proto = GetPrototype(); + if (object->IsJSGlobalProxy()) { + HandleScope scope(isolate); + Handle proto(object->GetPrototype(), isolate); if (proto->IsNull()) return false; ASSERT(proto->IsJSGlobalObject()); - return JSObject::cast(proto)->HasRealElementProperty(isolate, index); + return HasRealElementProperty(Handle::cast(proto), index); } - return GetElementAttributeWithoutInterceptor(this, index, false) != ABSENT; + return object->GetElementAttributeWithoutInterceptor( + *object, index, false) != ABSENT; } -bool JSObject::HasRealNamedCallbackProperty(Isolate* isolate, Name* key) { +bool JSObject::HasRealNamedCallbackProperty(Handle object, + Handle key) { + Isolate* isolate = object->GetIsolate(); + SealHandleScope shs(isolate); // Check access rights if needed. - if (IsAccessCheckNeeded()) { - if (!isolate->MayNamedAccess(this, key, v8::ACCESS_HAS)) { - isolate->ReportFailedAccessCheck(this, v8::ACCESS_HAS); + if (object->IsAccessCheckNeeded()) { + if (!isolate->MayNamedAccess(*object, *key, v8::ACCESS_HAS)) { + isolate->ReportFailedAccessCheck(*object, v8::ACCESS_HAS); return false; } } LookupResult result(isolate); - LocalLookupRealNamedProperty(key, &result); + object->LocalLookupRealNamedProperty(*key, &result); return result.IsPropertyCallbacks(); } diff --git a/src/objects.h b/src/objects.h index 30c3f63ea3..8db2ceebe5 100644 --- a/src/objects.h +++ b/src/objects.h @@ -2414,9 +2414,11 @@ class JSObject: public JSReceiver { inline bool HasIndexedInterceptor(); // Support functions for v8 api (needed for correct interceptor behavior). - bool HasRealNamedProperty(Isolate* isolate, Name* key); - bool HasRealElementProperty(Isolate* isolate, uint32_t index); - bool HasRealNamedCallbackProperty(Isolate* isolate, Name* key); + static bool HasRealNamedProperty(Handle object, + Handle key); + static bool HasRealElementProperty(Handle object, uint32_t index); + static bool HasRealNamedCallbackProperty(Handle object, + Handle key); // Get the header size for a JSObject. Used to compute the index of // internal fields as well as the number of internal fields. diff --git a/src/runtime.cc b/src/runtime.cc index 0b39a436d3..b25547b23e 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -5582,40 +5582,39 @@ static MaybeObject* HasLocalPropertyImplementation(Isolate* isolate, RUNTIME_FUNCTION(MaybeObject*, Runtime_HasLocalProperty) { - SealHandleScope shs(isolate); + HandleScope scope(isolate); ASSERT(args.length() == 2); - CONVERT_ARG_CHECKED(Name, key, 1); + CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); + Handle object = args.at(0); uint32_t index; const bool key_is_array_index = key->AsArrayIndex(&index); - Object* obj = args[0]; // Only JS objects can have properties. - if (obj->IsJSObject()) { - JSObject* object = JSObject::cast(obj); + if (object->IsJSObject()) { + Handle js_obj = Handle::cast(object); // Fast case: either the key is a real named property or it is not // an array index and there are no interceptors or hidden // prototypes. - if (object->HasRealNamedProperty(isolate, key)) { + if (JSObject::HasRealNamedProperty(js_obj, key)) { ASSERT(!isolate->has_scheduled_exception()); return isolate->heap()->true_value(); } else { RETURN_IF_SCHEDULED_EXCEPTION(isolate); } - Map* map = object->map(); + Map* map = js_obj->map(); if (!key_is_array_index && !map->has_named_interceptor() && !HeapObject::cast(map->prototype())->map()->is_hidden_prototype()) { return isolate->heap()->false_value(); } // Slow case. - HandleScope scope(isolate); return HasLocalPropertyImplementation(isolate, - Handle(object), + Handle(js_obj), Handle(key)); - } else if (obj->IsString() && key_is_array_index) { + } else if (object->IsString() && key_is_array_index) { // Well, there is one exception: Handle [] on strings. - String* string = String::cast(obj); + Handle string = Handle::cast(object); if (index < static_cast(string->length())) { return isolate->heap()->true_value(); }