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