| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // Helper functions; called from the runtime system. | 174 // Helper functions; called from the runtime system. |
| 175 function FormatMessage(message) { | 175 function FormatMessage(message) { |
| 176 var format = kMessages[message.type]; | 176 var format = kMessages[message.type]; |
| 177 if (!format) return "<unknown message " + message.type + ">"; | 177 if (!format) return "<unknown message " + message.type + ">"; |
| 178 return FormatString(format, message.args); | 178 return FormatString(format, message.args); |
| 179 } | 179 } |
| 180 | 180 |
| 181 | 181 |
| 182 function GetLineNumber(message) { | 182 function GetLineNumber(message) { |
| 183 if (message.startPos == -1) return -1; | 183 if (message.startPos == -1) return -1; |
| 184 var location = message.script.locationFromPosition(message.startPos); | 184 var location = message.script.locationFromPosition(message.startPos, true); |
| 185 if (location == null) return -1; | 185 if (location == null) return -1; |
| 186 return location.line + 1; | 186 return location.line + 1; |
| 187 } | 187 } |
| 188 | 188 |
| 189 | 189 |
| 190 // Returns the source code line containing the given source | 190 // Returns the source code line containing the given source |
| 191 // position, or the empty string if the position is invalid. | 191 // position, or the empty string if the position is invalid. |
| 192 function GetSourceLine(message) { | 192 function GetSourceLine(message) { |
| 193 var location = message.script.locationFromPosition(message.startPos); | 193 var location = message.script.locationFromPosition(message.startPos, true); |
| 194 if (location == null) return ""; | 194 if (location == null) return ""; |
| 195 location.restrict(); | 195 location.restrict(); |
| 196 return location.sourceText(); | 196 return location.sourceText(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 | 199 |
| 200 function MakeTypeError(type, args) { | 200 function MakeTypeError(type, args) { |
| 201 return MakeGenericError($TypeError, type, args); | 201 return MakeGenericError($TypeError, type, args); |
| 202 } | 202 } |
| 203 | 203 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 223 | 223 |
| 224 | 224 |
| 225 function MakeError(type, args) { | 225 function MakeError(type, args) { |
| 226 return MakeGenericError($Error, type, args); | 226 return MakeGenericError($Error, type, args); |
| 227 } | 227 } |
| 228 | 228 |
| 229 | 229 |
| 230 /** | 230 /** |
| 231 * Get information on a specific source position. | 231 * Get information on a specific source position. |
| 232 * @param {number} position The source position | 232 * @param {number} position The source position |
| 233 * @param {boolean} include_resource_offset Set to true to have the resource |
| 234 * offset added to the location |
| 233 * @return {SourceLocation} | 235 * @return {SourceLocation} |
| 234 * If line is negative or not in the source null is returned. | 236 * If line is negative or not in the source null is returned. |
| 235 */ | 237 */ |
| 236 Script.prototype.locationFromPosition = function (position) { | 238 Script.prototype.locationFromPosition = function (position, |
| 239 include_resource_offset) { |
| 237 var lineCount = this.lineCount(); | 240 var lineCount = this.lineCount(); |
| 238 var line = -1; | 241 var line = -1; |
| 239 if (position <= this.line_ends[0]) { | 242 if (position <= this.line_ends[0]) { |
| 240 line = 0; | 243 line = 0; |
| 241 } else { | 244 } else { |
| 242 for (var i = 1; i < lineCount; i++) { | 245 for (var i = 1; i < lineCount; i++) { |
| 243 if (this.line_ends[i - 1] < position && position <= this.line_ends[i]) { | 246 if (this.line_ends[i - 1] < position && position <= this.line_ends[i]) { |
| 244 line = i; | 247 line = i; |
| 245 break; | 248 break; |
| 246 } | 249 } |
| 247 } | 250 } |
| 248 } | 251 } |
| 249 | 252 |
| 250 if (line == -1) return null; | 253 if (line == -1) return null; |
| 251 | 254 |
| 252 // Determine start, end and column. | 255 // Determine start, end and column. |
| 253 var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; | 256 var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; |
| 254 var end = this.line_ends[line]; | 257 var end = this.line_ends[line]; |
| 255 if (end > 0 && this.source.charAt(end - 1) == '\r') end--; | 258 if (end > 0 && this.source.charAt(end - 1) == '\r') end--; |
| 256 var column = position - start; | 259 var column = position - start; |
| 257 | 260 |
| 258 // Adjust according to the offset within the resource. | 261 // Adjust according to the offset within the resource. |
| 259 line += this.line_offset; | 262 if (include_resource_offset) { |
| 260 if (line == this.line_offset) { | 263 line += this.line_offset; |
| 261 column += this.column_offset; | 264 if (line == this.line_offset) { |
| 265 column += this.column_offset; |
| 266 } |
| 262 } | 267 } |
| 263 | 268 |
| 264 return new SourceLocation(this, position, line, column, start, end); | 269 return new SourceLocation(this, position, line, column, start, end); |
| 265 }; | 270 }; |
| 266 | 271 |
| 267 | 272 |
| 268 /** | 273 /** |
| 269 * Get information on a specific source line and column possibly offset by a | 274 * Get information on a specific source line and column possibly offset by a |
| 270 * fixed source position. This function is used to find a source position from | 275 * fixed source position. This function is used to find a source position from |
| 271 * a line and column position. The fixed source position offset is typically | 276 * a line and column position. The fixed source position offset is typically |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 result += ToDetailString(recv) + "."; | 571 result += ToDetailString(recv) + "."; |
| 567 result += GetFunctionName(fun, recv); | 572 result += GetFunctionName(fun, recv); |
| 568 } | 573 } |
| 569 if (pos != -1) { | 574 if (pos != -1) { |
| 570 var script = %FunctionGetScript(fun); | 575 var script = %FunctionGetScript(fun); |
| 571 var file; | 576 var file; |
| 572 if (script) { | 577 if (script) { |
| 573 file = %FunctionGetScript(fun).data; | 578 file = %FunctionGetScript(fun).data; |
| 574 } | 579 } |
| 575 if (file) { | 580 if (file) { |
| 576 var location = %FunctionGetScript(fun).locationFromPosition(pos); | 581 var location = %FunctionGetScript(fun).locationFromPosition(pos, true); |
| 577 if (!isTopLevel) result += "("; | 582 if (!isTopLevel) result += "("; |
| 578 result += file; | 583 result += file; |
| 579 if (location != null) { | 584 if (location != null) { |
| 580 result += ":" + (location.line + 1) + ":" + (location.column + 1); | 585 result += ":" + (location.line + 1) + ":" + (location.column + 1); |
| 581 } | 586 } |
| 582 if (!isTopLevel) result += ")"; | 587 if (!isTopLevel) result += ")"; |
| 583 } | 588 } |
| 584 } | 589 } |
| 585 return (result) ? " at " + result : result; | 590 return (result) ? " at " + result : result; |
| 586 } | 591 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); | 667 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); |
| 663 } | 668 } |
| 664 var message = this.message; | 669 var message = this.message; |
| 665 return this.name + (message ? (": " + message) : ""); | 670 return this.name + (message ? (": " + message) : ""); |
| 666 }, DONT_ENUM); | 671 }, DONT_ENUM); |
| 667 | 672 |
| 668 | 673 |
| 669 // Boilerplate for exceptions for stack overflows. Used from | 674 // Boilerplate for exceptions for stack overflows. Used from |
| 670 // Top::StackOverflow(). | 675 // Top::StackOverflow(). |
| 671 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 676 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |