| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 const kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true}; | 31 const kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true}; |
| 32 const kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, | 32 const kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, |
| 33 h: true, f: true, l: true, m: true, n: true, r: true, s: true, x: true, | 33 h: true, f: true, l: true, m: true, n: true, r: true, s: true, x: true, |
| 34 y: true}; | 34 y: true}; |
| 35 | 35 |
| 36 function GetInstanceName(cons) { | 36 function GetInstanceName(cons) { |
| 37 if (cons.length == 0) { | 37 if (cons.length == 0) { |
| 38 return ""; | 38 return ""; |
| 39 } | 39 } |
| 40 var first = cons.charAt(0).toLowerCase(); | 40 var first = %StringToLowerCase(StringCharAt.call(cons, 0)); |
| 41 var mapping = kVowelSounds; | 41 var mapping = kVowelSounds; |
| 42 if (cons.length > 1 && (cons.charAt(0) != first)) { | 42 if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) { |
| 43 // First char is upper case | 43 // First char is upper case |
| 44 var second = cons.charAt(1).toLowerCase(); | 44 var second = %StringToLowerCase(StringCharAt.call(cons, 1)); |
| 45 // Second char is upper case | 45 // Second char is upper case |
| 46 if (cons.charAt(1) != second) | 46 if (StringCharAt.call(cons, 1) != second) |
| 47 mapping = kCapitalVowelSounds; | 47 mapping = kCapitalVowelSounds; |
| 48 } | 48 } |
| 49 var s = mapping[first] ? "an " : "a "; | 49 var s = mapping[first] ? "an " : "a "; |
| 50 return s + cons; | 50 return s + cons; |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 const kMessages = { | 54 const kMessages = { |
| 55 // Error | 55 // Error |
| 56 cyclic_proto: "Cyclic __proto__ value", | 56 cyclic_proto: "Cyclic __proto__ value", |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 circular_structure: "Converting circular structure to JSON" | 119 circular_structure: "Converting circular structure to JSON" |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 | 122 |
| 123 function FormatString(format, args) { | 123 function FormatString(format, args) { |
| 124 var result = format; | 124 var result = format; |
| 125 for (var i = 0; i < args.length; i++) { | 125 for (var i = 0; i < args.length; i++) { |
| 126 var str; | 126 var str; |
| 127 try { str = ToDetailString(args[i]); } | 127 try { str = ToDetailString(args[i]); } |
| 128 catch (e) { str = "#<error>"; } | 128 catch (e) { str = "#<error>"; } |
| 129 result = result.split("%" + i).join(str); | 129 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); |
| 130 } | 130 } |
| 131 return result; | 131 return result; |
| 132 } | 132 } |
| 133 | 133 |
| 134 | 134 |
| 135 function ToDetailString(obj) { | 135 function ToDetailString(obj) { |
| 136 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri
ng) { | 136 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri
ng) { |
| 137 var constructor = obj.constructor; | 137 var constructor = obj.constructor; |
| 138 if (!constructor) return ToString(obj); | 138 if (!constructor) return ToString(obj); |
| 139 var constructorName = constructor.name; | 139 var constructorName = constructor.name; |
| 140 if (!constructorName) return ToString(obj); | 140 if (!constructorName) return ToString(obj); |
| 141 return "#<" + GetInstanceName(constructorName) + ">"; | 141 return "#<" + GetInstanceName(constructorName) + ">"; |
| 142 } else { | 142 } else { |
| 143 return ToString(obj); | 143 return ToString(obj); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 | 147 |
| 148 function MakeGenericError(constructor, type, args) { | 148 function MakeGenericError(constructor, type, args) { |
| 149 if (args instanceof $Array) { | 149 if (IS_UNDEFINED(args)) { |
| 150 for (var i = 0; i < args.length; i++) { | |
| 151 var elem = args[i]; | |
| 152 if (elem instanceof $Array && elem.length > 100) { // arbitrary limit, gra
b a reasonable slice to report | |
| 153 args[i] = elem.slice(0,20).concat("..."); | |
| 154 } | |
| 155 } | |
| 156 } else if (IS_UNDEFINED(args)) { | |
| 157 args = []; | 150 args = []; |
| 158 } | 151 } |
| 159 | |
| 160 var e = new constructor(kAddMessageAccessorsMarker); | 152 var e = new constructor(kAddMessageAccessorsMarker); |
| 161 e.type = type; | 153 e.type = type; |
| 162 e.arguments = args; | 154 e.arguments = args; |
| 163 return e; | 155 return e; |
| 164 } | 156 } |
| 165 | 157 |
| 166 | 158 |
| 167 /** | 159 /** |
| 168 * Setup the Script function and constructor. | 160 * Setup the Script function and constructor. |
| 169 */ | 161 */ |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 * If line is negative or not in the source null is returned. | 266 * If line is negative or not in the source null is returned. |
| 275 */ | 267 */ |
| 276 Script.prototype.locationFromPosition = function (position, | 268 Script.prototype.locationFromPosition = function (position, |
| 277 include_resource_offset) { | 269 include_resource_offset) { |
| 278 var line = this.lineFromPosition(position); | 270 var line = this.lineFromPosition(position); |
| 279 if (line == -1) return null; | 271 if (line == -1) return null; |
| 280 | 272 |
| 281 // Determine start, end and column. | 273 // Determine start, end and column. |
| 282 var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; | 274 var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; |
| 283 var end = this.line_ends[line]; | 275 var end = this.line_ends[line]; |
| 284 if (end > 0 && this.source.charAt(end - 1) == '\r') end--; | 276 if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--; |
| 285 var column = position - start; | 277 var column = position - start; |
| 286 | 278 |
| 287 // Adjust according to the offset within the resource. | 279 // Adjust according to the offset within the resource. |
| 288 if (include_resource_offset) { | 280 if (include_resource_offset) { |
| 289 line += this.line_offset; | 281 line += this.line_offset; |
| 290 if (line == this.line_offset) { | 282 if (line == this.line_offset) { |
| 291 column += this.column_offset; | 283 column += this.column_offset; |
| 292 } | 284 } |
| 293 } | 285 } |
| 294 | 286 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } | 379 } |
| 388 | 380 |
| 389 // Check parameter. | 381 // Check parameter. |
| 390 if (line < 0 || this.lineCount() <= line) { | 382 if (line < 0 || this.lineCount() <= line) { |
| 391 return null; | 383 return null; |
| 392 } | 384 } |
| 393 | 385 |
| 394 // Return the source line. | 386 // Return the source line. |
| 395 var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; | 387 var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; |
| 396 var end = this.line_ends[line]; | 388 var end = this.line_ends[line]; |
| 397 return this.source.substring(start, end); | 389 return StringSubstring.call(this.source, start, end); |
| 398 } | 390 } |
| 399 | 391 |
| 400 | 392 |
| 401 /** | 393 /** |
| 402 * Returns the number of source lines. | 394 * Returns the number of source lines. |
| 403 * @return {number} | 395 * @return {number} |
| 404 * Number of source lines. | 396 * Number of source lines. |
| 405 */ | 397 */ |
| 406 Script.prototype.lineCount = function() { | 398 Script.prototype.lineCount = function() { |
| 407 // Return number of source lines. | 399 // Return number of source lines. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 483 } |
| 492 }; | 484 }; |
| 493 | 485 |
| 494 | 486 |
| 495 /** | 487 /** |
| 496 * Get the source text for a SourceLocation | 488 * Get the source text for a SourceLocation |
| 497 * @return {String} | 489 * @return {String} |
| 498 * Source text for this location. | 490 * Source text for this location. |
| 499 */ | 491 */ |
| 500 SourceLocation.prototype.sourceText = function () { | 492 SourceLocation.prototype.sourceText = function () { |
| 501 return this.script.source.substring(this.start, this.end); | 493 return StringSubstring.call(this.script.source, this.start, this.end); |
| 502 }; | 494 }; |
| 503 | 495 |
| 504 | 496 |
| 505 /** | 497 /** |
| 506 * Class for a source slice. A source slice is a part of a script source with | 498 * Class for a source slice. A source slice is a part of a script source with |
| 507 * the following properties: | 499 * the following properties: |
| 508 * script : script object for the source | 500 * script : script object for the source |
| 509 * from_line : line number for the first line in the slice | 501 * from_line : line number for the first line in the slice |
| 510 * to_line : source line number for the last line in the slice | 502 * to_line : source line number for the last line in the slice |
| 511 * from_position : position of the first character in the slice | 503 * from_position : position of the first character in the slice |
| (...skipping 16 matching lines...) Expand all Loading... |
| 528 this.to_position = to_position; | 520 this.to_position = to_position; |
| 529 } | 521 } |
| 530 | 522 |
| 531 | 523 |
| 532 /** | 524 /** |
| 533 * Get the source text for a SourceSlice | 525 * Get the source text for a SourceSlice |
| 534 * @return {String} Source text for this slice. The last line will include | 526 * @return {String} Source text for this slice. The last line will include |
| 535 * the line terminating characters (if any) | 527 * the line terminating characters (if any) |
| 536 */ | 528 */ |
| 537 SourceSlice.prototype.sourceText = function () { | 529 SourceSlice.prototype.sourceText = function () { |
| 538 return this.script.source.substring(this.from_position, this.to_position); | 530 return StringSubstring.call(this.script.source, this.from_position, this.to_po
sition); |
| 539 }; | 531 }; |
| 540 | 532 |
| 541 | 533 |
| 542 // Returns the offset of the given position within the containing | 534 // Returns the offset of the given position within the containing |
| 543 // line. | 535 // line. |
| 544 function GetPositionInLine(message) { | 536 function GetPositionInLine(message) { |
| 545 var location = message.script.locationFromPosition(message.startPos, false); | 537 var location = message.script.locationFromPosition(message.startPos, false); |
| 546 if (location == null) return -1; | 538 if (location == null) return -1; |
| 547 location.restrict(); | 539 location.restrict(); |
| 548 return message.startPos - location.start; | 540 return message.startPos - location.start; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); | 692 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); |
| 701 } | 693 } |
| 702 var message = this.message; | 694 var message = this.message; |
| 703 return this.name + (message ? (": " + message) : ""); | 695 return this.name + (message ? (": " + message) : ""); |
| 704 }, DONT_ENUM); | 696 }, DONT_ENUM); |
| 705 | 697 |
| 706 | 698 |
| 707 // Boilerplate for exceptions for stack overflows. Used from | 699 // Boilerplate for exceptions for stack overflows. Used from |
| 708 // Top::StackOverflow(). | 700 // Top::StackOverflow(). |
| 709 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 701 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |