Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1252)

Unified Diff: src/objects.cc

Issue 19537: Adding src_file_name:line_number into perf log entries for compiled JS functi... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
===================================================================
--- src/objects.cc (revision 1206)
+++ src/objects.cc (working copy)
@@ -6775,6 +6775,61 @@
}
+// Init line_ends array with code positions of line ends inside script source
+void Script::InitLineEnds() {
+ if (!line_ends()->IsUndefined()) return;
+
+ Handle<String> src(String::cast(source()));
+ const int src_len = src->length();
+ Handle<JSArray> array = Factory::NewJSArray(0);
+ int array_index = 0;
+ Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n"));
+ int position = 0;
+ while (position < src_len) {
+ position = Runtime::StringMatch(src, new_line, position);
+ if (position != -1) {
+ SetElement(array, array_index++, Handle<Smi>(Smi::FromInt(position++)));
+ } else {
+ break;
+ }
+ }
+
+ // If the script does not end with a line ending add the final end position
+ // as just past the last line ending.
+ if (array_index == 0 ||
+ (Smi::cast(array->GetElement(array_index - 1))->value() != src_len - 1)) {
+ SetElement(array, array_index++, Handle<Smi>(Smi::FromInt(src_len)));
+ }
+
+ Handle<FixedArray> fixed_array = Factory::NewFixedArray(0);
+ set_line_ends(fixed_array->AddKeysFromJSArray(*array));
+ ASSERT(line_ends()->IsFixedArray());
+}
+
+
+// Convert code position into line number
+int Script::GetLineNumber(int code_pos) {
+ InitLineEnds();
+ FixedArray* line_ends_array = FixedArray::cast(line_ends());
+
+ int line = -1;
+ if (code_pos <= (Smi::cast(line_ends_array->get(0)))->value()) {
+ line = 0;
+ } else {
+ const int line_ends_length = line_ends_array->length();
+ for (int i = 1; i < line_ends_length; ++i) {
+ if ((Smi::cast(line_ends_array->get(i - 1)))->value() < code_pos &&
+ code_pos <= (Smi::cast(line_ends_array->get(i)))->value()) {
+ line = i;
+ break;
+ }
+ }
+ }
+
+ return line != -1 ? line + line_offset()->value() : line;
+}
+
+
// Check if there is a break point at this code position.
bool DebugInfo::HasBreakPoint(int code_position) {
// Get the break point info object for this code position.
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698