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

Unified Diff: src/messages.js

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/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 cba474538eda764a926818345812af0077c74459..6687b5215163cd1b18761d7947cd6ff4ef3233a3 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -392,34 +392,26 @@ 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;
- }
-
- // 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;
+ 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;
} else {
- return i;
+ return mid;
}
}
-
- 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