Commit aca928b7 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

Reland [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
TBR=yangguo@chromium.org
LOG=Y

Review URL: https://codereview.chromium.org/1033973002

Cr-Commit-Position: refs/heads/master@{#27458}
parent f0d555b2
......@@ -353,7 +353,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();
}
......@@ -654,57 +653,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
......@@ -722,7 +670,6 @@ function SourceLocationSourceText() {
SetUpLockedPrototype(SourceLocation,
$Array("script", "position", "line", "column", "start", "end"),
$Array(
"restrict", SourceLocationRestrict,
"sourceText", SourceLocationSourceText
)
);
......@@ -779,7 +726,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;
}
......
......@@ -63,9 +63,9 @@ var comment_lines = 28;
// This is the last position in the entire file (note: this equals
// file size of <debug-sourceinfo.js> - 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 <LF>).
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)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment