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

Unified Diff: src/messages.js

Issue 39342: Refactor some source position info (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 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/debug-delay.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/messages.js
===================================================================
--- src/messages.js (revision 1456)
+++ src/messages.js (working copy)
@@ -181,7 +181,7 @@
function GetLineNumber(message) {
if (message.startPos == -1) return -1;
- var location = message.script.locationFromPosition(message.startPos);
+ var location = message.script.locationFromPosition(message.startPos, true);
if (location == null) return -1;
return location.line + 1;
}
@@ -190,7 +190,7 @@
// Returns the source code line containing the given source
// position, or the empty string if the position is invalid.
function GetSourceLine(message) {
- var location = message.script.locationFromPosition(message.startPos);
+ var location = message.script.locationFromPosition(message.startPos, true);
if (location == null) return "";
location.restrict();
return location.sourceText();
@@ -230,10 +230,13 @@
/**
* Get information on a specific source position.
* @param {number} position The source position
+ * @param {boolean} include_resource_offset Set to true to have the resource
+ * offset added to the location
* @return {SourceLocation}
* If line is negative or not in the source null is returned.
*/
-Script.prototype.locationFromPosition = function (position) {
+Script.prototype.locationFromPosition = function (position,
+ include_resource_offset) {
var lineCount = this.lineCount();
var line = -1;
if (position <= this.line_ends[0]) {
@@ -256,9 +259,11 @@
var column = position - start;
// Adjust according to the offset within the resource.
- line += this.line_offset;
- if (line == this.line_offset) {
- column += this.column_offset;
+ if (include_resource_offset) {
+ line += this.line_offset;
+ if (line == this.line_offset) {
+ column += this.column_offset;
+ }
}
return new SourceLocation(this, position, line, column, start, end);
@@ -573,7 +578,7 @@
file = %FunctionGetScript(fun).data;
}
if (file) {
- var location = %FunctionGetScript(fun).locationFromPosition(pos);
+ var location = %FunctionGetScript(fun).locationFromPosition(pos, true);
if (!isTopLevel) result += "(";
result += file;
if (location != null) {
« no previous file with comments | « src/debug-delay.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698