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
This commit is contained in:
sgjesse@chromium.org 2010-05-10 06:24:01 +00:00
parent 8d51195778
commit 6d54362dbd
2 changed files with 20 additions and 16 deletions

View File

@ -394,21 +394,20 @@ Local<StackTrace> Top::CaptureCurrentStackTrace(
int script_line_offset = script->line_offset()->value();
int position = frame->code()->SourcePosition(frame->pc());
int line_number = GetScriptLineNumber(Handle<Script>(script), position);
if (options & StackTrace::kColumnOffset) {
// line_number is already shifted by the script_line_offset.
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()));
int start = (line_number == 0) ?
0 : Smi::cast(line_ends->get(line_number - 1))->value() + 1;
int start = (relative_line_number == 0) ? 0 :
Smi::cast(line_ends->get(relative_line_number - 1))->value() + 1;
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.
column_offset += script_line_offset;
column_offset += script->column_offset()->value();
}
SetProperty(stackFrame, column_key,
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,
Handle<Smi>(Smi::FromInt(line_number + 1)), NONE);
}
@ -420,7 +419,7 @@ Local<StackTrace> Top::CaptureCurrentStackTrace(
if (options & StackTrace::kFunctionName) {
Handle<Object> fun_name(fun->shared()->name());
if (!fun_name->IsString()) {
if (fun_name->ToBoolean()->IsFalse()) {
fun_name = Handle<Object>(fun->shared()->inferred_name());
}
SetProperty(stackFrame, function_key, fun_name, NONE);

View File

@ -9634,14 +9634,14 @@ v8::Handle<Value> AnalyzeStackInNativeCode(const v8::Arguments& args) {
v8::Handle<v8::StackTrace> stackTrace =
v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
CHECK_EQ(4, stackTrace->GetFrameCount());
checkStackFrame(origin, "bat", 2, 1, false, false,
checkStackFrame(origin, "bat", 4, 22, false, false,
stackTrace->GetFrame(0));
checkStackFrame(origin, "baz", 5, 3, false, true,
checkStackFrame(origin, "baz", 8, 3, false, true,
stackTrace->GetFrame(1));
checkStackFrame(NULL, "", 1, 1, true, false,
stackTrace->GetFrame(2));
// 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));
CHECK(stackTrace->AsArray()->IsArray());
@ -9678,16 +9678,21 @@ THREADED_TEST(CaptureStackTrace) {
// Test getting DETAILED information.
const char *detailed_source =
"function bat() {\n"
"AnalyzeStackInNativeCode(2);\n"
"function bat() {AnalyzeStackInNativeCode(2);\n"
"}\n"
"\n"
"function baz() {\n"
" bat();\n"
"}\n"
"eval('new baz();');";
v8::Handle<v8::String> detailed_src = v8::String::New(detailed_source);
v8::Handle<Value> detailed_result =
v8::Script::New(detailed_src, origin)->Run();
// Make the script using a non-zero line and column offset.
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->IsObject());
}