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

Unified Diff: src/objects.cc

Issue 1053563002: Revert of Correctly compute line numbers in functions from the function constructor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added regression test Created 5 years, 9 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/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 41960e65862f495dd11ab37b653a74cf039c676e..371adbe95d7afe13b7722d1c31aa4b6b1db4887e 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -10367,31 +10367,27 @@ int Script::GetColumnNumber(Handle<Script> script, int code_pos) {
}
-int Script::GetLineNumberWithArray(int position) {
+int Script::GetLineNumberWithArray(int code_pos) {
DisallowHeapAllocation no_allocation;
- FixedArray* line_ends = FixedArray::cast(this->line_ends());
- int upper = line_ends->length() - 1;
- if (upper < 0) return -1;
- int offset = line_offset()->value();
+ 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;
- if (position > Smi::cast(line_ends->get(upper))->value()) {
- return upper + 1 + offset;
+ if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) {
+ return line_offset()->value();
}
- if (position <= Smi::cast(line_ends->get(0))->value()) return offset;
- 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;
+ 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;
} else {
- return mid + offset;
+ left += half;
}
}
- return -1;
+ return right + line_offset()->value();
}
« 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