ElementsAccessor::Delete() maybehandlified.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20631 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ishell@chromium.org 2014-04-09 15:45:12 +00:00
parent f320fe9471
commit 7135c9fde2
4 changed files with 116 additions and 77 deletions

View File

@ -754,7 +754,7 @@ class ElementsAccessorBase : public ElementsAccessor {
UNIMPLEMENTED();
}
MUST_USE_RESULT virtual Handle<Object> Delete(
MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
Handle<JSObject> obj,
uint32_t key,
JSReceiver::DeleteMode mode) V8_OVERRIDE = 0;
@ -1038,7 +1038,7 @@ class FastElementsAccessor
return isolate->factory()->true_value();
}
virtual Handle<Object> Delete(
virtual MaybeHandle<Object> Delete(
Handle<JSObject> obj,
uint32_t key,
JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
@ -1373,7 +1373,7 @@ class TypedElementsAccessor
return obj;
}
MUST_USE_RESULT virtual Handle<Object> Delete(
MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
Handle<JSObject> obj,
uint32_t key,
JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
@ -1476,59 +1476,46 @@ class DictionaryElementsAccessor
return length_object;
}
MUST_USE_RESULT static MaybeObject* DeleteCommon(
JSObject* obj,
uint32_t key,
JSReceiver::DeleteMode mode) {
Isolate* isolate = obj->GetIsolate();
Heap* heap = isolate->heap();
FixedArray* backing_store = FixedArray::cast(obj->elements());
bool is_arguments =
(obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS);
if (is_arguments) {
backing_store = FixedArray::cast(backing_store->get(1));
}
SeededNumberDictionary* dictionary =
SeededNumberDictionary::cast(backing_store);
int entry = dictionary->FindEntry(key);
if (entry != SeededNumberDictionary::kNotFound) {
Object* result = dictionary->DeleteProperty(entry, mode);
if (result == heap->false_value()) {
if (mode == JSObject::STRICT_DELETION) {
// Deleting a non-configurable property in strict mode.
HandleScope scope(isolate);
Handle<Object> holder(obj, isolate);
Handle<Object> name = isolate->factory()->NewNumberFromUint(key);
Handle<Object> args[2] = { name, holder };
Handle<Object> error =
isolate->factory()->NewTypeError("strict_delete_property",
HandleVector(args, 2));
return isolate->Throw(*error);
}
return heap->false_value();
}
MaybeObject* maybe_elements = dictionary->Shrink(key);
FixedArray* new_elements = NULL;
if (!maybe_elements->To(&new_elements)) {
return maybe_elements;
}
if (is_arguments) {
FixedArray::cast(obj->elements())->set(1, new_elements);
} else {
obj->set_elements(new_elements);
}
}
return heap->true_value();
}
// TODO(ishell): Temporary wrapper until handlified.
MUST_USE_RESULT static Handle<Object> DeleteCommon(
MUST_USE_RESULT static MaybeHandle<Object> DeleteCommon(
Handle<JSObject> obj,
uint32_t key,
JSReceiver::DeleteMode mode) {
CALL_HEAP_FUNCTION(obj->GetIsolate(),
DeleteCommon(*obj, key, mode),
Object);
Isolate* isolate = obj->GetIsolate();
Handle<FixedArray> backing_store(FixedArray::cast(obj->elements()),
isolate);
bool is_arguments =
(obj->GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS);
if (is_arguments) {
backing_store = handle(FixedArray::cast(backing_store->get(1)), isolate);
}
Handle<SeededNumberDictionary> dictionary =
Handle<SeededNumberDictionary>::cast(backing_store);
int entry = dictionary->FindEntry(key);
if (entry != SeededNumberDictionary::kNotFound) {
Handle<Object> result =
SeededNumberDictionary::DeleteProperty(dictionary, entry, mode);
if (*result == *isolate->factory()->false_value()) {
if (mode == JSObject::STRICT_DELETION) {
// Deleting a non-configurable property in strict mode.
Handle<Object> name = isolate->factory()->NewNumberFromUint(key);
Handle<Object> args[2] = { name, obj };
Handle<Object> error =
isolate->factory()->NewTypeError("strict_delete_property",
HandleVector(args, 2));
return isolate->Throw<Object>(error);
}
return isolate->factory()->false_value();
}
Handle<FixedArray> new_elements =
SeededNumberDictionary::Shrink(dictionary, key);
if (is_arguments) {
FixedArray::cast(obj->elements())->set(1, *new_elements);
} else {
obj->set_elements(*new_elements);
}
}
return isolate->factory()->true_value();
}
static void CopyElementsImpl(Handle<FixedArrayBase> from,
@ -1546,7 +1533,7 @@ class DictionaryElementsAccessor
friend class ElementsAccessorBase<DictionaryElementsAccessor,
ElementsKindTraits<DICTIONARY_ELEMENTS> >;
MUST_USE_RESULT virtual Handle<Object> Delete(
MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
Handle<JSObject> obj,
uint32_t key,
JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {
@ -1747,7 +1734,7 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase<
return obj;
}
MUST_USE_RESULT virtual Handle<Object> Delete(
MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
Handle<JSObject> obj,
uint32_t key,
JSReceiver::DeleteMode mode) V8_FINAL V8_OVERRIDE {

View File

@ -161,7 +161,7 @@ class ElementsAccessor {
int length) = 0;
// Deletes an element in an object, returning a new elements backing store.
MUST_USE_RESULT virtual Handle<Object> Delete(
MUST_USE_RESULT virtual MaybeHandle<Object> Delete(
Handle<JSObject> holder,
uint32_t key,
JSReceiver::DeleteMode mode) = 0;

View File

@ -5189,8 +5189,9 @@ Handle<Object> JSObject::DeletePropertyWithInterceptor(Handle<JSObject> object,
}
Handle<Object> JSObject::DeleteElementWithInterceptor(Handle<JSObject> object,
uint32_t index) {
MaybeHandle<Object> JSObject::DeleteElementWithInterceptor(
Handle<JSObject> object,
uint32_t index) {
Isolate* isolate = object->GetIsolate();
Factory* factory = isolate->factory();
@ -5215,16 +5216,15 @@ Handle<Object> JSObject::DeleteElementWithInterceptor(Handle<JSObject> object,
// Rebox CustomArguments::kReturnValueOffset before returning.
return handle(*result_internal, isolate);
}
Handle<Object> delete_result = object->GetElementsAccessor()->Delete(
MaybeHandle<Object> delete_result = object->GetElementsAccessor()->Delete(
object, index, NORMAL_DELETION);
RETURN_HANDLE_IF_SCHEDULED_EXCEPTION(isolate, Object);
return delete_result;
}
Handle<Object> JSObject::DeleteElement(Handle<JSObject> object,
uint32_t index,
DeleteMode mode) {
MaybeHandle<Object> JSObject::DeleteElement(Handle<JSObject> object,
uint32_t index,
DeleteMode mode) {
Isolate* isolate = object->GetIsolate();
Factory* factory = isolate->factory();
@ -5271,12 +5271,14 @@ Handle<Object> JSObject::DeleteElement(Handle<JSObject> object,
}
// Skip interceptor if forcing deletion.
Handle<Object> result;
MaybeHandle<Object> maybe_result;
if (object->HasIndexedInterceptor() && mode != FORCE_DELETION) {
result = DeleteElementWithInterceptor(object, index);
maybe_result = DeleteElementWithInterceptor(object, index);
} else {
result = object->GetElementsAccessor()->Delete(object, index, mode);
maybe_result = object->GetElementsAccessor()->Delete(object, index, mode);
}
Handle<Object> result;
ASSIGN_RETURN_ON_EXCEPTION(isolate, result, maybe_result, Object);
if (should_enqueue_change_record && !HasLocalElement(object, index)) {
Handle<String> name = factory->Uint32ToString(index);
@ -5287,9 +5289,9 @@ Handle<Object> JSObject::DeleteElement(Handle<JSObject> object,
}
Handle<Object> JSObject::DeleteProperty(Handle<JSObject> object,
Handle<Name> name,
DeleteMode mode) {
MaybeHandle<Object> JSObject::DeleteProperty(Handle<JSObject> object,
Handle<Name> name,
DeleteMode mode) {
Isolate* isolate = object->GetIsolate();
// ECMA-262, 3rd, 8.6.2.5
ASSERT(name->IsName());
@ -14256,13 +14258,28 @@ template void Dictionary<SeededNumberDictionaryShape, uint32_t>::CopyKeysTo(
template Object* Dictionary<NameDictionaryShape, Name*>::DeleteProperty(
int, JSObject::DeleteMode);
template Handle<Object> Dictionary<NameDictionaryShape, Name*>::DeleteProperty(
Handle<Dictionary<NameDictionaryShape, Name*> >,
int,
JSObject::DeleteMode);
template Object* Dictionary<SeededNumberDictionaryShape, uint32_t>::
DeleteProperty(int, JSObject::DeleteMode);
template Handle<Object>
Dictionary<SeededNumberDictionaryShape, uint32_t>::DeleteProperty(
Handle<Dictionary<SeededNumberDictionaryShape, uint32_t> >,
int,
JSObject::DeleteMode);
template MaybeObject* Dictionary<NameDictionaryShape, Name*>::Shrink(Name* n);
template MaybeObject* Dictionary<SeededNumberDictionaryShape, uint32_t>::Shrink(
uint32_t);
template Handle<FixedArray>
Dictionary<SeededNumberDictionaryShape, uint32_t>::Shrink(
Handle<Dictionary<SeededNumberDictionaryShape, uint32_t> >,
uint32_t);
template void Dictionary<NameDictionaryShape, Name*>::CopyKeysTo(
FixedArray*,
@ -15261,6 +15278,18 @@ MaybeObject* Dictionary<Shape, Key>::EnsureCapacity(int n, Key key) {
}
// TODO(ishell): Temporary wrapper until handlified.
template<typename Shape, typename Key>
Handle<Object> Dictionary<Shape, Key>::DeleteProperty(
Handle<Dictionary<Shape, Key> > dictionary,
int entry,
JSObject::DeleteMode mode) {
CALL_HEAP_FUNCTION(dictionary->GetIsolate(),
dictionary->DeleteProperty(entry, mode),
Object);
}
template<typename Shape, typename Key>
Object* Dictionary<Shape, Key>::DeleteProperty(int entry,
JSReceiver::DeleteMode mode) {
@ -15276,6 +15305,17 @@ Object* Dictionary<Shape, Key>::DeleteProperty(int entry,
}
// TODO(ishell): Temporary wrapper until handlified.
template<typename Shape, typename Key>
Handle<FixedArray> Dictionary<Shape, Key>::Shrink(
Handle<Dictionary<Shape, Key> > dictionary,
Key key) {
CALL_HEAP_FUNCTION(dictionary->GetIsolate(),
dictionary->Shrink(key),
FixedArray);
}
template<typename Shape, typename Key>
MaybeObject* Dictionary<Shape, Key>::Shrink(Key key) {
return HashTable<Shape, Key>::Shrink(key);

View File

@ -2925,9 +2925,10 @@ class JSObject: public JSReceiver {
Handle<Object> value,
PropertyAttributes attributes);
static Handle<Object> DeleteProperty(Handle<JSObject> object,
Handle<Name> name,
DeleteMode mode);
MUST_USE_RESULT static MaybeHandle<Object> DeleteProperty(
Handle<JSObject> object,
Handle<Name> name,
DeleteMode mode);
static Handle<Object> DeletePropertyPostInterceptor(Handle<JSObject> object,
Handle<Name> name,
DeleteMode mode);
@ -2939,11 +2940,13 @@ class JSObject: public JSReceiver {
Handle<Name> name,
DeleteMode mode);
static Handle<Object> DeleteElement(Handle<JSObject> object,
uint32_t index,
DeleteMode mode);
static Handle<Object> DeleteElementWithInterceptor(Handle<JSObject> object,
uint32_t index);
MUST_USE_RESULT static MaybeHandle<Object> DeleteElement(
Handle<JSObject> object,
uint32_t index,
DeleteMode mode);
MUST_USE_RESULT static MaybeHandle<Object> DeleteElementWithInterceptor(
Handle<JSObject> object,
uint32_t index);
bool ReferencesObjectFromElements(FixedArray* elements,
ElementsKind kind,
@ -3974,9 +3977,18 @@ class Dictionary: public HashTable<Shape, Key> {
// Delete a property from the dictionary.
Object* DeleteProperty(int entry, JSObject::DeleteMode mode);
// TODO(ishell): Temporary wrapper until handlified.
static Handle<Object> DeleteProperty(
Handle<Dictionary<Shape, Key> > dictionary,
int entry,
JSObject::DeleteMode mode);
// Attempt to shrink the dictionary after deletion of key.
MUST_USE_RESULT MaybeObject* Shrink(Key key);
// TODO(ishell): Temporary wrapper until handlified.
MUST_USE_RESULT static Handle<FixedArray> Shrink(
Handle<Dictionary<Shape, Key> > dictionary,
Key key);
// Returns the number of elements in the dictionary filtering out properties
// with the specified attributes.