From b563ceac0f95551a128a1403cdbacc7aefcdabaf Mon Sep 17 00:00:00 2001 From: kozyatinskiy Date: Mon, 23 Mar 2015 09:33:02 -0700 Subject: [PATCH] [V8] Removed SourceLocationRestrict This method uses in messages.js in GetSourceLine and GetPositionInLine. This methods uses in v8::Message API methods and there is no documentation about it. Method looks obsolete. One of the strange side effect is shown by attached issue. BUG=chromium:468781 R=yangguo@chromium.org LOG=Y Review URL: https://codereview.chromium.org/1022333004 Cr-Commit-Position: refs/heads/master@{#27374} --- src/messages.js | 54 ------------------------ test/mjsunit/debug-sourceinfo.js | 91 ++-------------------------------------- 2 files changed, 3 insertions(+), 142 deletions(-) diff --git a/src/messages.js b/src/messages.js index 12170c4..752f2ea 100644 --- a/src/messages.js +++ b/src/messages.js @@ -352,7 +352,6 @@ function GetSourceLine(message) { var start_position = %MessageGetStartPosition(message); var location = script.locationFromPosition(start_position, true); if (location == null) return ""; - location.restrict(); return location.sourceText(); } @@ -653,57 +652,6 @@ function SourceLocation(script, position, line, column, start, end) { this.end = end; } -var kLineLengthLimit = 78; - -/** - * Restrict source location start and end positions to make the source slice - * no more that a certain number of characters wide. - * @param {number} opt_limit The with limit of the source text with a default - * of 78 - * @param {number} opt_before The number of characters to prefer before the - * position with a default value of 10 less that the limit - */ -function SourceLocationRestrict(opt_limit, opt_before) { - // Find the actual limit to use. - var limit; - var before; - if (!IS_UNDEFINED(opt_limit)) { - limit = opt_limit; - } else { - limit = kLineLengthLimit; - } - if (!IS_UNDEFINED(opt_before)) { - before = opt_before; - } else { - // If no before is specified center for small limits and perfer more source - // before the the position that after for longer limits. - if (limit <= 20) { - before = $floor(limit / 2); - } else { - before = limit - 10; - } - } - if (before >= limit) { - before = limit - 1; - } - - // If the [start, end[ interval is too big we restrict - // it in one or both ends. We make sure to always produce - // restricted intervals of maximum allowed size. - if (this.end - this.start > limit) { - var start_limit = this.position - before; - var end_limit = this.position + limit - before; - if (this.start < start_limit && end_limit < this.end) { - this.start = start_limit; - this.end = end_limit; - } else if (this.start < start_limit) { - this.start = this.end - limit; - } else { - this.end = this.start + limit; - } - } -} - /** * Get the source text for a SourceLocation @@ -721,7 +669,6 @@ function SourceLocationSourceText() { SetUpLockedPrototype(SourceLocation, $Array("script", "position", "line", "column", "start", "end"), $Array( - "restrict", SourceLocationRestrict, "sourceText", SourceLocationSourceText ) ); @@ -778,7 +725,6 @@ function GetPositionInLine(message) { var start_position = %MessageGetStartPosition(message); var location = script.locationFromPosition(start_position, false); if (location == null) return -1; - location.restrict(); return start_position - location.start; } diff --git a/test/mjsunit/debug-sourceinfo.js b/test/mjsunit/debug-sourceinfo.js index 2181b7d..1dbe1b7 100644 --- a/test/mjsunit/debug-sourceinfo.js +++ b/test/mjsunit/debug-sourceinfo.js @@ -63,9 +63,9 @@ var comment_lines = 28; // This is the last position in the entire file (note: this equals // file size of - 1, since starting at 0). -var last_position = 13890; +var last_position = 11337; // This is the last line of entire file (note: starting at 0). -var last_line = 350; +var last_line = 265; // This is the last column of last line (note: starting at 0 and +1, due // to trailing ). var last_column = 1; @@ -257,94 +257,9 @@ assertEquals(last_position, script.locationFromPosition(last_position).position) assertEquals(last_line, script.locationFromPosition(last_position).line); assertEquals(last_column, script.locationFromPosition(last_position).column); -// Test source line and restriction. All the following tests start from line 1 -// column 2 in function b, which is the call to c. -// c(true); -// ^ - +// Test that script.sourceLine(line) works. var location; -location = script.locationFromLine(1, 0, start_b); -assertEquals(' c(true);', location.sourceText()); - -result = ['c', ' c', ' c(', ' c(', ' c(t'] -for (var i = 1; i <= 5; i++) { - location = script.locationFromLine(1, 2, start_b); - location.restrict(i); - assertEquals(result[i - 1], location.sourceText()); -} - -location = script.locationFromLine(1, 2, start_b); -location.restrict(1, 0); -assertEquals('c', location.sourceText()); - -location = script.locationFromLine(1, 2, start_b); -location.restrict(2, 0); -assertEquals('c(', location.sourceText()); - -location = script.locationFromLine(1, 2, start_b); -location.restrict(2, 1); -assertEquals(' c', location.sourceText()); - -location = script.locationFromLine(1, 2, start_b); -location.restrict(2, 2); -assertEquals(' c', location.sourceText()); - -location = script.locationFromLine(1, 2, start_b); -location.restrict(2, 3); -assertEquals(' c', location.sourceText()); - -location = script.locationFromLine(1, 2, start_b); -location.restrict(3, 1); -assertEquals(' c(', location.sourceText()); - -location = script.locationFromLine(1, 2, start_b); -location.restrict(5, 0); -assertEquals('c(tru', location.sourceText()); - -location = script.locationFromLine(1, 2, start_b); -location.restrict(5, 2); -assertEquals(' c(t', location.sourceText()); - -location = script.locationFromLine(1, 2, start_b); -location.restrict(5, 4); -assertEquals(' c(t', location.sourceText()); - -// All the following tests start from line 1 column 10 in function b, which is -// the final character. -// c(true); -// ^ - -location = script.locationFromLine(1, 10, start_b); -location.restrict(5, 0); -assertEquals('rue);', location.sourceText()); - -location = script.locationFromLine(1, 10, start_b); -location.restrict(7, 0); -assertEquals('(true);', location.sourceText()); - -// All the following tests start from line 1 column 0 in function b, which is -// the first character. -// c(true); -//^ - -location = script.locationFromLine(1, 0, start_b); -location.restrict(5, 0); -assertEquals(' c(t', location.sourceText()); - -location = script.locationFromLine(1, 0, start_b); -location.restrict(5, 4); -assertEquals(' c(t', location.sourceText()); - -location = script.locationFromLine(1, 0, start_b); -location.restrict(7, 0); -assertEquals(' c(tru', location.sourceText()); - -location = script.locationFromLine(1, 0, start_b); -location.restrict(7, 6); -assertEquals(' c(tru', location.sourceText()); - -// Test that script.sourceLine(line) works. for (line = 0; line < num_lines_d; line++) { var line_content_regexp = new RegExp(" x = " + (line + 1)); assertTrue(line_content_regexp.test(script.sourceLine(start_line_d + line))); -- 2.7.4