Revert of [V8] Removed SourceLocationRestrict (patchset #3 id:40001 of https://codereview.chromium.org/1022333004/)

Reason for revert:
[Sheriff] This seems to change layout test expectations of some tests, e.g.:
http://build.chromium.org/p/client.v8/builders/V8-Blink%20Linux%2064%20%28dbg%29/builds/2317

Expectation example:
https://storage.googleapis.com/chromium-layout-test-archives/V8-Blink_Linux_64__dbg_/2317/layout-test-results/fast/events/window-onerror-11-pretty-diff.html

Please add a needsmanualrebaseline expectation to the tests affected by this change on the blink side first before relanding.

Original issue's description:
> [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
>
> Committed: https://crrev.com/b563ceac0f95551a128a1403cdbacc7aefcdabaf
> Cr-Commit-Position: refs/heads/master@{#27374}

TBR=yangguo@chromium.org,kozyatinskiy@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=chromium:468781

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

Cr-Commit-Position: refs/heads/master@{#27398}
This commit is contained in:
machenbach 2015-03-24 05:04:39 -07:00 committed by Commit bot
parent c9db590d3b
commit 310d75218e
2 changed files with 142 additions and 3 deletions

View File

@ -352,6 +352,7 @@ function GetSourceLine(message) {
var start_position = %MessageGetStartPosition(message);
var location = script.locationFromPosition(start_position, true);
if (location == null) return "";
location.restrict();
return location.sourceText();
}
@ -652,6 +653,57 @@ 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
@ -669,6 +721,7 @@ function SourceLocationSourceText() {
SetUpLockedPrototype(SourceLocation,
$Array("script", "position", "line", "column", "start", "end"),
$Array(
"restrict", SourceLocationRestrict,
"sourceText", SourceLocationSourceText
)
);
@ -725,6 +778,7 @@ 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;
}

View File

@ -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 = 11337;
var last_position = 13890;
// This is the last line of entire file (note: starting at 0).
var last_line = 265;
var last_line = 350;
// This is the last column of last line (note: starting at 0 and +1, due
// to trailing <LF>).
var last_column = 1;
@ -257,9 +257,94 @@ 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 that script.sourceLine(line) works.
// 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);
// ^
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)));