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

Unified Diff: src/objects.cc

Issue 701093003: Correctly compute line numbers in functions from the function constructor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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/messages.js ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 01b4a1aca09f61e9504b67a41f7f6abb66971e39..13952e838b0d6637c047000ae02872ee8da5d214 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -9932,27 +9932,31 @@ int Script::GetColumnNumber(Handle<Script> script, int code_pos) {
}
-int Script::GetLineNumberWithArray(int code_pos) {
+int Script::GetLineNumberWithArray(int position) {
DisallowHeapAllocation no_allocation;
- DCHECK(line_ends()->IsFixedArray());
- FixedArray* line_ends_array = FixedArray::cast(line_ends());
- int line_ends_len = line_ends_array->length();
- if (line_ends_len == 0) return -1;
+ FixedArray* line_ends = FixedArray::cast(this->line_ends());
+ int upper = line_ends->length() - 1;
+ if (upper < 0) return -1;
+ int offset = line_offset()->value();
- if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) {
- return line_offset()->value();
+ if (position > Smi::cast(line_ends->get(upper))->value()) {
+ return upper + 1 + offset;
}
+ if (position <= Smi::cast(line_ends->get(0))->value()) return offset;
- int left = 0;
- int right = line_ends_len;
- while (int half = (right - left) / 2) {
- if ((Smi::cast(line_ends_array->get(left + half)))->value() > code_pos) {
- right -= half;
+ int lower = 1;
+ // Binary search.
+ while (true) {
+ int mid = (lower + upper) / 2;
+ if (position <= Smi::cast(line_ends->get(mid - 1))->value()) {
+ upper = mid - 1;
+ } else if (position > Smi::cast(line_ends->get(mid))->value()) {
+ lower = mid + 1;
} else {
- left += half;
+ return mid + offset;
}
}
- return right + line_offset()->value();
+ return -1;
}
« no previous file with comments | « src/messages.js ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698