Commit dd891816 authored by ishell@chromium.org's avatar ishell@chromium.org

Callers of ElementsAccessor::AddElementsToFixedArray(),...

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
parent 0c2c71c1
......@@ -515,7 +515,7 @@ BUILTIN(ArrayPop) {
ElementsAccessor* accessor = array->GetElementsAccessor();
int new_length = len - 1;
Handle<Object> 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;
}
......
......@@ -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<Object> receiver,
Handle<JSObject> holder,
uint32_t key,
Handle<FixedArrayBase> 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<FixedArray> AddElementsToFixedArray(
Handle<Object> receiver,
Handle<JSObject> holder,
Handle<FixedArray> to,
Handle<FixedArrayBase> 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<FixedArrayBase> 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;
......
......@@ -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<Object> receiver,
Handle<JSObject> holder,
uint32_t key,
Handle<FixedArrayBase> backing_store) = 0;
inline bool HasElement(
Handle<Object> receiver,
Handle<JSObject> 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<FixedArray> AddElementsToFixedArray(
Handle<Object> receiver,
Handle<JSObject> holder,
Handle<FixedArray> to,
Handle<FixedArrayBase> from) = 0;
inline Handle<FixedArray> AddElementsToFixedArray(
Handle<Object> receiver,
Handle<JSObject> holder,
Handle<FixedArray> 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<FixedArrayBase> 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<FixedArrayBase> backing_store,
uint32_t index) = 0;
private:
......
......@@ -124,20 +124,6 @@ Address HandleScope::current_limit_address(Isolate* isolate) {
}
Handle<FixedArray> AddKeysFromJSArray(Handle<FixedArray> content,
Handle<JSArray> array) {
CALL_HEAP_FUNCTION(content->GetIsolate(),
content->AddKeysFromJSArray(*array), FixedArray);
}
Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
Handle<FixedArray> second) {
CALL_HEAP_FUNCTION(first->GetIsolate(),
first->UnionOfKeys(*second), FixedArray);
}
Handle<JSGlobalProxy> ReinitializeJSGlobalProxy(
Handle<JSFunction> constructor,
Handle<JSGlobalProxy> global) {
......@@ -512,7 +498,8 @@ Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
args,
threw);
if (*threw) return content;
content = AddKeysFromJSArray(content, Handle<JSArray>::cast(names));
content = FixedArray::AddKeysFromJSArray(content,
Handle<JSArray>::cast(names));
break;
}
......@@ -535,7 +522,7 @@ Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
Handle<FixedArray> 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<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
v8::Handle<v8::Array> 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<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> 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<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
v8::Handle<v8::Array> 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));
}
......
......@@ -305,9 +305,6 @@ Handle<Object> GetProperty(Handle<JSReceiver> obj, const char* name);
Handle<String> LookupSingleCharacterStringFromCode(Isolate* isolate,
uint32_t index);
Handle<FixedArray> AddKeysFromJSArray(Handle<FixedArray>,
Handle<JSArray> array);
// Get the JS object corresponding to the given script; create it
// if none exists.
Handle<JSValue> GetScriptWrapper(Handle<Script> script);
......@@ -344,11 +341,6 @@ Handle<FixedArray> ReduceFixedArrayTo(Handle<FixedArray> array, int length);
Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
bool cache_result);
// Computes the union of keys and return the result.
// Used for implementing "for (n in object) { }"
Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
Handle<FixedArray> second);
Handle<JSGlobalProxy> ReinitializeJSGlobalProxy(
Handle<JSFunction> constructor,
Handle<JSGlobalProxy> global);
......
......@@ -7906,14 +7906,15 @@ void FixedArray::Shrink(int new_length) {
}
MaybeObject* FixedArray::AddKeysFromJSArray(JSArray* array) {
Handle<FixedArray> FixedArray::AddKeysFromJSArray(Handle<FixedArray> content,
Handle<JSArray> array) {
ElementsAccessor* accessor = array->GetElementsAccessor();
MaybeObject* maybe_result =
accessor->AddElementsToFixedArray(array, array, this);
FixedArray* result;
if (!maybe_result->To<FixedArray>(&result)) return maybe_result;
Handle<FixedArray> result =
accessor->AddElementsToFixedArray(array, array, content);
#ifdef ENABLE_SLOW_ASSERTS
if (FLAG_enable_slow_asserts) {
DisallowHeapAllocation no_allocation;
for (int i = 0; i < result->length(); i++) {
Object* current = result->get(i);
ASSERT(current->IsNumber() || current->IsName());
......@@ -7924,14 +7925,19 @@ MaybeObject* FixedArray::AddKeysFromJSArray(JSArray* array) {
}
MaybeObject* FixedArray::UnionOfKeys(FixedArray* other) {
ElementsAccessor* accessor = ElementsAccessor::ForArray(other);
MaybeObject* maybe_result =
accessor->AddElementsToFixedArray(NULL, NULL, this, other);
FixedArray* result;
if (!maybe_result->To(&result)) return maybe_result;
Handle<FixedArray> FixedArray::UnionOfKeys(Handle<FixedArray> first,
Handle<FixedArray> second) {
ElementsAccessor* accessor = ElementsAccessor::ForArray(second);
Handle<FixedArray> result =
accessor->AddElementsToFixedArray(
Handle<Object>::null(), // receiver
Handle<JSObject>::null(), // holder
first,
Handle<FixedArrayBase>::cast(second));
#ifdef ENABLE_SLOW_ASSERTS
if (FLAG_enable_slow_asserts) {
DisallowHeapAllocation no_allocation;
for (int i = 0; i < result->length(); i++) {
Object* current = result->get(i);
ASSERT(current->IsNumber() || current->IsName());
......
......@@ -3060,10 +3060,13 @@ class FixedArray: public FixedArrayBase {
PretenureFlag pretenure = NOT_TENURED);
// Add the elements of a JSArray to this FixedArray.
MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array);
static Handle<FixedArray> AddKeysFromJSArray(Handle<FixedArray> content,
Handle<JSArray> array);
// Compute the union of this and other.
MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other);
// Computes the union of keys and return the result.
// Used for implementing "for (n in object) { }"
static Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
Handle<FixedArray> second);
// Copy a sub array from the receiver to dest.
void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
......
......@@ -10716,7 +10716,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetArrayKeys) {
isolate->factory()->NewFixedArray(
current->NumberOfLocalElements(NONE));
current->GetLocalElementKeys(*current_keys, NONE);
keys = UnionOfKeys(keys, current_keys);
keys = FixedArray::UnionOfKeys(keys, current_keys);
}
// Erase any keys >= length.
// TODO(adamk): Remove this step when the contract of %GetArrayKeys
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment