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
This commit is contained in:
yangguo@chromium.org 2013-10-18 12:52:07 +00:00
parent b50be9ff12
commit a428465819
4 changed files with 50 additions and 41 deletions

View File

@ -3526,9 +3526,8 @@ bool v8::Object::HasRealNamedProperty(Handle<String> key) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()", ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()",
return false); return false);
return Utils::OpenHandle(this)->HasRealNamedProperty( return i::JSObject::HasRealNamedProperty(Utils::OpenHandle(this),
isolate, Utils::OpenHandle(*key));
*Utils::OpenHandle(*key));
} }
@ -3536,7 +3535,7 @@ bool v8::Object::HasRealIndexedProperty(uint32_t index) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()", ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()",
return false); 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<String> key) {
"v8::Object::HasRealNamedCallbackProperty()", "v8::Object::HasRealNamedCallbackProperty()",
return false); return false);
ENTER_V8(isolate); ENTER_V8(isolate);
return Utils::OpenHandle(this)->HasRealNamedCallbackProperty( return i::JSObject::HasRealNamedCallbackProperty(Utils::OpenHandle(this),
isolate, Utils::OpenHandle(*key));
*Utils::OpenHandle(*key));
} }

View File

@ -6557,7 +6557,7 @@ Handle<Object> JSObject::GetAccessor(Handle<JSObject> object,
uint32_t index = 0; uint32_t index = 0;
if (name->AsArrayIndex(&index)) { if (name->AsArrayIndex(&index)) {
for (Handle<Object> obj = object; for (Handle<Object> obj = object;
*obj != isolate->heap()->null_value(); !obj->IsNull();
obj = handle(JSReceiver::cast(*obj)->GetPrototype(), isolate)) { obj = handle(JSReceiver::cast(*obj)->GetPrototype(), isolate)) {
if (obj->IsJSObject() && JSObject::cast(*obj)->HasDictionaryElements()) { if (obj->IsJSObject() && JSObject::cast(*obj)->HasDictionaryElements()) {
JSObject* js_object = JSObject::cast(*obj); JSObject* js_object = JSObject::cast(*obj);
@ -6575,7 +6575,7 @@ Handle<Object> JSObject::GetAccessor(Handle<JSObject> object,
} }
} else { } else {
for (Handle<Object> obj = object; for (Handle<Object> obj = object;
*obj != isolate->heap()->null_value(); !obj->IsNull();
obj = handle(JSReceiver::cast(*obj)->GetPrototype(), isolate)) { obj = handle(JSReceiver::cast(*obj)->GetPrototype(), isolate)) {
LookupResult result(isolate); LookupResult result(isolate);
JSReceiver::cast(*obj)->LocalLookup(*name, &result); JSReceiver::cast(*obj)->LocalLookup(*name, &result);
@ -13177,52 +13177,62 @@ Handle<Object> JSObject::GetPropertyWithInterceptor(
} }
bool JSObject::HasRealNamedProperty(Isolate* isolate, Name* key) { bool JSObject::HasRealNamedProperty(Handle<JSObject> object,
Handle<Name> key) {
Isolate* isolate = object->GetIsolate();
SealHandleScope shs(isolate);
// Check access rights if needed. // Check access rights if needed.
if (IsAccessCheckNeeded()) { if (object->IsAccessCheckNeeded()) {
if (!isolate->MayNamedAccess(this, key, v8::ACCESS_HAS)) { if (!isolate->MayNamedAccess(*object, *key, v8::ACCESS_HAS)) {
isolate->ReportFailedAccessCheck(this, v8::ACCESS_HAS); isolate->ReportFailedAccessCheck(*object, v8::ACCESS_HAS);
return false; return false;
} }
} }
LookupResult result(isolate); LookupResult result(isolate);
LocalLookupRealNamedProperty(key, &result); object->LocalLookupRealNamedProperty(*key, &result);
return result.IsFound() && !result.IsInterceptor(); return result.IsFound() && !result.IsInterceptor();
} }
bool JSObject::HasRealElementProperty(Isolate* isolate, uint32_t index) { bool JSObject::HasRealElementProperty(Handle<JSObject> object, uint32_t index) {
Isolate* isolate = object->GetIsolate();
SealHandleScope shs(isolate);
// Check access rights if needed. // Check access rights if needed.
if (IsAccessCheckNeeded()) { if (object->IsAccessCheckNeeded()) {
if (!isolate->MayIndexedAccess(this, index, v8::ACCESS_HAS)) { if (!isolate->MayIndexedAccess(*object, index, v8::ACCESS_HAS)) {
isolate->ReportFailedAccessCheck(this, v8::ACCESS_HAS); isolate->ReportFailedAccessCheck(*object, v8::ACCESS_HAS);
return false; return false;
} }
} }
if (IsJSGlobalProxy()) { if (object->IsJSGlobalProxy()) {
Object* proto = GetPrototype(); HandleScope scope(isolate);
Handle<Object> proto(object->GetPrototype(), isolate);
if (proto->IsNull()) return false; if (proto->IsNull()) return false;
ASSERT(proto->IsJSGlobalObject()); ASSERT(proto->IsJSGlobalObject());
return JSObject::cast(proto)->HasRealElementProperty(isolate, index); return HasRealElementProperty(Handle<JSObject>::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<JSObject> object,
Handle<Name> key) {
Isolate* isolate = object->GetIsolate();
SealHandleScope shs(isolate);
// Check access rights if needed. // Check access rights if needed.
if (IsAccessCheckNeeded()) { if (object->IsAccessCheckNeeded()) {
if (!isolate->MayNamedAccess(this, key, v8::ACCESS_HAS)) { if (!isolate->MayNamedAccess(*object, *key, v8::ACCESS_HAS)) {
isolate->ReportFailedAccessCheck(this, v8::ACCESS_HAS); isolate->ReportFailedAccessCheck(*object, v8::ACCESS_HAS);
return false; return false;
} }
} }
LookupResult result(isolate); LookupResult result(isolate);
LocalLookupRealNamedProperty(key, &result); object->LocalLookupRealNamedProperty(*key, &result);
return result.IsPropertyCallbacks(); return result.IsPropertyCallbacks();
} }

View File

@ -2414,9 +2414,11 @@ class JSObject: public JSReceiver {
inline bool HasIndexedInterceptor(); inline bool HasIndexedInterceptor();
// Support functions for v8 api (needed for correct interceptor behavior). // Support functions for v8 api (needed for correct interceptor behavior).
bool HasRealNamedProperty(Isolate* isolate, Name* key); static bool HasRealNamedProperty(Handle<JSObject> object,
bool HasRealElementProperty(Isolate* isolate, uint32_t index); Handle<Name> key);
bool HasRealNamedCallbackProperty(Isolate* isolate, Name* key); static bool HasRealElementProperty(Handle<JSObject> object, uint32_t index);
static bool HasRealNamedCallbackProperty(Handle<JSObject> object,
Handle<Name> key);
// Get the header size for a JSObject. Used to compute the index of // Get the header size for a JSObject. Used to compute the index of
// internal fields as well as the number of internal fields. // internal fields as well as the number of internal fields.

View File

@ -5582,40 +5582,39 @@ static MaybeObject* HasLocalPropertyImplementation(Isolate* isolate,
RUNTIME_FUNCTION(MaybeObject*, Runtime_HasLocalProperty) { RUNTIME_FUNCTION(MaybeObject*, Runtime_HasLocalProperty) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
CONVERT_ARG_CHECKED(Name, key, 1); CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
Handle<Object> object = args.at<Object>(0);
uint32_t index; uint32_t index;
const bool key_is_array_index = key->AsArrayIndex(&index); const bool key_is_array_index = key->AsArrayIndex(&index);
Object* obj = args[0];
// Only JS objects can have properties. // Only JS objects can have properties.
if (obj->IsJSObject()) { if (object->IsJSObject()) {
JSObject* object = JSObject::cast(obj); Handle<JSObject> js_obj = Handle<JSObject>::cast(object);
// Fast case: either the key is a real named property or it is not // Fast case: either the key is a real named property or it is not
// an array index and there are no interceptors or hidden // an array index and there are no interceptors or hidden
// prototypes. // prototypes.
if (object->HasRealNamedProperty(isolate, key)) { if (JSObject::HasRealNamedProperty(js_obj, key)) {
ASSERT(!isolate->has_scheduled_exception()); ASSERT(!isolate->has_scheduled_exception());
return isolate->heap()->true_value(); return isolate->heap()->true_value();
} else { } else {
RETURN_IF_SCHEDULED_EXCEPTION(isolate); RETURN_IF_SCHEDULED_EXCEPTION(isolate);
} }
Map* map = object->map(); Map* map = js_obj->map();
if (!key_is_array_index && if (!key_is_array_index &&
!map->has_named_interceptor() && !map->has_named_interceptor() &&
!HeapObject::cast(map->prototype())->map()->is_hidden_prototype()) { !HeapObject::cast(map->prototype())->map()->is_hidden_prototype()) {
return isolate->heap()->false_value(); return isolate->heap()->false_value();
} }
// Slow case. // Slow case.
HandleScope scope(isolate);
return HasLocalPropertyImplementation(isolate, return HasLocalPropertyImplementation(isolate,
Handle<JSObject>(object), Handle<JSObject>(js_obj),
Handle<Name>(key)); Handle<Name>(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. // Well, there is one exception: Handle [] on strings.
String* string = String::cast(obj); Handle<String> string = Handle<String>::cast(object);
if (index < static_cast<uint32_t>(string->length())) { if (index < static_cast<uint32_t>(string->length())) {
return isolate->heap()->true_value(); return isolate->heap()->true_value();
} }