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

JSArray::SetContent() handlified.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20145 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ca871bf0
......@@ -1975,12 +1975,11 @@ MUST_USE_RESULT Handle<Object> ElementsAccessorBase<ElementsAccessorSubclass,
}
}
Factory* factory = isolate->factory();
// Fall-back case: The new length is not a number so make the array
// size one and set only element to length.
Handle<FixedArray> new_backing_store = factory->NewFixedArray(1);
Handle<FixedArray> new_backing_store = isolate->factory()->NewFixedArray(1);
new_backing_store->set(0, *length);
factory->SetContent(array, new_backing_store);
JSArray::SetContent(array, new_backing_store);
return array;
}
......
......@@ -1493,14 +1493,6 @@ void Factory::SetElementsCapacityAndLength(Handle<JSArray> array,
}
void Factory::SetContent(Handle<JSArray> array,
Handle<FixedArrayBase> elements) {
CALL_HEAP_FUNCTION_VOID(
isolate(),
array->SetContent(*elements));
}
Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
Handle<JSFunction> function) {
ASSERT(function->shared()->is_generator());
......
......@@ -374,8 +374,6 @@ class Factory {
int capacity,
int length);
void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements);
Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
Handle<JSArrayBuffer> NewJSArrayBuffer();
......
......@@ -1031,7 +1031,6 @@ bool Object::IsNaN() {
}
// static
Handle<Object> Object::ToSmi(Isolate* isolate, Handle<Object> object) {
if (object->IsSmi()) return object;
if (object->IsHeapNumber()) {
......@@ -1662,6 +1661,18 @@ MaybeObject* JSObject::EnsureCanContainElements(Object** objects,
}
// TODO(ishell): Temporary wrapper until handlified.
void JSObject::EnsureCanContainElements(Handle<JSObject> object,
Handle<FixedArrayBase> elements,
uint32_t length,
EnsureElementsMode mode) {
CALL_HEAP_FUNCTION_VOID(object->GetIsolate(),
object->EnsureCanContainElements(*elements,
length,
mode));
}
MaybeObject* JSObject::EnsureCanContainElements(FixedArrayBase* elements,
uint32_t length,
EnsureElementsMode mode) {
......@@ -6569,19 +6580,19 @@ bool JSArray::AllowsSetElementsLength() {
}
MaybeObject* JSArray::SetContent(FixedArrayBase* storage) {
MaybeObject* maybe_result = EnsureCanContainElements(
storage, storage->length(), ALLOW_COPIED_DOUBLE_ELEMENTS);
if (maybe_result->IsFailure()) return maybe_result;
ASSERT((storage->map() == GetHeap()->fixed_double_array_map() &&
IsFastDoubleElementsKind(GetElementsKind())) ||
((storage->map() != GetHeap()->fixed_double_array_map()) &&
(IsFastObjectElementsKind(GetElementsKind()) ||
(IsFastSmiElementsKind(GetElementsKind()) &&
FixedArray::cast(storage)->ContainsOnlySmisOrHoles()))));
set_elements(storage);
set_length(Smi::FromInt(storage->length()));
return this;
void JSArray::SetContent(Handle<JSArray> array,
Handle<FixedArrayBase> storage) {
EnsureCanContainElements(array, storage, storage->length(),
ALLOW_COPIED_DOUBLE_ELEMENTS);
ASSERT((storage->map() == array->GetHeap()->fixed_double_array_map() &&
IsFastDoubleElementsKind(array->GetElementsKind())) ||
((storage->map() != array->GetHeap()->fixed_double_array_map()) &&
(IsFastObjectElementsKind(array->GetElementsKind()) ||
(IsFastSmiElementsKind(array->GetElementsKind()) &&
Handle<FixedArray>::cast(storage)->ContainsOnlySmisOrHoles()))));
array->set_elements(*storage);
array->set_length(Smi::FromInt(storage->length()));
}
......
......@@ -2424,6 +2424,11 @@ class JSObject: public JSReceiver {
Object** elements,
uint32_t count,
EnsureElementsMode mode);
static inline void EnsureCanContainElements(
Handle<JSObject> object,
Handle<FixedArrayBase> elements,
uint32_t length,
EnsureElementsMode mode);
MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
FixedArrayBase* elements,
uint32_t length,
......@@ -10032,7 +10037,8 @@ class JSArray: public JSObject {
Handle<Object> length);
// Set the content of the array to the content of storage.
MUST_USE_RESULT inline MaybeObject* SetContent(FixedArrayBase* storage);
static inline void SetContent(Handle<JSArray> array,
Handle<FixedArrayBase> storage);
// Casting.
static inline JSArray* cast(Object* obj);
......
......@@ -3304,8 +3304,7 @@ class FixedArrayBuilder {
}
Handle<JSArray> ToJSArray(Handle<JSArray> target_array) {
Factory* factory = target_array->GetIsolate()->factory();
factory->SetContent(target_array, array_);
JSArray::SetContent(target_array, array_);
target_array->set_length(Smi::FromInt(length_));
return target_array;
}
......@@ -4581,7 +4580,7 @@ static MaybeObject* SearchRegExpMultiple(
Handle<FixedArray> cached_fixed_array =
Handle<FixedArray>(FixedArray::cast(*cached_answer));
// The cache FixedArray is a COW-array and can therefore be reused.
isolate->factory()->SetContent(result_array, cached_fixed_array);
JSArray::SetContent(result_array, cached_fixed_array);
// The actual length of the result array is stored in the last element of
// the backing store (the backing FixedArray may have a larger capacity).
Object* cached_fixed_array_last_element =
......@@ -9699,8 +9698,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DateCacheVersion) {
// Return result as a JS array.
Handle<JSObject> result =
isolate->factory()->NewJSObject(isolate->array_function());
isolate->factory()->SetContent(Handle<JSArray>::cast(result),
date_cache_version);
JSArray::SetContent(Handle<JSArray>::cast(result), date_cache_version);
return *result;
}
......@@ -12976,7 +12974,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetLoadedScripts) {
// Return result as a JS array.
Handle<JSObject> result =
isolate->factory()->NewJSObject(isolate->array_function());
isolate->factory()->SetContent(Handle<JSArray>::cast(result), instances);
JSArray::SetContent(Handle<JSArray>::cast(result), instances);
return *result;
}
......@@ -13106,7 +13104,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugReferencedBy) {
isolate->context()->native_context()->array_function());
Handle<JSObject> result = isolate->factory()->NewJSObject(constructor);
isolate->factory()->SetContent(Handle<JSArray>::cast(result), instances);
JSArray::SetContent(Handle<JSArray>::cast(result), instances);
return *result;
}
......@@ -13184,7 +13182,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) {
Handle<JSFunction> array_function(
isolate->context()->native_context()->array_function());
Handle<JSObject> result = isolate->factory()->NewJSObject(array_function);
isolate->factory()->SetContent(Handle<JSArray>::cast(result), instances);
JSArray::SetContent(Handle<JSArray>::cast(result), instances);
return *result;
}
......
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