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

Unified Diff: src/messages.js

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/generator.js ('k') | src/objects.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index 69be1c9ab53e737bcdb93a9b6f9dbdf2c2cf0e2e..fe4098fb089871d06f01de5141cf2829937a0f40 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -410,26 +410,34 @@ function MakeReferenceErrorEmbedded(type, arg) {
else the line number.
*/
function ScriptLineFromPosition(position) {
+ var lower = 0;
+ var upper = this.lineCount() - 1;
var line_ends = this.line_ends;
- var upper = line_ends.length - 1;
- if (upper < 0) return -1;
// We'll never find invalid positions so bail right away.
- if (position > line_ends[upper]) return -1;
- if (position <= line_ends[0]) return 0;
-
- var lower = 1;
- // Binary search.
- while (true) {
- var mid = (upper + lower) >> 1;
- if (position <= line_ends[mid - 1]) {
- upper = mid - 1;
- } else if (position > line_ends[mid]){
- lower = mid + 1;
+ if (position > line_ends[upper]) {
+ return -1;
+ }
+
+ // This means we don't have to safe-guard indexing line_ends[i - 1].
+ if (position <= line_ends[0]) {
+ return 0;
+ }
+
+ // Binary search to find line # from position range.
+ while (upper >= 1) {
+ var i = (lower + upper) >> 1;
+
+ if (position > line_ends[i]) {
+ lower = i + 1;
+ } else if (position <= line_ends[i - 1]) {
+ upper = i - 1;
} else {
- return mid;
+ return i;
}
}
+
+ return -1;
}
/**
« no previous file with comments | « src/generator.js ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698