OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // ------------------------------------------------------------------- | 5 // ------------------------------------------------------------------- |
6 | 6 |
7 var $errorToString; | 7 var $errorToString; |
8 var $getStackTraceLine; | |
9 var $internalErrorSymbol; | 8 var $internalErrorSymbol; |
10 var $messageGetPositionInLine; | |
11 var $messageGetLineNumber; | |
12 var $messageGetSourceLine; | |
13 var $stackOverflowBoilerplate; | |
14 var $stackTraceSymbol; | 9 var $stackTraceSymbol; |
15 var MakeError; | 10 var MakeError; |
16 var MakeEvalError; | 11 var MakeEvalError; |
17 var MakeRangeError; | 12 var MakeRangeError; |
18 var MakeReferenceError; | 13 var MakeReferenceError; |
19 var MakeSyntaxError; | 14 var MakeSyntaxError; |
20 var MakeTypeError; | 15 var MakeTypeError; |
21 var MakeURIError; | 16 var MakeURIError; |
22 | 17 |
23 (function(global, utils) { | 18 (function(global, utils) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 function GetLineNumber(message) { | 201 function GetLineNumber(message) { |
207 var start_position = %MessageGetStartPosition(message); | 202 var start_position = %MessageGetStartPosition(message); |
208 if (start_position == -1) return kNoLineNumberInfo; | 203 if (start_position == -1) return kNoLineNumberInfo; |
209 var script = %MessageGetScript(message); | 204 var script = %MessageGetScript(message); |
210 var location = script.locationFromPosition(start_position, true); | 205 var location = script.locationFromPosition(start_position, true); |
211 if (location == null) return kNoLineNumberInfo; | 206 if (location == null) return kNoLineNumberInfo; |
212 return location.line + 1; | 207 return location.line + 1; |
213 } | 208 } |
214 | 209 |
215 | 210 |
| 211 //Returns the offset of the given position within the containing line. |
| 212 function GetColumnNumber(message) { |
| 213 var script = %MessageGetScript(message); |
| 214 var start_position = %MessageGetStartPosition(message); |
| 215 var location = script.locationFromPosition(start_position, true); |
| 216 if (location == null) return -1; |
| 217 return location.column; |
| 218 } |
| 219 |
| 220 |
216 // Returns the source code line containing the given source | 221 // Returns the source code line containing the given source |
217 // position, or the empty string if the position is invalid. | 222 // position, or the empty string if the position is invalid. |
218 function GetSourceLine(message) { | 223 function GetSourceLine(message) { |
219 var script = %MessageGetScript(message); | 224 var script = %MessageGetScript(message); |
220 var start_position = %MessageGetStartPosition(message); | 225 var start_position = %MessageGetStartPosition(message); |
221 var location = script.locationFromPosition(start_position, true); | 226 var location = script.locationFromPosition(start_position, true); |
222 if (location == null) return ""; | 227 if (location == null) return ""; |
223 return location.sourceText(); | 228 return location.sourceText(); |
224 } | 229 } |
225 | 230 |
| 231 |
226 /** | 232 /** |
227 * Find a line number given a specific source position. | 233 * Find a line number given a specific source position. |
228 * @param {number} position The source position. | 234 * @param {number} position The source position. |
229 * @return {number} 0 if input too small, -1 if input too large, | 235 * @return {number} 0 if input too small, -1 if input too large, |
230 else the line number. | 236 else the line number. |
231 */ | 237 */ |
232 function ScriptLineFromPosition(position) { | 238 function ScriptLineFromPosition(position) { |
233 var lower = 0; | 239 var lower = 0; |
234 var upper = this.lineCount() - 1; | 240 var upper = this.lineCount() - 1; |
235 var line_ends = this.line_ends; | 241 var line_ends = this.line_ends; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 this.to_position, | 555 this.to_position, |
550 StringSubstring); | 556 StringSubstring); |
551 } | 557 } |
552 | 558 |
553 utils.SetUpLockedPrototype(SourceSlice, | 559 utils.SetUpLockedPrototype(SourceSlice, |
554 ["script", "from_line", "to_line", "from_position", "to_position"], | 560 ["script", "from_line", "to_line", "from_position", "to_position"], |
555 ["sourceText", SourceSliceSourceText] | 561 ["sourceText", SourceSliceSourceText] |
556 ); | 562 ); |
557 | 563 |
558 | 564 |
559 // Returns the offset of the given position within the containing | |
560 // line. | |
561 function GetPositionInLine(message) { | |
562 var script = %MessageGetScript(message); | |
563 var start_position = %MessageGetStartPosition(message); | |
564 var location = script.locationFromPosition(start_position, true); | |
565 if (location == null) return -1; | |
566 return location.column; | |
567 } | |
568 | |
569 | |
570 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 565 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
571 return new CallSite(recv, fun, pos, false).toString(); | 566 return new CallSite(recv, fun, pos, false).toString(); |
572 } | 567 } |
573 | 568 |
574 // ---------------------------------------------------------------------------- | 569 // ---------------------------------------------------------------------------- |
575 // Error implementation | 570 // Error implementation |
576 | 571 |
577 var CallSiteReceiverKey = NEW_PRIVATE("CallSite#receiver"); | 572 var CallSiteReceiverKey = NEW_PRIVATE("CallSite#receiver"); |
578 var CallSiteFunctionKey = NEW_PRIVATE("CallSite#function"); | 573 var CallSiteFunctionKey = NEW_PRIVATE("CallSite#function"); |
579 var CallSitePositionKey = NEW_PRIVATE("CallSite#position"); | 574 var CallSitePositionKey = NEW_PRIVATE("CallSite#position"); |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); | 993 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); |
999 } | 994 } |
1000 | 995 |
1001 return %ErrorToStringRT(this); | 996 return %ErrorToStringRT(this); |
1002 } | 997 } |
1003 | 998 |
1004 utils.InstallFunctions(GlobalError.prototype, DONT_ENUM, | 999 utils.InstallFunctions(GlobalError.prototype, DONT_ENUM, |
1005 ['toString', ErrorToString]); | 1000 ['toString', ErrorToString]); |
1006 | 1001 |
1007 $errorToString = ErrorToString; | 1002 $errorToString = ErrorToString; |
1008 $messageGetPositionInLine = GetPositionInLine; | |
1009 $messageGetLineNumber = GetLineNumber; | |
1010 $messageGetSourceLine = GetSourceLine; | |
1011 | 1003 |
1012 MakeError = function(type, arg0, arg1, arg2) { | 1004 MakeError = function(type, arg0, arg1, arg2) { |
1013 return MakeGenericError(GlobalError, type, arg0, arg1, arg2); | 1005 return MakeGenericError(GlobalError, type, arg0, arg1, arg2); |
1014 } | 1006 } |
1015 | 1007 |
1016 MakeRangeError = function(type, arg0, arg1, arg2) { | 1008 MakeRangeError = function(type, arg0, arg1, arg2) { |
1017 return MakeGenericError(GlobalRangeError, type, arg0, arg1, arg2); | 1009 return MakeGenericError(GlobalRangeError, type, arg0, arg1, arg2); |
1018 } | 1010 } |
1019 | 1011 |
1020 MakeSyntaxError = function(type, arg0, arg1, arg2) { | 1012 MakeSyntaxError = function(type, arg0, arg1, arg2) { |
1021 return MakeGenericError(GlobalSyntaxError, type, arg0, arg1, arg2); | 1013 return MakeGenericError(GlobalSyntaxError, type, arg0, arg1, arg2); |
1022 } | 1014 } |
1023 | 1015 |
1024 MakeTypeError = function(type, arg0, arg1, arg2) { | 1016 MakeTypeError = function(type, arg0, arg1, arg2) { |
1025 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); | 1017 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); |
1026 } | 1018 } |
1027 | 1019 |
1028 MakeURIError = function() { | 1020 MakeURIError = function() { |
1029 return MakeGenericError(GlobalURIError, kURIMalformed); | 1021 return MakeGenericError(GlobalURIError, kURIMalformed); |
1030 } | 1022 } |
1031 | 1023 |
1032 // Boilerplate for exceptions for stack overflows. Used from | 1024 // Boilerplate for exceptions for stack overflows. Used from |
1033 // Isolate::StackOverflow(). | 1025 // Isolate::StackOverflow(). |
1034 $stackOverflowBoilerplate = MakeRangeError(kStackOverflow); | 1026 var StackOverflowBoilerplate = MakeRangeError(kStackOverflow); |
1035 %DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack', | 1027 %DefineAccessorPropertyUnchecked(StackOverflowBoilerplate, 'stack', |
1036 StackTraceGetter, StackTraceSetter, | 1028 StackTraceGetter, StackTraceSetter, |
1037 DONT_ENUM); | 1029 DONT_ENUM); |
1038 | 1030 |
1039 // Define actual captureStackTrace function after everything has been set up. | 1031 // Define actual captureStackTrace function after everything has been set up. |
1040 captureStackTrace = function captureStackTrace(obj, cons_opt) { | 1032 captureStackTrace = function captureStackTrace(obj, cons_opt) { |
1041 // Define accessors first, as this may fail and throw. | 1033 // Define accessors first, as this may fail and throw. |
1042 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, | 1034 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, |
1043 set: StackTraceSetter, | 1035 set: StackTraceSetter, |
1044 configurable: true }); | 1036 configurable: true }); |
1045 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); | 1037 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); |
1046 }; | 1038 }; |
1047 | 1039 |
1048 GlobalError.captureStackTrace = captureStackTrace; | 1040 GlobalError.captureStackTrace = captureStackTrace; |
1049 | 1041 |
1050 utils.ExportToRuntime(function(to) { | 1042 utils.ExportToRuntime(function(to) { |
1051 to.Error = GlobalError; | 1043 to.Error = GlobalError; |
1052 to.EvalError = GlobalEvalError; | 1044 to.EvalError = GlobalEvalError; |
1053 to.RangeError = GlobalRangeError; | 1045 to.RangeError = GlobalRangeError; |
1054 to.ReferenceError = GlobalReferenceError; | 1046 to.ReferenceError = GlobalReferenceError; |
1055 to.SyntaxError = GlobalSyntaxError; | 1047 to.SyntaxError = GlobalSyntaxError; |
1056 to.TypeError = GlobalTypeError; | 1048 to.TypeError = GlobalTypeError; |
1057 to.URIError = GlobalURIError; | 1049 to.URIError = GlobalURIError; |
1058 to.GetStackTraceLine = GetStackTraceLine; | 1050 to.GetStackTraceLine = GetStackTraceLine; |
1059 to.NoSideEffectToString = NoSideEffectToString; | 1051 to.NoSideEffectToString = NoSideEffectToString; |
1060 to.ToDetailString = ToDetailString; | 1052 to.ToDetailString = ToDetailString; |
1061 to.MakeError = MakeGenericError; | 1053 to.MakeError = MakeGenericError; |
| 1054 to.MessageGetLineNumber = GetLineNumber; |
| 1055 to.MessageGetColumnNumber = GetColumnNumber; |
| 1056 to.MessageGetSourceLine = GetSourceLine; |
| 1057 to.StackOverflowBoilerplate = StackOverflowBoilerplate; |
1062 }); | 1058 }); |
1063 | 1059 |
1064 }); | 1060 }); |
OLD | NEW |