Reviewers: Yury Semikhatsky, pfeldman, Søren Gjesse, Michail Naganov,
Message:
I was implementing WebKit changes to use this API and found a difference
between
GetScriptLineNumber() from handles.cc and my original helper function.
This should fix this and it ammends the test case to cover it.
Description:
Fixes bug with v8::StackTrace for non-zero script line offsets.
GetScriptLineNumber() in handles.cc already adjusted by the script line
offset.
The implementation of CaptureCurrentStackTrace in top.cc did not account for
this.
Please review this at http://codereview.chromium.org/1985004/show
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M src/top.cc
M test/cctest/test-api.cc
Index: test/cctest/test-api.cc
===================================================================
--- test/cctest/test-api.cc (revision 4607)
+++ test/cctest/test-api.cc (working copy)
@@ -9634,14 +9634,14 @@
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", 5, 1, 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());
@@ -9686,8 +9686,12 @@
"}\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 offset.
+ v8::Handle<v8::Integer> line_offset = v8::Integer::New(3);
+ v8::ScriptOrigin detailed_origin(origin, line_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());
}
Index: src/top.cc
===================================================================
--- src/top.cc (revision 4607)
+++ src/top.cc (working copy)
@@ -394,21 +394,20 @@
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 == script_line_offset) {
// For the case where the code is on the same line as the script
tag.
column_offset += script_line_offset;
}
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);
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev