ElementsAccessor::GetAccessorPair() handlified.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/225683003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20530 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ishell@chromium.org 2014-04-07 09:20:44 +00:00
parent c19764595f
commit 7a3703db64
5 changed files with 70 additions and 55 deletions

View File

@ -732,24 +732,21 @@ class ElementsAccessorBase : public ElementsAccessor {
? NONEXISTENT : FIELD;
}
MUST_USE_RESULT virtual AccessorPair* GetAccessorPair(
Object* receiver,
JSObject* holder,
MUST_USE_RESULT virtual MaybeHandle<AccessorPair> GetAccessorPair(
Handle<Object> receiver,
Handle<JSObject> holder,
uint32_t key,
FixedArrayBase* backing_store) V8_FINAL V8_OVERRIDE {
if (backing_store == NULL) {
backing_store = holder->elements();
}
Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE {
return ElementsAccessorSubclass::GetAccessorPairImpl(
receiver, holder, key, backing_store);
}
MUST_USE_RESULT static AccessorPair* GetAccessorPairImpl(
Object* receiver,
JSObject* obj,
uint32_t key,
FixedArrayBase* backing_store) {
return NULL;
MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
Handle<Object> receiver,
Handle<JSObject> obj,
uint32_t key,
Handle<FixedArrayBase> backing_store) {
return MaybeHandle<AccessorPair>();
}
MUST_USE_RESULT virtual Handle<Object> SetLength(
@ -1655,19 +1652,20 @@ class DictionaryElementsAccessor
return NONEXISTENT;
}
MUST_USE_RESULT static AccessorPair* GetAccessorPairImpl(
Object* receiver,
JSObject* obj,
MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
Handle<Object> receiver,
Handle<JSObject> obj,
uint32_t key,
FixedArrayBase* store) {
SeededNumberDictionary* backing_store = SeededNumberDictionary::cast(store);
Handle<FixedArrayBase> store) {
Handle<SeededNumberDictionary> backing_store =
Handle<SeededNumberDictionary>::cast(store);
int entry = backing_store->FindEntry(key);
if (entry != SeededNumberDictionary::kNotFound &&
backing_store->DetailsAt(entry).type() == CALLBACKS &&
backing_store->ValueAt(entry)->IsAccessorPair()) {
return AccessorPair::cast(backing_store->ValueAt(entry));
return handle(AccessorPair::cast(backing_store->ValueAt(entry)));
}
return NULL;
return MaybeHandle<AccessorPair>();
}
static bool HasElementImpl(Object* receiver,
@ -1766,18 +1764,18 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase<
}
}
MUST_USE_RESULT static AccessorPair* GetAccessorPairImpl(
Object* receiver,
JSObject* obj,
MUST_USE_RESULT static MaybeHandle<AccessorPair> GetAccessorPairImpl(
Handle<Object> receiver,
Handle<JSObject> obj,
uint32_t key,
FixedArrayBase* parameters) {
FixedArray* parameter_map = FixedArray::cast(parameters);
Object* probe = GetParameterMapArg(obj, parameter_map, key);
Handle<FixedArrayBase> parameters) {
Handle<FixedArray> parameter_map = Handle<FixedArray>::cast(parameters);
Handle<Object> probe = GetParameterMapArg(obj, parameter_map, key);
if (!probe->IsTheHole()) {
return NULL;
return MaybeHandle<AccessorPair>();
} else {
// If not aliased, check the arguments.
FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
Handle<FixedArray> arguments(FixedArray::cast(parameter_map->get(1)));
return ElementsAccessor::ForArray(arguments)->GetAccessorPair(
receiver, obj, key, arguments);
}

View File

@ -127,11 +127,18 @@ class ElementsAccessor {
// can optionally pass in the backing store to use for the check, which must
// be compatible with the ElementsKind of the ElementsAccessor. If
// backing_store is NULL, the holder->elements() is used as the backing store.
MUST_USE_RESULT virtual AccessorPair* GetAccessorPair(
Object* receiver,
JSObject* holder,
MUST_USE_RESULT virtual MaybeHandle<AccessorPair> GetAccessorPair(
Handle<Object> receiver,
Handle<JSObject> holder,
uint32_t key,
FixedArrayBase* backing_store = NULL) = 0;
Handle<FixedArrayBase> backing_store) = 0;
MUST_USE_RESULT inline MaybeHandle<AccessorPair> GetAccessorPair(
Handle<Object> receiver,
Handle<JSObject> holder,
uint32_t key) {
return GetAccessorPair(receiver, holder, key, handle(holder->elements()));
}
// Modifies the length data property as specified for JSArrays and resizes the
// underlying backing store accordingly. The method honors the semantics of

View File

@ -5192,7 +5192,7 @@ Handle<Object> JSObject::DeleteElement(Handle<JSObject> object,
if (object->map()->is_observed()) {
should_enqueue_change_record = HasLocalElement(object, index);
if (should_enqueue_change_record) {
if (object->GetLocalElementAccessorPair(index) != NULL) {
if (!GetLocalElementAccessorPair(object, index).is_null()) {
old_value = Handle<Object>::cast(factory->the_hole_value());
} else {
old_value = Object::GetElementNoExceptionThrown(isolate, object, index);
@ -6371,7 +6371,7 @@ void JSObject::DefineAccessor(Handle<JSObject> object,
if (is_observed) {
if (is_element) {
preexists = HasLocalElement(object, index);
if (preexists && object->GetLocalElementAccessorPair(index) == NULL) {
if (preexists && GetLocalElementAccessorPair(object, index).is_null()) {
old_value = Object::GetElementNoExceptionThrown(isolate, object, index);
}
} else {
@ -11319,7 +11319,7 @@ static bool GetOldValue(Isolate* isolate,
ASSERT(attributes != ABSENT);
if (attributes == DONT_DELETE) return false;
Handle<Object> value;
if (object->GetLocalElementAccessorPair(index) != NULL) {
if (!JSObject::GetLocalElementAccessorPair(object, index).is_null()) {
value = Handle<Object>::cast(isolate->factory()->the_hole_value());
} else {
value = Object::GetElementNoExceptionThrown(isolate, object, index);
@ -11858,35 +11858,40 @@ void JSObject::EnsureCanContainElements(Handle<JSObject> object,
}
AccessorPair* JSObject::GetLocalPropertyAccessorPair(Name* name) {
MaybeHandle<AccessorPair> JSObject::GetLocalPropertyAccessorPair(
Handle<JSObject> object,
Handle<Name> name) {
uint32_t index = 0;
if (name->AsArrayIndex(&index)) {
return GetLocalElementAccessorPair(index);
return GetLocalElementAccessorPair(object, index);
}
LookupResult lookup(GetIsolate());
LocalLookupRealNamedProperty(name, &lookup);
Isolate* isolate = object->GetIsolate();
LookupResult lookup(isolate);
object->LocalLookupRealNamedProperty(*name, &lookup);
if (lookup.IsPropertyCallbacks() &&
lookup.GetCallbackObject()->IsAccessorPair()) {
return AccessorPair::cast(lookup.GetCallbackObject());
return handle(AccessorPair::cast(lookup.GetCallbackObject()), isolate);
}
return NULL;
return MaybeHandle<AccessorPair>();
}
AccessorPair* JSObject::GetLocalElementAccessorPair(uint32_t index) {
if (IsJSGlobalProxy()) {
Object* proto = GetPrototype();
if (proto->IsNull()) return NULL;
MaybeHandle<AccessorPair> JSObject::GetLocalElementAccessorPair(
Handle<JSObject> object,
uint32_t index) {
if (object->IsJSGlobalProxy()) {
Handle<Object> proto(object->GetPrototype(), object->GetIsolate());
if (proto->IsNull()) return MaybeHandle<AccessorPair>();
ASSERT(proto->IsJSGlobalObject());
return JSObject::cast(proto)->GetLocalElementAccessorPair(index);
return GetLocalElementAccessorPair(Handle<JSObject>::cast(proto), index);
}
// Check for lookup interceptor.
if (HasIndexedInterceptor()) return NULL;
if (object->HasIndexedInterceptor()) return MaybeHandle<AccessorPair>();
return GetElementsAccessor()->GetAccessorPair(this, this, index);
return object->GetElementsAccessor()->GetAccessorPair(object, object, index);
}
@ -12535,7 +12540,7 @@ Handle<Object> JSObject::SetElement(Handle<JSObject> object,
Handle<Object> new_length_handle;
if (old_attributes != ABSENT) {
if (object->GetLocalElementAccessorPair(index) == NULL) {
if (GetLocalElementAccessorPair(object, index).is_null()) {
old_value = Object::GetElementNoExceptionThrown(isolate, object, index);
}
} else if (object->IsJSArray()) {

View File

@ -2469,8 +2469,12 @@ class JSObject: public JSReceiver {
}
// These methods do not perform access checks!
AccessorPair* GetLocalPropertyAccessorPair(Name* name);
AccessorPair* GetLocalElementAccessorPair(uint32_t index);
MUST_USE_RESULT static MaybeHandle<AccessorPair> GetLocalPropertyAccessorPair(
Handle<JSObject> object,
Handle<Name> name);
MUST_USE_RESULT static MaybeHandle<AccessorPair> GetLocalElementAccessorPair(
Handle<JSObject> object,
uint32_t index);
static Handle<Object> SetFastElement(Handle<JSObject> object, uint32_t index,
Handle<Object> value,

View File

@ -1926,14 +1926,15 @@ static Handle<Object> GetOwnProperty(Isolate* isolate,
return factory->undefined_value();
}
ASSERT(!isolate->has_scheduled_exception());
AccessorPair* raw_accessors = obj->GetLocalPropertyAccessorPair(*name);
Handle<AccessorPair> accessors(raw_accessors, isolate);
Handle<AccessorPair> accessors;
bool has_accessors =
JSObject::GetLocalPropertyAccessorPair(obj, name).ToHandle(&accessors);
Handle<FixedArray> elms = isolate->factory()->NewFixedArray(DESCRIPTOR_SIZE);
elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0));
elms->set(CONFIGURABLE_INDEX, heap->ToBoolean((attrs & DONT_DELETE) == 0));
elms->set(IS_ACCESSOR_INDEX, heap->ToBoolean(raw_accessors != NULL));
elms->set(IS_ACCESSOR_INDEX, heap->ToBoolean(has_accessors));
if (raw_accessors == NULL) {
if (!has_accessors) {
elms->set(WRITABLE_INDEX, heap->ToBoolean((attrs & READ_ONLY) == 0));
// Runtime::GetObjectProperty does access check.
Handle<Object> value = Runtime::GetObjectProperty(isolate, obj, name);