Commit 6d54362d authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Fixes bug with v8::StackTrace for non-zero script line offsets

Change by jaimeyap see http://codereview.chromium.org/1985004 for details.
Review URL: http://codereview.chromium.org/2049004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4623 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8d511957
...@@ -394,21 +394,20 @@ Local<StackTrace> Top::CaptureCurrentStackTrace( ...@@ -394,21 +394,20 @@ Local<StackTrace> Top::CaptureCurrentStackTrace(
int script_line_offset = script->line_offset()->value(); int script_line_offset = script->line_offset()->value();
int position = frame->code()->SourcePosition(frame->pc()); int position = frame->code()->SourcePosition(frame->pc());
int line_number = GetScriptLineNumber(Handle<Script>(script), position); int line_number = GetScriptLineNumber(Handle<Script>(script), position);
// line_number is already shifted by the script_line_offset.
if (options & StackTrace::kColumnOffset) { int relative_line_number = line_number - script_line_offset;
if (options & StackTrace::kColumnOffset && relative_line_number >= 0) {
Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
int start = (line_number == 0) ? int start = (relative_line_number == 0) ? 0 :
0 : Smi::cast(line_ends->get(line_number - 1))->value() + 1; Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1;
int column_offset = position - start; int column_offset = position - start;
if (line_number == script_line_offset) { if (relative_line_number == 0) {
// For the case where the code is on the same line as the script tag. // For the case where the code is on the same line as the script tag.
column_offset += script_line_offset; column_offset += script->column_offset()->value();
} }
SetProperty(stackFrame, column_key, SetProperty(stackFrame, column_key,
Handle<Smi>(Smi::FromInt(column_offset + 1)), NONE); Handle<Smi>(Smi::FromInt(column_offset + 1)), NONE);
} }
// Adjust the line_number by the offset in the parent resource.
line_number += script_line_offset;
SetProperty(stackFrame, line_key, SetProperty(stackFrame, line_key,
Handle<Smi>(Smi::FromInt(line_number + 1)), NONE); Handle<Smi>(Smi::FromInt(line_number + 1)), NONE);
} }
...@@ -420,7 +419,7 @@ Local<StackTrace> Top::CaptureCurrentStackTrace( ...@@ -420,7 +419,7 @@ Local<StackTrace> Top::CaptureCurrentStackTrace(
if (options & StackTrace::kFunctionName) { if (options & StackTrace::kFunctionName) {
Handle<Object> fun_name(fun->shared()->name()); Handle<Object> fun_name(fun->shared()->name());
if (!fun_name->IsString()) { if (fun_name->ToBoolean()->IsFalse()) {
fun_name = Handle<Object>(fun->shared()->inferred_name()); fun_name = Handle<Object>(fun->shared()->inferred_name());
} }
SetProperty(stackFrame, function_key, fun_name, NONE); SetProperty(stackFrame, function_key, fun_name, NONE);
......
...@@ -9634,14 +9634,14 @@ v8::Handle<Value> AnalyzeStackInNativeCode(const v8::Arguments& args) { ...@@ -9634,14 +9634,14 @@ v8::Handle<Value> AnalyzeStackInNativeCode(const v8::Arguments& args) {
v8::Handle<v8::StackTrace> stackTrace = v8::Handle<v8::StackTrace> stackTrace =
v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
CHECK_EQ(4, stackTrace->GetFrameCount()); CHECK_EQ(4, stackTrace->GetFrameCount());
checkStackFrame(origin, "bat", 2, 1, false, false, checkStackFrame(origin, "bat", 4, 22, false, false,
stackTrace->GetFrame(0)); stackTrace->GetFrame(0));
checkStackFrame(origin, "baz", 5, 3, false, true, checkStackFrame(origin, "baz", 8, 3, false, true,
stackTrace->GetFrame(1)); stackTrace->GetFrame(1));
checkStackFrame(NULL, "", 1, 1, true, false, checkStackFrame(NULL, "", 1, 1, true, false,
stackTrace->GetFrame(2)); stackTrace->GetFrame(2));
// The last frame is an anonymous function that has the initial call to foo. // The last frame is an anonymous function that has the initial call to foo.
checkStackFrame(origin, "", 7, 1, false, false, checkStackFrame(origin, "", 10, 1, false, false,
stackTrace->GetFrame(3)); stackTrace->GetFrame(3));
CHECK(stackTrace->AsArray()->IsArray()); CHECK(stackTrace->AsArray()->IsArray());
...@@ -9678,16 +9678,21 @@ THREADED_TEST(CaptureStackTrace) { ...@@ -9678,16 +9678,21 @@ THREADED_TEST(CaptureStackTrace) {
// Test getting DETAILED information. // Test getting DETAILED information.
const char *detailed_source = const char *detailed_source =
"function bat() {\n" "function bat() {AnalyzeStackInNativeCode(2);\n"
"AnalyzeStackInNativeCode(2);\n"
"}\n" "}\n"
"\n"
"function baz() {\n" "function baz() {\n"
" bat();\n" " bat();\n"
"}\n" "}\n"
"eval('new baz();');"; "eval('new baz();');";
v8::Handle<v8::String> detailed_src = v8::String::New(detailed_source); v8::Handle<v8::String> detailed_src = v8::String::New(detailed_source);
v8::Handle<Value> detailed_result = // Make the script using a non-zero line and column offset.
v8::Script::New(detailed_src, origin)->Run(); v8::Handle<v8::Integer> line_offset = v8::Integer::New(3);
v8::Handle<v8::Integer> column_offset = v8::Integer::New(5);
v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset);
v8::Handle<v8::Script> detailed_script(
v8::Script::New(detailed_src, &detailed_origin));
v8::Handle<Value> detailed_result = detailed_script->Run();
ASSERT(!detailed_result.IsEmpty()); ASSERT(!detailed_result.IsEmpty());
ASSERT(detailed_result->IsObject()); ASSERT(detailed_result->IsObject());
} }
......
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