| 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; | 8 var $getStackTraceLine; |
| 9 var $messageGetPositionInLine; | 9 var $messageGetPositionInLine; |
| 10 var $messageGetLineNumber; | 10 var $messageGetLineNumber; |
| 11 var $messageGetSourceLine; | 11 var $messageGetSourceLine; |
| 12 var $noSideEffectToString; | 12 var $noSideEffectToString; |
| 13 var $stackOverflowBoilerplate; | 13 var $stackOverflowBoilerplate; |
| 14 var $stackTraceSymbol; | 14 var $stackTraceSymbol; |
| 15 var $toDetailString; | 15 var $toDetailString; |
| 16 var $Error; | 16 var $Error; |
| 17 var $EvalError; | 17 var $EvalError; |
| 18 var $RangeError; | 18 var $RangeError; |
| 19 var $ReferenceError; | 19 var $ReferenceError; |
| 20 var $SyntaxError; | 20 var $SyntaxError; |
| 21 var $TypeError; | 21 var $TypeError; |
| 22 var $URIError; | 22 var $URIError; |
| 23 var MakeError; | 23 var MakeError; |
| 24 var MakeEvalError; | 24 var MakeEvalError; |
| 25 var MakeRangeError; | 25 var MakeRangeError; |
| 26 var MakeReferenceError; | 26 var MakeReferenceError; |
| 27 var MakeSyntaxError; | 27 var MakeSyntaxError; |
| 28 var MakeTypeError; | 28 var MakeTypeError; |
| 29 var MakeURIError; | 29 var MakeURIError; |
| 30 var MakeReferenceErrorEmbedded; | |
| 31 var MakeSyntaxErrorEmbedded; | |
| 32 var MakeTypeErrorEmbedded; | |
| 33 | 30 |
| 34 (function(global, utils) { | 31 (function(global, utils) { |
| 35 | 32 |
| 36 %CheckIsBootstrapping(); | 33 %CheckIsBootstrapping(); |
| 37 | 34 |
| 38 // ------------------------------------------------------------------- | 35 // ------------------------------------------------------------------- |
| 39 // Imports | 36 // Imports |
| 40 | 37 |
| 41 var GlobalObject = global.Object; | 38 var GlobalObject = global.Object; |
| 42 var InternalArray = utils.InternalArray; | 39 var InternalArray = utils.InternalArray; |
| 40 var ObjectDefineProperty = utils.ObjectDefineProperty; |
| 43 | 41 |
| 42 var ArrayJoin; |
| 43 var ObjectToString; |
| 44 var StringCharAt; | 44 var StringCharAt; |
| 45 var StringIndexOf; | 45 var StringIndexOf; |
| 46 var StringSubstring; | 46 var StringSubstring; |
| 47 | 47 |
| 48 utils.Import(function(from) { | 48 utils.Import(function(from) { |
| 49 ArrayJoin = from.ArrayJoin; |
| 50 ObjectToString = from.ObjectToString; |
| 49 StringCharAt = from.StringCharAt; | 51 StringCharAt = from.StringCharAt; |
| 50 StringIndexOf = from.StringIndexOf; | 52 StringIndexOf = from.StringIndexOf; |
| 51 StringSubstring = from.StringSubstring; | 53 StringSubstring = from.StringSubstring; |
| 52 }); | 54 }); |
| 53 | 55 |
| 54 // ------------------------------------------------------------------- | 56 // ------------------------------------------------------------------- |
| 55 | 57 |
| 56 var GlobalError; | 58 var GlobalError; |
| 57 var GlobalTypeError; | 59 var GlobalTypeError; |
| 58 var GlobalRangeError; | 60 var GlobalRangeError; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 78 if (IS_FUNCTION(obj)) { | 80 if (IS_FUNCTION(obj)) { |
| 79 var str = %_CallFunction(obj, obj, $functionSourceString); | 81 var str = %_CallFunction(obj, obj, $functionSourceString); |
| 80 if (str.length > 128) { | 82 if (str.length > 128) { |
| 81 str = %_SubString(str, 0, 111) + "...<omitted>..." + | 83 str = %_SubString(str, 0, 111) + "...<omitted>..." + |
| 82 %_SubString(str, str.length - 2, str.length); | 84 %_SubString(str, str.length - 2, str.length); |
| 83 } | 85 } |
| 84 return str; | 86 return str; |
| 85 } | 87 } |
| 86 if (IS_SYMBOL(obj)) return %_CallFunction(obj, $symbolToString); | 88 if (IS_SYMBOL(obj)) return %_CallFunction(obj, $symbolToString); |
| 87 if (IS_OBJECT(obj) | 89 if (IS_OBJECT(obj) |
| 88 && %GetDataProperty(obj, "toString") === $objectToString) { | 90 && %GetDataProperty(obj, "toString") === ObjectToString) { |
| 89 var constructor = %GetDataProperty(obj, "constructor"); | 91 var constructor = %GetDataProperty(obj, "constructor"); |
| 90 if (typeof constructor == "function") { | 92 if (typeof constructor == "function") { |
| 91 var constructorName = constructor.name; | 93 var constructorName = constructor.name; |
| 92 if (IS_STRING(constructorName) && constructorName !== "") { | 94 if (IS_STRING(constructorName) && constructorName !== "") { |
| 93 return "#<" + constructorName + ">"; | 95 return "#<" + constructorName + ">"; |
| 94 } | 96 } |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { | 99 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { |
| 98 return %_CallFunction(obj, ErrorToString); | 100 return %_CallFunction(obj, ErrorToString); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 function ToStringCheckErrorObject(obj) { | 132 function ToStringCheckErrorObject(obj) { |
| 131 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { | 133 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { |
| 132 return %_CallFunction(obj, ErrorToString); | 134 return %_CallFunction(obj, ErrorToString); |
| 133 } else { | 135 } else { |
| 134 return $toString(obj); | 136 return $toString(obj); |
| 135 } | 137 } |
| 136 } | 138 } |
| 137 | 139 |
| 138 | 140 |
| 139 function ToDetailString(obj) { | 141 function ToDetailString(obj) { |
| 140 if (obj != null && IS_OBJECT(obj) && obj.toString === $objectToString) { | 142 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { |
| 141 var constructor = obj.constructor; | 143 var constructor = obj.constructor; |
| 142 if (typeof constructor == "function") { | 144 if (typeof constructor == "function") { |
| 143 var constructorName = constructor.name; | 145 var constructorName = constructor.name; |
| 144 if (IS_STRING(constructorName) && constructorName !== "") { | 146 if (IS_STRING(constructorName) && constructorName !== "") { |
| 145 return "#<" + constructorName + ">"; | 147 return "#<" + constructorName + ">"; |
| 146 } | 148 } |
| 147 } | 149 } |
| 148 } | 150 } |
| 149 return ToStringCheckErrorObject(obj); | 151 return ToStringCheckErrorObject(obj); |
| 150 } | 152 } |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 * | 404 * |
| 403 * @return {?string} script name if present, value for //# sourceURL or | 405 * @return {?string} script name if present, value for //# sourceURL or |
| 404 * deprecated //@ sourceURL comment otherwise. | 406 * deprecated //@ sourceURL comment otherwise. |
| 405 */ | 407 */ |
| 406 function ScriptNameOrSourceURL() { | 408 function ScriptNameOrSourceURL() { |
| 407 if (this.source_url) return this.source_url; | 409 if (this.source_url) return this.source_url; |
| 408 return this.name; | 410 return this.name; |
| 409 } | 411 } |
| 410 | 412 |
| 411 | 413 |
| 412 $setUpLockedPrototype(Script, [ | 414 utils.SetUpLockedPrototype(Script, [ |
| 413 "source", | 415 "source", |
| 414 "name", | 416 "name", |
| 415 "source_url", | 417 "source_url", |
| 416 "source_mapping_url", | 418 "source_mapping_url", |
| 417 "line_ends", | 419 "line_ends", |
| 418 "line_offset", | 420 "line_offset", |
| 419 "column_offset" | 421 "column_offset" |
| 420 ], [ | 422 ], [ |
| 421 "lineFromPosition", ScriptLineFromPosition, | 423 "lineFromPosition", ScriptLineFromPosition, |
| 422 "locationFromPosition", ScriptLocationFromPosition, | 424 "locationFromPosition", ScriptLocationFromPosition, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 * Source text for this location. | 468 * Source text for this location. |
| 467 */ | 469 */ |
| 468 function SourceLocationSourceText() { | 470 function SourceLocationSourceText() { |
| 469 return %_CallFunction(this.script.source, | 471 return %_CallFunction(this.script.source, |
| 470 this.start, | 472 this.start, |
| 471 this.end, | 473 this.end, |
| 472 StringSubstring); | 474 StringSubstring); |
| 473 } | 475 } |
| 474 | 476 |
| 475 | 477 |
| 476 $setUpLockedPrototype(SourceLocation, | 478 utils.SetUpLockedPrototype(SourceLocation, |
| 477 ["script", "position", "line", "column", "start", "end"], | 479 ["script", "position", "line", "column", "start", "end"], |
| 478 ["sourceText", SourceLocationSourceText] | 480 ["sourceText", SourceLocationSourceText] |
| 479 ); | 481 ); |
| 480 | 482 |
| 481 | 483 |
| 482 /** | 484 /** |
| 483 * Class for a source slice. A source slice is a part of a script source with | 485 * Class for a source slice. A source slice is a part of a script source with |
| 484 * the following properties: | 486 * the following properties: |
| 485 * script : script object for the source | 487 * script : script object for the source |
| 486 * from_line : line number for the first line in the slice | 488 * from_line : line number for the first line in the slice |
| (...skipping 23 matching lines...) Expand all Loading... |
| 510 * @return {String} Source text for this slice. The last line will include | 512 * @return {String} Source text for this slice. The last line will include |
| 511 * the line terminating characters (if any) | 513 * the line terminating characters (if any) |
| 512 */ | 514 */ |
| 513 function SourceSliceSourceText() { | 515 function SourceSliceSourceText() { |
| 514 return %_CallFunction(this.script.source, | 516 return %_CallFunction(this.script.source, |
| 515 this.from_position, | 517 this.from_position, |
| 516 this.to_position, | 518 this.to_position, |
| 517 StringSubstring); | 519 StringSubstring); |
| 518 } | 520 } |
| 519 | 521 |
| 520 $setUpLockedPrototype(SourceSlice, | 522 utils.SetUpLockedPrototype(SourceSlice, |
| 521 ["script", "from_line", "to_line", "from_position", "to_position"], | 523 ["script", "from_line", "to_line", "from_position", "to_position"], |
| 522 ["sourceText", SourceSliceSourceText] | 524 ["sourceText", SourceSliceSourceText] |
| 523 ); | 525 ); |
| 524 | 526 |
| 525 | 527 |
| 526 // Returns the offset of the given position within the containing | 528 // Returns the offset of the given position within the containing |
| 527 // line. | 529 // line. |
| 528 function GetPositionInLine(message) { | 530 function GetPositionInLine(message) { |
| 529 var script = %MessageGetScript(message); | 531 var script = %MessageGetScript(message); |
| 530 var start_position = %MessageGetStartPosition(message); | 532 var start_position = %MessageGetStartPosition(message); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 } else { | 710 } else { |
| 709 line += fileLocation; | 711 line += fileLocation; |
| 710 addSuffix = false; | 712 addSuffix = false; |
| 711 } | 713 } |
| 712 if (addSuffix) { | 714 if (addSuffix) { |
| 713 line += " (" + fileLocation + ")"; | 715 line += " (" + fileLocation + ")"; |
| 714 } | 716 } |
| 715 return line; | 717 return line; |
| 716 } | 718 } |
| 717 | 719 |
| 718 $setUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [ | 720 utils.SetUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [ |
| 719 "getThis", CallSiteGetThis, | 721 "getThis", CallSiteGetThis, |
| 720 "getTypeName", CallSiteGetTypeName, | 722 "getTypeName", CallSiteGetTypeName, |
| 721 "isToplevel", CallSiteIsToplevel, | 723 "isToplevel", CallSiteIsToplevel, |
| 722 "isEval", CallSiteIsEval, | 724 "isEval", CallSiteIsEval, |
| 723 "getEvalOrigin", CallSiteGetEvalOrigin, | 725 "getEvalOrigin", CallSiteGetEvalOrigin, |
| 724 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, | 726 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, |
| 725 "getFunction", CallSiteGetFunction, | 727 "getFunction", CallSiteGetFunction, |
| 726 "getFunctionName", CallSiteGetFunctionName, | 728 "getFunctionName", CallSiteGetFunctionName, |
| 727 "getMethodName", CallSiteGetMethodName, | 729 "getMethodName", CallSiteGetMethodName, |
| 728 "getFileName", CallSiteGetFileName, | 730 "getFileName", CallSiteGetFileName, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 } catch (e) { | 837 } catch (e) { |
| 836 try { | 838 try { |
| 837 line = "<error: " + e + ">"; | 839 line = "<error: " + e + ">"; |
| 838 } catch (ee) { | 840 } catch (ee) { |
| 839 // Any code that reaches this point is seriously nasty! | 841 // Any code that reaches this point is seriously nasty! |
| 840 line = "<error>"; | 842 line = "<error>"; |
| 841 } | 843 } |
| 842 } | 844 } |
| 843 lines.push(" at " + line); | 845 lines.push(" at " + line); |
| 844 } | 846 } |
| 845 return %_CallFunction(lines, "\n", $arrayJoin); | 847 return %_CallFunction(lines, "\n", ArrayJoin); |
| 846 } | 848 } |
| 847 | 849 |
| 848 | 850 |
| 849 function GetTypeName(receiver, requireConstructor) { | 851 function GetTypeName(receiver, requireConstructor) { |
| 850 var constructor = receiver.constructor; | 852 var constructor = receiver.constructor; |
| 851 if (!constructor) { | 853 if (!constructor) { |
| 852 return requireConstructor ? null : | 854 return requireConstructor ? null : |
| 853 %_CallFunction(receiver, NoSideEffectsObjectToString); | 855 %_CallFunction(receiver, NoSideEffectsObjectToString); |
| 854 } | 856 } |
| 855 var constructorName = constructor.name; | 857 var constructorName = constructor.name; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 var StackTraceSetter = function(v) { | 897 var StackTraceSetter = function(v) { |
| 896 if (HAS_PRIVATE(this, $stackTraceSymbol)) { | 898 if (HAS_PRIVATE(this, $stackTraceSymbol)) { |
| 897 SET_PRIVATE(this, $stackTraceSymbol, UNDEFINED); | 899 SET_PRIVATE(this, $stackTraceSymbol, UNDEFINED); |
| 898 SET_PRIVATE(this, formatted_stack_trace_symbol, v); | 900 SET_PRIVATE(this, formatted_stack_trace_symbol, v); |
| 899 } | 901 } |
| 900 }; | 902 }; |
| 901 | 903 |
| 902 | 904 |
| 903 // Use a dummy function since we do not actually want to capture a stack trace | 905 // Use a dummy function since we do not actually want to capture a stack trace |
| 904 // when constructing the initial Error prototytpes. | 906 // when constructing the initial Error prototytpes. |
| 905 var captureStackTrace = function captureStackTrace(obj, cons_opt) { | 907 var captureStackTrace = function() {}; |
| 906 // Define accessors first, as this may fail and throw. | |
| 907 $objectDefineProperty(obj, 'stack', { get: StackTraceGetter, | |
| 908 set: StackTraceSetter, | |
| 909 configurable: true }); | |
| 910 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); | |
| 911 } | |
| 912 | 908 |
| 913 | 909 |
| 914 // Define special error type constructors. | 910 // Define special error type constructors. |
| 915 function DefineError(global, f) { | 911 function DefineError(global, f) { |
| 916 // Store the error function in both the global object | 912 // Store the error function in both the global object |
| 917 // and the runtime object. The function is fetched | 913 // and the runtime object. The function is fetched |
| 918 // from the runtime object when throwing errors from | 914 // from the runtime object when throwing errors from |
| 919 // within the runtime system to avoid strange side | 915 // within the runtime system to avoid strange side |
| 920 // effects when overwriting the error functions from | 916 // effects when overwriting the error functions from |
| 921 // user code. | 917 // user code. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 }; | 952 }; |
| 957 | 953 |
| 958 GlobalError = DefineError(global, function Error() { }); | 954 GlobalError = DefineError(global, function Error() { }); |
| 959 GlobalEvalError = DefineError(global, function EvalError() { }); | 955 GlobalEvalError = DefineError(global, function EvalError() { }); |
| 960 GlobalRangeError = DefineError(global, function RangeError() { }); | 956 GlobalRangeError = DefineError(global, function RangeError() { }); |
| 961 GlobalReferenceError = DefineError(global, function ReferenceError() { }); | 957 GlobalReferenceError = DefineError(global, function ReferenceError() { }); |
| 962 GlobalSyntaxError = DefineError(global, function SyntaxError() { }); | 958 GlobalSyntaxError = DefineError(global, function SyntaxError() { }); |
| 963 GlobalTypeError = DefineError(global, function TypeError() { }); | 959 GlobalTypeError = DefineError(global, function TypeError() { }); |
| 964 GlobalURIError = DefineError(global, function URIError() { }); | 960 GlobalURIError = DefineError(global, function URIError() { }); |
| 965 | 961 |
| 966 | |
| 967 GlobalError.captureStackTrace = captureStackTrace; | |
| 968 | |
| 969 %AddNamedProperty(GlobalError.prototype, 'message', '', DONT_ENUM); | 962 %AddNamedProperty(GlobalError.prototype, 'message', '', DONT_ENUM); |
| 970 | 963 |
| 971 // Global list of error objects visited during ErrorToString. This is | 964 // Global list of error objects visited during ErrorToString. This is |
| 972 // used to detect cycles in error toString formatting. | 965 // used to detect cycles in error toString formatting. |
| 973 var visited_errors = new InternalArray(); | 966 var visited_errors = new InternalArray(); |
| 974 var cyclic_error_marker = new GlobalObject(); | 967 var cyclic_error_marker = new GlobalObject(); |
| 975 | 968 |
| 976 function GetPropertyWithoutInvokingMonkeyGetters(error, name) { | 969 function GetPropertyWithoutInvokingMonkeyGetters(error, name) { |
| 977 var current = error; | 970 var current = error; |
| 978 // Climb the prototype chain until we find the holder. | 971 // Climb the prototype chain until we find the holder. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 } catch(e) { | 1016 } catch(e) { |
| 1024 // If this error message was encountered already return the empty | 1017 // If this error message was encountered already return the empty |
| 1025 // string for it instead of recursively formatting it. | 1018 // string for it instead of recursively formatting it. |
| 1026 if (e === cyclic_error_marker) { | 1019 if (e === cyclic_error_marker) { |
| 1027 return ''; | 1020 return ''; |
| 1028 } | 1021 } |
| 1029 throw e; | 1022 throw e; |
| 1030 } | 1023 } |
| 1031 } | 1024 } |
| 1032 | 1025 |
| 1033 $installFunctions(GlobalError.prototype, DONT_ENUM, | 1026 utils.InstallFunctions(GlobalError.prototype, DONT_ENUM, |
| 1034 ['toString', ErrorToString]); | 1027 ['toString', ErrorToString]); |
| 1035 | 1028 |
| 1036 $errorToString = ErrorToString; | 1029 $errorToString = ErrorToString; |
| 1037 $getStackTraceLine = GetStackTraceLine; | 1030 $getStackTraceLine = GetStackTraceLine; |
| 1038 $messageGetPositionInLine = GetPositionInLine; | 1031 $messageGetPositionInLine = GetPositionInLine; |
| 1039 $messageGetLineNumber = GetLineNumber; | 1032 $messageGetLineNumber = GetLineNumber; |
| 1040 $messageGetSourceLine = GetSourceLine; | 1033 $messageGetSourceLine = GetSourceLine; |
| 1041 $noSideEffectToString = NoSideEffectToString; | 1034 $noSideEffectToString = NoSideEffectToString; |
| 1042 $toDetailString = ToDetailString; | 1035 $toDetailString = ToDetailString; |
| 1043 | 1036 |
| 1044 $Error = GlobalError; | 1037 $Error = GlobalError; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1070 } | 1063 } |
| 1071 | 1064 |
| 1072 MakeTypeError = function(type, arg0, arg1, arg2) { | 1065 MakeTypeError = function(type, arg0, arg1, arg2) { |
| 1073 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); | 1066 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); |
| 1074 } | 1067 } |
| 1075 | 1068 |
| 1076 MakeURIError = function() { | 1069 MakeURIError = function() { |
| 1077 return MakeGenericError(GlobalURIError, kURIMalformed); | 1070 return MakeGenericError(GlobalURIError, kURIMalformed); |
| 1078 } | 1071 } |
| 1079 | 1072 |
| 1080 //Boilerplate for exceptions for stack overflows. Used from | 1073 // Boilerplate for exceptions for stack overflows. Used from |
| 1081 //Isolate::StackOverflow(). | 1074 // Isolate::StackOverflow(). |
| 1082 $stackOverflowBoilerplate = MakeRangeError(kStackOverflow); | 1075 $stackOverflowBoilerplate = MakeRangeError(kStackOverflow); |
| 1083 %DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack', | 1076 %DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack', |
| 1084 StackTraceGetter, StackTraceSetter, DONT_ENUM); | 1077 StackTraceGetter, StackTraceSetter, |
| 1078 DONT_ENUM); |
| 1085 | 1079 |
| 1086 }) | 1080 // Define actual captureStackTrace function after everything has been set up. |
| 1081 captureStackTrace = function captureStackTrace(obj, cons_opt) { |
| 1082 // Define accessors first, as this may fail and throw. |
| 1083 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, |
| 1084 set: StackTraceSetter, |
| 1085 configurable: true }); |
| 1086 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); |
| 1087 }; |
| 1088 |
| 1089 GlobalError.captureStackTrace = captureStackTrace; |
| 1090 |
| 1091 }); |
| OLD | NEW |