Commit 50945297 authored by ulan@chromium.org's avatar ulan@chromium.org

Refactor function.arguments accessor.

This prepares for API-style accessor conversion.

BUG=
R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20943 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ea0de1e9
......@@ -969,16 +969,7 @@ const AccessorDescriptor Accessors::FunctionName = {
//
Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
CALL_HEAP_FUNCTION(function->GetIsolate(),
Accessors::FunctionGetArguments(function->GetIsolate(),
*function,
NULL),
Object);
}
static Object* ConstructArgumentsObjectForInlinedFunction(
static Handle<Object> ArgumentsForInlinedFunction(
JavaScriptFrame* frame,
Handle<JSFunction> inlined_function,
int inlined_frame_index) {
......@@ -1002,34 +993,38 @@ static Object* ConstructArgumentsObjectForInlinedFunction(
arguments->set_elements(*array);
// Return the freshly allocated arguments object.
return *arguments;
return arguments;
}
Object* Accessors::FunctionGetArguments(Isolate* isolate,
Object* object,
void*) {
HandleScope scope(isolate);
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
if (holder == NULL) return isolate->heap()->undefined_value();
Handle<JSFunction> function(holder, isolate);
static int FindFunctionInFrame(JavaScriptFrame* frame,
Handle<JSFunction> function) {
DisallowHeapAllocation no_allocation;
List<JSFunction*> functions(2);
frame->GetFunctions(&functions);
for (int i = functions.length() - 1; i >= 0; i--) {
if (functions[i] == *function) return i;
}
return -1;
}
Handle<Object> GetFunctionArguments(Isolate* isolate,
Handle<JSFunction> function) {
if (function->shared()->native()) return isolate->factory()->null_value();
if (function->shared()->native()) return isolate->heap()->null_value();
// Find the top invocation of the function by traversing frames.
List<JSFunction*> functions(2);
for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
JavaScriptFrame* frame = it.frame();
frame->GetFunctions(&functions);
for (int i = functions.length() - 1; i >= 0; i--) {
// Skip all frames that aren't invocations of the given function.
if (functions[i] != *function) continue;
int function_index = FindFunctionInFrame(frame, function);
if (function_index < 0) continue;
if (i > 0) {
if (function_index > 0) {
// The function in question was inlined. Inlined functions have the
// correct number of arguments and no allocated arguments object, so
// we can construct a fresh one by interpreting the function's
// deoptimization input data.
return ConstructArgumentsObjectForInlinedFunction(frame, function, i);
return ArgumentsForInlinedFunction(frame, function, function_index);
}
if (!frame->is_optimized()) {
......@@ -1039,7 +1034,7 @@ Object* Accessors::FunctionGetArguments(Isolate* isolate,
isolate->heap()->arguments_string());
if (index >= 0) {
Handle<Object> arguments(frame->GetExpression(index), isolate);
if (!arguments->IsArgumentsMarker()) return *arguments;
if (!arguments->IsArgumentsMarker()) return arguments;
}
}
......@@ -1062,13 +1057,31 @@ Object* Accessors::FunctionGetArguments(Isolate* isolate,
arguments->set_elements(*array);
// Return the freshly allocated arguments object.
return *arguments;
}
functions.Rewind(0);
return arguments;
}
// No frame corresponding to the given function found. Return null.
return isolate->heap()->null_value();
return isolate->factory()->null_value();
}
Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
return GetFunctionArguments(function->GetIsolate(), function);
}
Object* Accessors::FunctionGetArguments(Isolate* isolate,
Object* object,
void*) {
HandleScope scope(isolate);
Handle<JSFunction> function;
{
DisallowHeapAllocation no_allocation;
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
if (holder == NULL) return isolate->heap()->undefined_value();
function = Handle<JSFunction>(holder, isolate);
}
return *GetFunctionArguments(isolate, function);
}
......
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