Commit 28aca51e authored by titzer@chromium.org's avatar titzer@chromium.org

Refactor JavaScriptFrame::function() to return a JSFunction* and remove associated casts.

BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15638 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d1d5f59d
......@@ -565,8 +565,7 @@ static Handle<SharedFunctionInfo> MakeFunctionInfo(CompilationInfo* info) {
if (info->is_eval()) {
StackTraceFrameIterator it(isolate);
if (!it.done()) {
script->set_eval_from_shared(
JSFunction::cast(it.frame()->function())->shared());
script->set_eval_from_shared(it.frame()->function()->shared());
Code* code = it.frame()->LookupCode();
int offset = static_cast<int>(
it.frame()->pc() - code->instruction_start());
......
......@@ -965,7 +965,7 @@ Object* Debug::Break(Arguments args) {
// Get the debug info (create it if it does not exist).
Handle<SharedFunctionInfo> shared =
Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared());
Handle<SharedFunctionInfo>(frame->function()->shared());
Handle<DebugInfo> debug_info = GetDebugInfo(shared);
// Find the break point where execution has stopped.
......@@ -1348,8 +1348,7 @@ void Debug::FloodHandlerWithOneShot() {
JavaScriptFrame* frame = it.frame();
if (frame->HasHandler()) {
// Flood the function with the catch block with break points
JSFunction* function = JSFunction::cast(frame->function());
FloodWithOneShot(Handle<JSFunction>(function));
FloodWithOneShot(Handle<JSFunction>(frame->function()));
return;
}
}
......@@ -1415,13 +1414,13 @@ void Debug::PrepareStep(StepAction step_action, int step_count) {
// breakpoints.
frames_it.Advance();
// Fill the function to return to with one-shot break points.
JSFunction* function = JSFunction::cast(frames_it.frame()->function());
JSFunction* function = frames_it.frame()->function();
FloodWithOneShot(Handle<JSFunction>(function));
return;
}
// Get the debug info (create it if it does not exist).
Handle<JSFunction> function(JSFunction::cast(frame->function()));
Handle<JSFunction> function(frame->function());
Handle<SharedFunctionInfo> shared(function->shared());
if (!EnsureDebugInfo(shared, function)) {
// Return if ensuring debug info failed.
......@@ -1486,15 +1485,14 @@ void Debug::PrepareStep(StepAction step_action, int step_count) {
frames_it.Advance();
}
// Skip builtin functions on the stack.
while (!frames_it.done() &&
JSFunction::cast(frames_it.frame()->function())->IsBuiltin()) {
while (!frames_it.done() && frames_it.frame()->function()->IsBuiltin()) {
frames_it.Advance();
}
// Step out: If there is a JavaScript caller frame, we need to
// flood it with breakpoints.
if (!frames_it.done()) {
// Fill the function to return to with one-shot break points.
JSFunction* function = JSFunction::cast(frames_it.frame()->function());
JSFunction* function = frames_it.frame()->function();
FloodWithOneShot(Handle<JSFunction>(function));
// Set target frame pointer.
ActivateStepOut(frames_it.frame());
......@@ -1916,7 +1914,7 @@ static void CollectActiveFunctionsFromThread(
function->shared()->code()->set_gc_metadata(active_code_marker);
}
} else if (frame->function()->IsJSFunction()) {
JSFunction* function = JSFunction::cast(frame->function());
JSFunction* function = frame->function();
ASSERT(frame->LookupCode()->kind() == Code::FUNCTION);
active_functions->Add(Handle<JSFunction>(function));
function->shared()->code()->set_gc_metadata(active_code_marker);
......@@ -1933,7 +1931,7 @@ static void RedirectActivationsToRecompiledCodeOnThread(
if (frame->is_optimized() || !frame->function()->IsJSFunction()) continue;
JSFunction* function = JSFunction::cast(frame->function());
JSFunction* function = frame->function();
ASSERT(frame->LookupCode()->kind() == Code::FUNCTION);
......
......@@ -186,7 +186,7 @@ DeoptimizedFrameInfo* Deoptimizer::DebuggerInspectableFrame(
ASSERT(isolate->deoptimizer_data()->deoptimized_frame_info_ == NULL);
// Get the function and code from the frame.
JSFunction* function = JSFunction::cast(frame->function());
JSFunction* function = frame->function();
Code* code = frame->LookupCode();
// Locate the deoptimization point in the code. As we are at a call the
......@@ -1609,7 +1609,7 @@ void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) {
for (int frame_index = 0; frame_index < jsframe_count(); ++frame_index) {
if (frame_index != 0) it->Advance();
JavaScriptFrame* frame = it->frame();
Handle<JSFunction> function(JSFunction::cast(frame->function()), isolate_);
Handle<JSFunction> function(frame->function(), isolate_);
Handle<JSObject> arguments;
for (int i = frame->ComputeExpressionsCount() - 1; i >= 0; --i) {
if (frame->GetExpression(i) == isolate_->heap()->arguments_marker()) {
......
......@@ -274,10 +274,8 @@ inline bool JavaScriptFrame::has_adapted_arguments() const {
}
inline Object* JavaScriptFrame::function() const {
Object* result = function_slot_object();
ASSERT(result->IsJSFunction());
return result;
inline JSFunction* JavaScriptFrame::function() const {
return JSFunction::cast(function_slot_object());
}
......
......@@ -205,7 +205,7 @@ void StackTraceFrameIterator::Advance() {
bool StackTraceFrameIterator::IsValidFrame() {
if (!frame()->function()->IsJSFunction()) return false;
Object* script = JSFunction::cast(frame()->function())->shared()->script();
Object* script = frame()->function()->shared()->script();
// Don't show functions from native scripts to user.
return (script->IsScript() &&
Script::TYPE_NATIVE != Script::cast(script)->type()->value());
......@@ -724,8 +724,7 @@ int JavaScriptFrame::GetArgumentsLength() const {
Code* JavaScriptFrame::unchecked_code() const {
JSFunction* function = JSFunction::cast(this->function());
return function->code();
return function()->code();
}
......@@ -733,8 +732,7 @@ int JavaScriptFrame::GetNumberOfIncomingArguments() const {
ASSERT(can_access_heap_objects() &&
isolate()->heap()->gc_state() == Heap::NOT_IN_GC);
JSFunction* function = JSFunction::cast(this->function());
return function->shared()->formal_parameter_count();
return function()->shared()->formal_parameter_count();
}
......@@ -745,7 +743,7 @@ Address JavaScriptFrame::GetCallerStackPointer() const {
void JavaScriptFrame::GetFunctions(List<JSFunction*>* functions) {
ASSERT(functions->length() == 0);
functions->Add(JSFunction::cast(function()));
functions->Add(function());
}
......@@ -754,7 +752,7 @@ void JavaScriptFrame::Summarize(List<FrameSummary>* functions) {
Code* code_pointer = LookupCode();
int offset = static_cast<int>(pc() - code_pointer->address());
FrameSummary summary(receiver(),
JSFunction::cast(function()),
function(),
code_pointer,
offset,
IsConstructor());
......@@ -775,40 +773,35 @@ void JavaScriptFrame::PrintTop(Isolate* isolate,
JavaScriptFrame* frame = it.frame();
if (frame->IsConstructor()) PrintF(file, "new ");
// function name
Object* maybe_fun = frame->function();
if (maybe_fun->IsJSFunction()) {
JSFunction* fun = JSFunction::cast(maybe_fun);
fun->PrintName();
Code* js_code = frame->unchecked_code();
Address pc = frame->pc();
int code_offset =
static_cast<int>(pc - js_code->instruction_start());
PrintF("+%d", code_offset);
SharedFunctionInfo* shared = fun->shared();
if (print_line_number) {
Code* code = Code::cast(
v8::internal::Isolate::Current()->heap()->FindCodeObject(pc));
int source_pos = code->SourcePosition(pc);
Object* maybe_script = shared->script();
if (maybe_script->IsScript()) {
Handle<Script> script(Script::cast(maybe_script));
int line = GetScriptLineNumberSafe(script, source_pos) + 1;
Object* script_name_raw = script->name();
if (script_name_raw->IsString()) {
String* script_name = String::cast(script->name());
SmartArrayPointer<char> c_script_name =
script_name->ToCString(DISALLOW_NULLS,
ROBUST_STRING_TRAVERSAL);
PrintF(file, " at %s:%d", *c_script_name, line);
} else {
PrintF(file, " at <unknown>:%d", line);
}
JSFunction* fun = frame->function();
fun->PrintName();
Code* js_code = frame->unchecked_code();
Address pc = frame->pc();
int code_offset =
static_cast<int>(pc - js_code->instruction_start());
PrintF("+%d", code_offset);
SharedFunctionInfo* shared = fun->shared();
if (print_line_number) {
Code* code = Code::cast(
v8::internal::Isolate::Current()->heap()->FindCodeObject(pc));
int source_pos = code->SourcePosition(pc);
Object* maybe_script = shared->script();
if (maybe_script->IsScript()) {
Handle<Script> script(Script::cast(maybe_script));
int line = GetScriptLineNumberSafe(script, source_pos) + 1;
Object* script_name_raw = script->name();
if (script_name_raw->IsString()) {
String* script_name = String::cast(script->name());
SmartArrayPointer<char> c_script_name =
script_name->ToCString(DISALLOW_NULLS,
ROBUST_STRING_TRAVERSAL);
PrintF(file, " at %s:%d", *c_script_name, line);
} else {
PrintF(file, " at <unknown>:<unknown>");
PrintF(file, " at <unknown>:%d", line);
}
} else {
PrintF(file, " at <unknown>:<unknown>");
}
} else {
PrintF("<unknown>");
}
if (print_args) {
......@@ -913,7 +906,7 @@ void FrameSummary::Print() {
JSFunction* OptimizedFrame::LiteralAt(FixedArray* literal_array,
int literal_id) {
if (literal_id == Translation::kSelfLiteralId) {
return JSFunction::cast(function());
return function();
}
return JSFunction::cast(literal_array->get(literal_id));
......@@ -1018,7 +1011,7 @@ DeoptimizationInputData* OptimizedFrame::GetDeoptimizationData(
int* deopt_index) {
ASSERT(is_optimized());
JSFunction* opt_function = JSFunction::cast(function());
JSFunction* opt_function = function();
Code* code = opt_function->code();
// The code object may have been replaced by lazy deoptimization. Fall
......@@ -1132,7 +1125,7 @@ void JavaScriptFrame::Print(StringStream* accumulator,
int index) const {
HandleScope scope(isolate());
Object* receiver = this->receiver();
Object* function = this->function();
JSFunction* function = this->function();
accumulator->PrintSecurityTokenIfChanged(function);
PrintIndex(accumulator, mode, index);
......@@ -1146,29 +1139,27 @@ void JavaScriptFrame::Print(StringStream* accumulator,
// or context slots.
Handle<ScopeInfo> scope_info(ScopeInfo::Empty(isolate()));
if (function->IsJSFunction()) {
Handle<SharedFunctionInfo> shared(JSFunction::cast(function)->shared());
scope_info = Handle<ScopeInfo>(shared->scope_info());
Object* script_obj = shared->script();
if (script_obj->IsScript()) {
Handle<Script> script(Script::cast(script_obj));
accumulator->Add(" [");
accumulator->PrintName(script->name());
Address pc = this->pc();
if (code != NULL && code->kind() == Code::FUNCTION &&
pc >= code->instruction_start() && pc < code->instruction_end()) {
int source_pos = code->SourcePosition(pc);
int line = GetScriptLineNumberSafe(script, source_pos) + 1;
accumulator->Add(":%d", line);
} else {
int function_start_pos = shared->start_position();
int line = GetScriptLineNumberSafe(script, function_start_pos) + 1;
accumulator->Add(":~%d", line);
}
accumulator->Add("] ");
Handle<SharedFunctionInfo> shared(function->shared());
scope_info = Handle<ScopeInfo>(shared->scope_info());
Object* script_obj = shared->script();
if (script_obj->IsScript()) {
Handle<Script> script(Script::cast(script_obj));
accumulator->Add(" [");
accumulator->PrintName(script->name());
Address pc = this->pc();
if (code != NULL && code->kind() == Code::FUNCTION &&
pc >= code->instruction_start() && pc < code->instruction_end()) {
int source_pos = code->SourcePosition(pc);
int line = GetScriptLineNumberSafe(script, source_pos) + 1;
accumulator->Add(":%d", line);
} else {
int function_start_pos = shared->start_position();
int line = GetScriptLineNumberSafe(script, function_start_pos) + 1;
accumulator->Add(":~%d", line);
}
accumulator->Add("] ");
}
accumulator->Add("(this=%o", receiver);
......@@ -1258,7 +1249,7 @@ void JavaScriptFrame::Print(StringStream* accumulator,
// Print details about the function.
if (FLAG_max_stack_trace_source_length != 0 && code != NULL) {
SharedFunctionInfo* shared = JSFunction::cast(function)->shared();
SharedFunctionInfo* shared = function->shared();
accumulator->Add("--------- s o u r c e c o d e ---------\n");
shared->SourceCodePrint(accumulator, FLAG_max_stack_trace_source_length);
accumulator->Add("\n-----------------------------------------\n");
......@@ -1273,10 +1264,8 @@ void ArgumentsAdaptorFrame::Print(StringStream* accumulator,
int index) const {
int actual = ComputeParametersCount();
int expected = -1;
Object* function = this->function();
if (function->IsJSFunction()) {
expected = JSFunction::cast(function)->shared()->formal_parameter_count();
}
JSFunction* function = this->function();
expected = function->shared()->formal_parameter_count();
PrintIndex(accumulator, mode, index);
accumulator->Add("arguments adaptor frame: %d->%d", actual, expected);
......
......@@ -543,7 +543,7 @@ class JavaScriptFrame: public StandardFrame {
virtual Type type() const { return JAVA_SCRIPT; }
// Accessors.
inline Object* function() const;
inline JSFunction* function() const;
inline Object* receiver() const;
inline void set_receiver(Object* value);
......
......@@ -159,7 +159,7 @@ Address IC::OriginalCodeAddress() const {
JavaScriptFrame* frame = JavaScriptFrame::cast(it.frame());
// Find the function on the stack and both the active code for the
// function and the original code.
JSFunction* function = JSFunction::cast(frame->function());
JSFunction* function = frame->function();
Handle<SharedFunctionInfo> shared(function->shared(), isolate());
Code* code = shared->code();
ASSERT(Debug::HasDebugInfo(shared));
......
......@@ -622,10 +622,8 @@ static bool IsVisibleInStackTrace(StackFrame* raw_frame,
// Only display JS frames.
if (!raw_frame->is_java_script()) return false;
JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame);
Object* raw_fun = frame->function();
// Not sure when this can happen but skip it just in case.
if (!raw_fun->IsJSFunction()) return false;
if ((raw_fun == caller) && !(*seen_caller)) {
JSFunction* fun = frame->function();
if ((fun == caller) && !(*seen_caller)) {
*seen_caller = true;
return false;
}
......@@ -637,7 +635,6 @@ static bool IsVisibleInStackTrace(StackFrame* raw_frame,
// The --builtins-in-stack-traces command line flag allows including
// internal call sites in the stack trace for debugging purposes.
if (!FLAG_builtins_in_stack_traces) {
JSFunction* fun = JSFunction::cast(raw_fun);
if (frame->receiver()->IsJSBuiltinsObject() ||
(fun->IsBuiltin() && !fun->shared()->native())) {
return false;
......@@ -1201,7 +1198,7 @@ void Isolate::PrintCurrentStackTrace(FILE* out) {
int pos = frame->LookupCode()->SourcePosition(frame->pc());
Handle<Object> pos_obj(Smi::FromInt(pos), this);
// Fetch function and receiver.
Handle<JSFunction> fun(JSFunction::cast(frame->function()));
Handle<JSFunction> fun(frame->function());
Handle<Object> recv(frame->receiver(), this);
// Advance to the next JavaScript frame and determine if the
// current frame is the top-level frame.
......@@ -1225,7 +1222,7 @@ void Isolate::ComputeLocation(MessageLocation* target) {
StackTraceFrameIterator it(this);
if (!it.done()) {
JavaScriptFrame* frame = it.frame();
JSFunction* fun = JSFunction::cast(frame->function());
JSFunction* fun = frame->function();
Object* script = fun->shared()->script();
if (script->IsScript() &&
!(Script::cast(script)->source()->IsUndefined())) {
......
......@@ -1621,8 +1621,7 @@ static bool CheckActivation(Handle<JSArray> shared_info_array,
LiveEdit::FunctionPatchabilityStatus status) {
if (!frame->is_java_script()) return false;
Handle<JSFunction> function(
JSFunction::cast(JavaScriptFrame::cast(frame)->function()));
Handle<JSFunction> function(JavaScriptFrame::cast(frame)->function());
Isolate* isolate = shared_info_array->GetIsolate();
int len = GetArrayLength(shared_info_array);
......
......@@ -247,7 +247,7 @@ void RuntimeProfiler::OptimizeNow() {
frame_count++ < frame_count_limit && !it.done();
it.Advance()) {
JavaScriptFrame* frame = it.frame();
JSFunction* function = JSFunction::cast(frame->function());
JSFunction* function = frame->function();
if (!FLAG_watch_ic_patching) {
// Adjust threshold each time we have processed
......
......@@ -2797,7 +2797,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSGeneratorObject) {
JavaScriptFrameIterator it(isolate);
JavaScriptFrame* frame = it.frame();
JSFunction* function = JSFunction::cast(frame->function());
JSFunction* function = frame->function();
RUNTIME_ASSERT(function->shared()->is_generator());
JSGeneratorObject* generator;
......@@ -2826,8 +2826,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_SuspendJSGeneratorObject) {
JavaScriptFrameIterator stack_iterator(isolate);
JavaScriptFrame* frame = stack_iterator.frame();
RUNTIME_ASSERT(JSFunction::cast(frame->function())->shared()->is_generator());
ASSERT_EQ(JSFunction::cast(frame->function()), generator_object->function());
RUNTIME_ASSERT(frame->function()->shared()->is_generator());
ASSERT_EQ(frame->function(), generator_object->function());
// The caller should have saved the context and continuation already.
ASSERT_EQ(generator_object->context(), Context::cast(frame->context()));
......@@ -5732,9 +5732,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetArgumentsProperty) {
// Handle special arguments properties.
if (key->Equals(isolate->heap()->length_string())) return Smi::FromInt(n);
if (key->Equals(isolate->heap()->callee_string())) {
Object* function = frame->function();
if (function->IsJSFunction() &&
!JSFunction::cast(function)->shared()->is_classic_mode()) {
JSFunction* function = frame->function();
if (!function->shared()->is_classic_mode()) {
return isolate->Throw(*isolate->factory()->NewTypeError(
"strict_arguments_callee", HandleVector<Object>(NULL, 0)));
}
......@@ -8221,7 +8220,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyDeoptimized) {
JavaScriptFrame* frame = it.frame();
RUNTIME_ASSERT(frame->function()->IsJSFunction());
Handle<JSFunction> function(JSFunction::cast(frame->function()), isolate);
Handle<JSFunction> function(frame->function(), isolate);
Handle<Code> optimized_code(function->code());
RUNTIME_ASSERT((type != Deoptimizer::EAGER &&
type != Deoptimizer::SOFT) || function->IsOptimized());
......@@ -8237,7 +8236,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NotifyDeoptimized) {
bool has_other_activations = false;
while (!it.done()) {
JavaScriptFrame* frame = it.frame();
JSFunction* other_function = JSFunction::cast(frame->function());
JSFunction* other_function = frame->function();
if (frame->is_optimized() && other_function->code() == function->code()) {
has_other_activations = true;
break;
......@@ -8353,8 +8352,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_NeverOptimize) {
// Disable optimization for the calling function.
JavaScriptFrameIterator it(isolate);
if (!it.done()) {
JSFunction *function = JSFunction::cast(it.frame()->function());
function->shared()->set_optimization_disabled(true);
it.frame()->function()->shared()->set_optimization_disabled(true);
}
return isolate->heap()->undefined_value();
}
......@@ -11235,7 +11233,7 @@ static bool SetLocalVariableValue(Isolate* isolate,
return false;
}
Handle<JSFunction> function(JSFunction::cast(frame->function()));
Handle<JSFunction> function(frame->function());
Handle<SharedFunctionInfo> shared(function->shared());
Handle<ScopeInfo> scope_info(shared->scope_info());
......@@ -11482,7 +11480,7 @@ class ScopeIterator {
: isolate_(isolate),
frame_(frame),
inlined_jsframe_index_(inlined_jsframe_index),
function_(JSFunction::cast(frame->function())),
function_(frame->function()),
context_(Context::cast(frame->context())),
nested_scope_chain_(4),
failed_(false) {
......@@ -11863,7 +11861,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetStepInPositions) {
JavaScriptFrame* frame = frame_it.frame();
Handle<SharedFunctionInfo> shared =
Handle<SharedFunctionInfo>(JSFunction::cast(frame->function())->shared());
Handle<SharedFunctionInfo>(frame->function()->shared());
Handle<DebugInfo> debug_info = Debug::GetDebugInfo(shared);
int len = 0;
......
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