From dd891816d40b52ad352f2517394c2f51907159b8 Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Fri, 4 Apr 2014 13:05:37 +0000 Subject: [PATCH] Callers of ElementsAccessor::AddElementsToFixedArray(), ElementsAccessor::HasElement() and ElementsAccessor::GetKeyForIndex() handlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/225623004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20513 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/builtins.cc | 4 ++-- src/elements.cc | 42 +++++++++++++++++++++++++++--------------- src/elements.h | 40 ++++++++++++++++++++++++++++++---------- src/handles.cc | 29 +++++++++-------------------- src/handles.h | 8 -------- src/objects.cc | 28 +++++++++++++++++----------- src/objects.h | 9 ++++++--- src/runtime.cc | 2 +- 8 files changed, 92 insertions(+), 70 deletions(-) diff --git a/src/builtins.cc b/src/builtins.cc index 1c6c0429b..463a15f6c 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -515,7 +515,7 @@ BUILTIN(ArrayPop) { ElementsAccessor* accessor = array->GetElementsAccessor(); int new_length = len - 1; Handle element; - if (accessor->HasElement(*array, *array, new_length, *elms_obj)) { + if (accessor->HasElement(array, array, new_length, elms_obj)) { element = accessor->Get( array, array, new_length, elms_obj); } else { @@ -756,7 +756,7 @@ BUILTIN(ArraySlice) { bool packed = true; ElementsAccessor* accessor = ElementsAccessor::ForKind(kind); for (int i = k; i < final; i++) { - if (!accessor->HasElement(*object, *object, i, *elms)) { + if (!accessor->HasElement(object, object, i, elms)) { packed = false; break; } diff --git a/src/elements.cc b/src/elements.cc index c2d31caee..cda95774b 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -622,15 +622,14 @@ class ElementsAccessorBase : public ElementsAccessor { receiver, holder, key, backing_store) != ABSENT; } - virtual bool HasElement(Object* receiver, - JSObject* holder, - uint32_t key, - FixedArrayBase* backing_store) V8_FINAL V8_OVERRIDE { - if (backing_store == NULL) { - backing_store = holder->elements(); - } + virtual bool HasElement( + Handle receiver, + Handle holder, + uint32_t key, + Handle backing_store) V8_FINAL V8_OVERRIDE { + // TODO(ishell): Handlify HasElementImpl(). return ElementsAccessorSubclass::HasElementImpl( - receiver, holder, key, backing_store); + *receiver, *holder, key, *backing_store); } // TODO(ishell): Temporary wrapper until handlified. @@ -830,11 +829,25 @@ class ElementsAccessorBase : public ElementsAccessor { from, from_start, to, from_kind, to_start, packed_size, copy_size); } - MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray( + virtual Handle AddElementsToFixedArray( + Handle receiver, + Handle holder, + Handle to, + Handle from) V8_FINAL V8_OVERRIDE { + CALL_HEAP_FUNCTION(to->GetIsolate(), + AddElementsToFixedArray( + receiver.is_null() ? NULL : *receiver, + holder.is_null() ? NULL : *holder, + *to, + *from), + FixedArray); + } + + static MUST_USE_RESULT MaybeObject* AddElementsToFixedArray( Object* receiver, JSObject* holder, FixedArray* to, - FixedArrayBase* from) V8_FINAL V8_OVERRIDE { + FixedArrayBase* from) { int len0 = to->length(); #ifdef ENABLE_SLOW_ASSERTS if (FLAG_enable_slow_asserts) { @@ -843,9 +856,6 @@ class ElementsAccessorBase : public ElementsAccessor { } } #endif - if (from == NULL) { - from = holder->elements(); - } // Optimize if 'other' is empty. // We cannot optimize if 'this' is empty, as other may have holes. @@ -922,9 +932,9 @@ class ElementsAccessorBase : public ElementsAccessor { return index; } - virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, + virtual uint32_t GetKeyForIndex(Handle backing_store, uint32_t index) V8_FINAL V8_OVERRIDE { - return ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, index); + return ElementsAccessorSubclass::GetKeyForIndexImpl(*backing_store, index); } private: @@ -1668,6 +1678,7 @@ class DictionaryElementsAccessor SeededNumberDictionary::kNotFound; } + // TODO(ishell): Handlify when all callers are handlified. static uint32_t GetKeyForIndexImpl(FixedArrayBase* store, uint32_t index) { SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); @@ -1825,6 +1836,7 @@ class SloppyArgumentsElementsAccessor : public ElementsAccessorBase< ForArray(arguments)->GetCapacity(arguments)); } + // TODO(ishell): Handlify when all callers are handlified. static uint32_t GetKeyForIndexImpl(FixedArrayBase* dict, uint32_t index) { return index; diff --git a/src/elements.h b/src/elements.h index c245550b5..1292a3cba 100644 --- a/src/elements.h +++ b/src/elements.h @@ -55,10 +55,18 @@ class ElementsAccessor { // 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. - virtual bool HasElement(Object* receiver, - JSObject* holder, - uint32_t key, - FixedArrayBase* backing_store = NULL) = 0; + virtual bool HasElement( + Handle receiver, + Handle holder, + uint32_t key, + Handle backing_store) = 0; + + inline bool HasElement( + Handle receiver, + Handle holder, + uint32_t key) { + return HasElement(receiver, holder, key, handle(holder->elements())); + } // Returns the element with the specified key or undefined if there is no such // element. This method doesn't iterate up the prototype chain. The caller @@ -181,11 +189,19 @@ class ElementsAccessor { *from_holder, 0, from_kind, to, 0, kCopyToEndAndInitializeToHole); } - MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray( - Object* receiver, - JSObject* holder, - FixedArray* to, - FixedArrayBase* from = NULL) = 0; + virtual Handle AddElementsToFixedArray( + Handle receiver, + Handle holder, + Handle to, + Handle from) = 0; + + inline Handle AddElementsToFixedArray( + Handle receiver, + Handle holder, + Handle to) { + return AddElementsToFixedArray( + receiver, holder, to, handle(holder->elements())); + } // Returns a shared ElementsAccessor for the specified ElementsKind. static ElementsAccessor* ForKind(ElementsKind elements_kind) { @@ -193,6 +209,10 @@ class ElementsAccessor { return elements_accessors_[elements_kind]; } + // TODO(ishell): Temporary wrapper until handlified. + inline static ElementsAccessor* ForArray(Handle array) { + return ForArray(*array); + } static ElementsAccessor* ForArray(FixedArrayBase* array); static void InitializeOncePerProcess(); @@ -211,7 +231,7 @@ class ElementsAccessor { // keys are equivalent to indexes, and GetKeyForIndex returns the same value // it is passed. In the NumberDictionary ElementsAccessor, GetKeyForIndex maps // the index to a key using the KeyAt method on the NumberDictionary. - virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, + virtual uint32_t GetKeyForIndex(Handle backing_store, uint32_t index) = 0; private: diff --git a/src/handles.cc b/src/handles.cc index 82df482bd..b3052ad6a 100644 --- a/src/handles.cc +++ b/src/handles.cc @@ -124,20 +124,6 @@ Address HandleScope::current_limit_address(Isolate* isolate) { } -Handle AddKeysFromJSArray(Handle content, - Handle array) { - CALL_HEAP_FUNCTION(content->GetIsolate(), - content->AddKeysFromJSArray(*array), FixedArray); -} - - -Handle UnionOfKeys(Handle first, - Handle second) { - CALL_HEAP_FUNCTION(first->GetIsolate(), - first->UnionOfKeys(*second), FixedArray); -} - - Handle ReinitializeJSGlobalProxy( Handle constructor, Handle global) { @@ -512,7 +498,8 @@ Handle GetKeysInFixedArrayFor(Handle object, args, threw); if (*threw) return content; - content = AddKeysFromJSArray(content, Handle::cast(names)); + content = FixedArray::AddKeysFromJSArray(content, + Handle::cast(names)); break; } @@ -535,7 +522,7 @@ Handle GetKeysInFixedArrayFor(Handle object, Handle element_keys = isolate->factory()->NewFixedArray(current->NumberOfEnumElements()); current->GetEnumElementKeys(*element_keys); - content = UnionOfKeys(content, element_keys); + content = FixedArray::UnionOfKeys(content, element_keys); ASSERT(ContainsOnlyValidKeys(content)); // Add the element keys from the interceptor. @@ -543,7 +530,8 @@ Handle GetKeysInFixedArrayFor(Handle object, v8::Handle result = GetKeysForIndexedInterceptor(object, current); if (!result.IsEmpty()) - content = AddKeysFromJSArray(content, v8::Utils::OpenHandle(*result)); + content = FixedArray::AddKeysFromJSArray( + content, v8::Utils::OpenHandle(*result)); ASSERT(ContainsOnlyValidKeys(content)); } @@ -564,8 +552,8 @@ Handle GetKeysInFixedArrayFor(Handle object, !current->HasNamedInterceptor() && !current->HasIndexedInterceptor()); // Compute the property keys and cache them if possible. - content = - UnionOfKeys(content, GetEnumPropertyKeys(current, cache_enum_keys)); + content = FixedArray::UnionOfKeys( + content, GetEnumPropertyKeys(current, cache_enum_keys)); ASSERT(ContainsOnlyValidKeys(content)); // Add the property keys from the interceptor. @@ -573,7 +561,8 @@ Handle GetKeysInFixedArrayFor(Handle object, v8::Handle result = GetKeysForNamedInterceptor(object, current); if (!result.IsEmpty()) - content = AddKeysFromJSArray(content, v8::Utils::OpenHandle(*result)); + content = FixedArray::AddKeysFromJSArray( + content, v8::Utils::OpenHandle(*result)); ASSERT(ContainsOnlyValidKeys(content)); } diff --git a/src/handles.h b/src/handles.h index 2dfe866be..3f6040421 100644 --- a/src/handles.h +++ b/src/handles.h @@ -305,9 +305,6 @@ Handle GetProperty(Handle obj, const char* name); Handle LookupSingleCharacterStringFromCode(Isolate* isolate, uint32_t index); -Handle AddKeysFromJSArray(Handle, - Handle array); - // Get the JS object corresponding to the given script; create it // if none exists. Handle GetScriptWrapper(Handle