Commit 9f6be9c5 authored by ishell@chromium.org's avatar ishell@chromium.org

Callers of JSArray::SetContent() handlified.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20128 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c92de5d1
...@@ -13042,20 +13042,20 @@ static int DebugReferencedBy(HeapIterator* iterator, ...@@ -13042,20 +13042,20 @@ static int DebugReferencedBy(HeapIterator* iterator,
// args[1]: constructor function for instances to exclude (Mirror) // args[1]: constructor function for instances to exclude (Mirror)
// args[2]: the the maximum number of objects to return // args[2]: the the maximum number of objects to return
RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugReferencedBy) { RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugReferencedBy) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 3); ASSERT(args.length() == 3);
// First perform a full GC in order to avoid references from dead objects. // First perform a full GC in order to avoid references from dead objects.
isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask, Heap* heap = isolate->heap();
"%DebugReferencedBy"); heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugReferencedBy");
// The heap iterator reserves the right to do a GC to make the heap iterable. // The heap iterator reserves the right to do a GC to make the heap iterable.
// Due to the GC above we know it won't need to do that, but it seems cleaner // Due to the GC above we know it won't need to do that, but it seems cleaner
// to get the heap iterator constructed before we start having unprotected // to get the heap iterator constructed before we start having unprotected
// Object* locals that are not protected by handles. // Object* locals that are not protected by handles.
// Check parameters. // Check parameters.
CONVERT_ARG_CHECKED(JSObject, target, 0); CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0);
Object* instance_filter = args[1]; Handle<Object> instance_filter = args.at<Object>(1);
RUNTIME_ASSERT(instance_filter->IsUndefined() || RUNTIME_ASSERT(instance_filter->IsUndefined() ||
instance_filter->IsJSObject()); instance_filter->IsJSObject());
CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]);
...@@ -13063,40 +13063,36 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugReferencedBy) { ...@@ -13063,40 +13063,36 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugReferencedBy) {
// Get the constructor function for context extension and arguments array. // Get the constructor function for context extension and arguments array.
JSObject* arguments_boilerplate = Handle<JSObject> arguments_boilerplate(
isolate->context()->native_context()->sloppy_arguments_boilerplate(); isolate->context()->native_context()->sloppy_arguments_boilerplate());
JSFunction* arguments_function = Handle<JSFunction> arguments_function(
JSFunction::cast(arguments_boilerplate->map()->constructor()); JSFunction::cast(arguments_boilerplate->map()->constructor()));
// Get the number of referencing objects. // Get the number of referencing objects.
int count; int count;
Heap* heap = isolate->heap();
HeapIterator heap_iterator(heap); HeapIterator heap_iterator(heap);
count = DebugReferencedBy(&heap_iterator, count = DebugReferencedBy(&heap_iterator,
target, instance_filter, max_references, *target, *instance_filter, max_references,
NULL, 0, arguments_function); NULL, 0, *arguments_function);
// Allocate an array to hold the result. // Allocate an array to hold the result.
Object* object; Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count);
{ MaybeObject* maybe_object = heap->AllocateFixedArray(count);
if (!maybe_object->ToObject(&object)) return maybe_object;
}
FixedArray* instances = FixedArray::cast(object);
// Fill the referencing objects. // Fill the referencing objects.
// AllocateFixedArray above does not make the heap non-iterable. // AllocateFixedArray above does not make the heap non-iterable.
ASSERT(heap->IsHeapIterable()); ASSERT(heap->IsHeapIterable());
HeapIterator heap_iterator2(heap); HeapIterator heap_iterator2(heap);
count = DebugReferencedBy(&heap_iterator2, count = DebugReferencedBy(&heap_iterator2,
target, instance_filter, max_references, *target, *instance_filter, max_references,
instances, count, arguments_function); *instances, count, *arguments_function);
// Return result as JS array. // Return result as JS array.
Object* result; Handle<JSFunction> constructor(
MaybeObject* maybe_result = heap->AllocateJSObject(
isolate->context()->native_context()->array_function()); isolate->context()->native_context()->array_function());
if (!maybe_result->ToObject(&result)) return maybe_result;
return JSArray::cast(result)->SetContent(instances); Handle<JSObject> result = isolate->factory()->NewJSObject(constructor);
isolate->factory()->SetContent(Handle<JSArray>::cast(result), instances);
return *result;
} }
...@@ -13136,7 +13132,7 @@ static int DebugConstructedBy(HeapIterator* iterator, ...@@ -13136,7 +13132,7 @@ static int DebugConstructedBy(HeapIterator* iterator,
// args[0]: the constructor to find instances of // args[0]: the constructor to find instances of
// args[1]: the the maximum number of objects to return // args[1]: the the maximum number of objects to return
RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) { RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) {
SealHandleScope shs(isolate); HandleScope scope(isolate);
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
// First perform a full GC in order to avoid dead objects. // First perform a full GC in order to avoid dead objects.
...@@ -13144,7 +13140,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) { ...@@ -13144,7 +13140,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) {
heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy");
// Check parameters. // Check parameters.
CONVERT_ARG_CHECKED(JSFunction, constructor, 0); CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0);
CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]);
RUNTIME_ASSERT(max_references >= 0); RUNTIME_ASSERT(max_references >= 0);
...@@ -13152,34 +13148,29 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) { ...@@ -13152,34 +13148,29 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) {
int count; int count;
HeapIterator heap_iterator(heap); HeapIterator heap_iterator(heap);
count = DebugConstructedBy(&heap_iterator, count = DebugConstructedBy(&heap_iterator,
constructor, *constructor,
max_references, max_references,
NULL, NULL,
0); 0);
// Allocate an array to hold the result. // Allocate an array to hold the result.
Object* object; Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count);
{ MaybeObject* maybe_object = heap->AllocateFixedArray(count);
if (!maybe_object->ToObject(&object)) return maybe_object;
}
FixedArray* instances = FixedArray::cast(object);
ASSERT(isolate->heap()->IsHeapIterable()); ASSERT(heap->IsHeapIterable());
// Fill the referencing objects. // Fill the referencing objects.
HeapIterator heap_iterator2(heap); HeapIterator heap_iterator2(heap);
count = DebugConstructedBy(&heap_iterator2, count = DebugConstructedBy(&heap_iterator2,
constructor, *constructor,
max_references, max_references,
instances, *instances,
count); count);
// Return result as JS array. // Return result as JS array.
Object* result; Handle<JSFunction> array_function(
{ MaybeObject* maybe_result = isolate->heap()->AllocateJSObject(
isolate->context()->native_context()->array_function()); isolate->context()->native_context()->array_function());
if (!maybe_result->ToObject(&result)) return maybe_result; Handle<JSObject> result = isolate->factory()->NewJSObject(array_function);
} isolate->factory()->SetContent(Handle<JSArray>::cast(result), instances);
return JSArray::cast(result)->SetContent(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