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 $formatMessage; | 8 var $formatMessage; |
9 var $getStackTraceLine; | 9 var $getStackTraceLine; |
10 var $messageGetPositionInLine; | 10 var $messageGetPositionInLine; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 str = "#<error>"; | 217 str = "#<error>"; |
218 } | 218 } |
219 } | 219 } |
220 } | 220 } |
221 result += str; | 221 result += str; |
222 } | 222 } |
223 return result; | 223 return result; |
224 } | 224 } |
225 | 225 |
226 | 226 |
| 227 function NoSideEffectsObjectToString() { |
| 228 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
| 229 if (IS_NULL(this)) return "[object Null]"; |
| 230 return "[object " + %_ClassOf(TO_OBJECT_INLINE(this)) + "]"; |
| 231 } |
| 232 |
| 233 |
227 function NoSideEffectToString(obj) { | 234 function NoSideEffectToString(obj) { |
228 if (IS_STRING(obj)) return obj; | 235 if (IS_STRING(obj)) return obj; |
229 if (IS_NUMBER(obj)) return %_NumberToString(obj); | 236 if (IS_NUMBER(obj)) return %_NumberToString(obj); |
230 if (IS_BOOLEAN(obj)) return obj ? 'true' : 'false'; | 237 if (IS_BOOLEAN(obj)) return obj ? 'true' : 'false'; |
231 if (IS_UNDEFINED(obj)) return 'undefined'; | 238 if (IS_UNDEFINED(obj)) return 'undefined'; |
232 if (IS_NULL(obj)) return 'null'; | 239 if (IS_NULL(obj)) return 'null'; |
233 if (IS_FUNCTION(obj)) { | 240 if (IS_FUNCTION(obj)) { |
234 var str = %_CallFunction(obj, FunctionToString); | 241 var str = %_CallFunction(obj, obj, $functionSourceString); |
235 if (str.length > 128) { | 242 if (str.length > 128) { |
236 str = %_SubString(str, 0, 111) + "...<omitted>..." + | 243 str = %_SubString(str, 0, 111) + "...<omitted>..." + |
237 %_SubString(str, str.length - 2, str.length); | 244 %_SubString(str, str.length - 2, str.length); |
238 } | 245 } |
239 return str; | 246 return str; |
240 } | 247 } |
241 if (IS_SYMBOL(obj)) return %_CallFunction(obj, $symbolToString); | 248 if (IS_SYMBOL(obj)) return %_CallFunction(obj, $symbolToString); |
242 if (IS_OBJECT(obj) | 249 if (IS_OBJECT(obj) |
243 && %GetDataProperty(obj, "toString") === ObjectToString) { | 250 && %GetDataProperty(obj, "toString") === $objectToString) { |
244 var constructor = %GetDataProperty(obj, "constructor"); | 251 var constructor = %GetDataProperty(obj, "constructor"); |
245 if (typeof constructor == "function") { | 252 if (typeof constructor == "function") { |
246 var constructorName = constructor.name; | 253 var constructorName = constructor.name; |
247 if (IS_STRING(constructorName) && constructorName !== "") { | 254 if (IS_STRING(constructorName) && constructorName !== "") { |
248 return "#<" + constructorName + ">"; | 255 return "#<" + constructorName + ">"; |
249 } | 256 } |
250 } | 257 } |
251 } | 258 } |
252 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { | 259 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { |
253 return %_CallFunction(obj, ErrorToString); | 260 return %_CallFunction(obj, ErrorToString); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 function ToStringCheckErrorObject(obj) { | 292 function ToStringCheckErrorObject(obj) { |
286 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { | 293 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { |
287 return %_CallFunction(obj, ErrorToString); | 294 return %_CallFunction(obj, ErrorToString); |
288 } else { | 295 } else { |
289 return ToString(obj); | 296 return ToString(obj); |
290 } | 297 } |
291 } | 298 } |
292 | 299 |
293 | 300 |
294 function ToDetailString(obj) { | 301 function ToDetailString(obj) { |
295 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { | 302 if (obj != null && IS_OBJECT(obj) && obj.toString === $objectToString) { |
296 var constructor = obj.constructor; | 303 var constructor = obj.constructor; |
297 if (typeof constructor == "function") { | 304 if (typeof constructor == "function") { |
298 var constructorName = constructor.name; | 305 var constructorName = constructor.name; |
299 if (IS_STRING(constructorName) && constructorName !== "") { | 306 if (IS_STRING(constructorName) && constructorName !== "") { |
300 return "#<" + constructorName + ">"; | 307 return "#<" + constructorName + ">"; |
301 } | 308 } |
302 } | 309 } |
303 } | 310 } |
304 return ToStringCheckErrorObject(obj); | 311 return ToStringCheckErrorObject(obj); |
305 } | 312 } |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 * | 570 * |
564 * @return {?string} script name if present, value for //# sourceURL or | 571 * @return {?string} script name if present, value for //# sourceURL or |
565 * deprecated //@ sourceURL comment otherwise. | 572 * deprecated //@ sourceURL comment otherwise. |
566 */ | 573 */ |
567 function ScriptNameOrSourceURL() { | 574 function ScriptNameOrSourceURL() { |
568 if (this.source_url) return this.source_url; | 575 if (this.source_url) return this.source_url; |
569 return this.name; | 576 return this.name; |
570 } | 577 } |
571 | 578 |
572 | 579 |
573 SetUpLockedPrototype(Script, [ | 580 $setUpLockedPrototype(Script, [ |
574 "source", | 581 "source", |
575 "name", | 582 "name", |
576 "source_url", | 583 "source_url", |
577 "source_mapping_url", | 584 "source_mapping_url", |
578 "line_ends", | 585 "line_ends", |
579 "line_offset", | 586 "line_offset", |
580 "column_offset" | 587 "column_offset" |
581 ], [ | 588 ], [ |
582 "lineFromPosition", ScriptLineFromPosition, | 589 "lineFromPosition", ScriptLineFromPosition, |
583 "locationFromPosition", ScriptLocationFromPosition, | 590 "locationFromPosition", ScriptLocationFromPosition, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 * Source text for this location. | 634 * Source text for this location. |
628 */ | 635 */ |
629 function SourceLocationSourceText() { | 636 function SourceLocationSourceText() { |
630 return %_CallFunction(this.script.source, | 637 return %_CallFunction(this.script.source, |
631 this.start, | 638 this.start, |
632 this.end, | 639 this.end, |
633 $stringSubstring); | 640 $stringSubstring); |
634 } | 641 } |
635 | 642 |
636 | 643 |
637 SetUpLockedPrototype(SourceLocation, | 644 $setUpLockedPrototype(SourceLocation, |
638 ["script", "position", "line", "column", "start", "end"], | 645 ["script", "position", "line", "column", "start", "end"], |
639 ["sourceText", SourceLocationSourceText] | 646 ["sourceText", SourceLocationSourceText] |
640 ); | 647 ); |
641 | 648 |
642 | 649 |
643 /** | 650 /** |
644 * Class for a source slice. A source slice is a part of a script source with | 651 * Class for a source slice. A source slice is a part of a script source with |
645 * the following properties: | 652 * the following properties: |
646 * script : script object for the source | 653 * script : script object for the source |
647 * from_line : line number for the first line in the slice | 654 * from_line : line number for the first line in the slice |
(...skipping 23 matching lines...) Expand all Loading... |
671 * @return {String} Source text for this slice. The last line will include | 678 * @return {String} Source text for this slice. The last line will include |
672 * the line terminating characters (if any) | 679 * the line terminating characters (if any) |
673 */ | 680 */ |
674 function SourceSliceSourceText() { | 681 function SourceSliceSourceText() { |
675 return %_CallFunction(this.script.source, | 682 return %_CallFunction(this.script.source, |
676 this.from_position, | 683 this.from_position, |
677 this.to_position, | 684 this.to_position, |
678 $stringSubstring); | 685 $stringSubstring); |
679 } | 686 } |
680 | 687 |
681 SetUpLockedPrototype(SourceSlice, | 688 $setUpLockedPrototype(SourceSlice, |
682 ["script", "from_line", "to_line", "from_position", "to_position"], | 689 ["script", "from_line", "to_line", "from_position", "to_position"], |
683 ["sourceText", SourceSliceSourceText] | 690 ["sourceText", SourceSliceSourceText] |
684 ); | 691 ); |
685 | 692 |
686 | 693 |
687 // Returns the offset of the given position within the containing | 694 // Returns the offset of the given position within the containing |
688 // line. | 695 // line. |
689 function GetPositionInLine(message) { | 696 function GetPositionInLine(message) { |
690 var script = %MessageGetScript(message); | 697 var script = %MessageGetScript(message); |
691 var start_position = %MessageGetStartPosition(message); | 698 var start_position = %MessageGetStartPosition(message); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 return %CallSiteGetFunctionNameRT(receiver, fun, pos); | 773 return %CallSiteGetFunctionNameRT(receiver, fun, pos); |
767 } | 774 } |
768 | 775 |
769 function CallSiteGetMethodName() { | 776 function CallSiteGetMethodName() { |
770 // See if we can find a unique property on the receiver that holds | 777 // See if we can find a unique property on the receiver that holds |
771 // this function. | 778 // this function. |
772 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 779 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); |
773 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | 780 var fun = GET_PRIVATE(this, CallSiteFunctionKey); |
774 var ownName = fun.name; | 781 var ownName = fun.name; |
775 if (ownName && receiver && | 782 if (ownName && receiver && |
776 (%_CallFunction(receiver, ownName, ObjectLookupGetter) === fun || | 783 (%_CallFunction(receiver, ownName, $objectLookupGetter) === fun || |
777 %_CallFunction(receiver, ownName, ObjectLookupSetter) === fun || | 784 %_CallFunction(receiver, ownName, $objectLookupSetter) === fun || |
778 (IS_OBJECT(receiver) && %GetDataProperty(receiver, ownName) === fun))) { | 785 (IS_OBJECT(receiver) && %GetDataProperty(receiver, ownName) === fun))) { |
779 // To handle DontEnum properties we guess that the method has | 786 // To handle DontEnum properties we guess that the method has |
780 // the same name as the function. | 787 // the same name as the function. |
781 return ownName; | 788 return ownName; |
782 } | 789 } |
783 var name = null; | 790 var name = null; |
784 for (var prop in receiver) { | 791 for (var prop in receiver) { |
785 if (%_CallFunction(receiver, prop, ObjectLookupGetter) === fun || | 792 if (%_CallFunction(receiver, prop, $objectLookupGetter) === fun || |
786 %_CallFunction(receiver, prop, ObjectLookupSetter) === fun || | 793 %_CallFunction(receiver, prop, $objectLookupSetter) === fun || |
787 (IS_OBJECT(receiver) && %GetDataProperty(receiver, prop) === fun)) { | 794 (IS_OBJECT(receiver) && %GetDataProperty(receiver, prop) === fun)) { |
788 // If we find more than one match bail out to avoid confusion. | 795 // If we find more than one match bail out to avoid confusion. |
789 if (name) { | 796 if (name) { |
790 return null; | 797 return null; |
791 } | 798 } |
792 name = prop; | 799 name = prop; |
793 } | 800 } |
794 } | 801 } |
795 if (name) { | 802 if (name) { |
796 return name; | 803 return name; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 } else { | 900 } else { |
894 line += fileLocation; | 901 line += fileLocation; |
895 addSuffix = false; | 902 addSuffix = false; |
896 } | 903 } |
897 if (addSuffix) { | 904 if (addSuffix) { |
898 line += " (" + fileLocation + ")"; | 905 line += " (" + fileLocation + ")"; |
899 } | 906 } |
900 return line; | 907 return line; |
901 } | 908 } |
902 | 909 |
903 SetUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [ | 910 $setUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [ |
904 "getThis", CallSiteGetThis, | 911 "getThis", CallSiteGetThis, |
905 "getTypeName", CallSiteGetTypeName, | 912 "getTypeName", CallSiteGetTypeName, |
906 "isToplevel", CallSiteIsToplevel, | 913 "isToplevel", CallSiteIsToplevel, |
907 "isEval", CallSiteIsEval, | 914 "isEval", CallSiteIsEval, |
908 "getEvalOrigin", CallSiteGetEvalOrigin, | 915 "getEvalOrigin", CallSiteGetEvalOrigin, |
909 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, | 916 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, |
910 "getFunction", CallSiteGetFunction, | 917 "getFunction", CallSiteGetFunction, |
911 "getFunctionName", CallSiteGetFunctionName, | 918 "getFunctionName", CallSiteGetFunctionName, |
912 "getMethodName", CallSiteGetMethodName, | 919 "getMethodName", CallSiteGetMethodName, |
913 "getFileName", CallSiteGetFileName, | 920 "getFileName", CallSiteGetFileName, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 SET_PRIVATE(this, $stackTraceSymbol, UNDEFINED); | 1089 SET_PRIVATE(this, $stackTraceSymbol, UNDEFINED); |
1083 SET_PRIVATE(this, formatted_stack_trace_symbol, v); | 1090 SET_PRIVATE(this, formatted_stack_trace_symbol, v); |
1084 } | 1091 } |
1085 }; | 1092 }; |
1086 | 1093 |
1087 | 1094 |
1088 // Use a dummy function since we do not actually want to capture a stack trace | 1095 // Use a dummy function since we do not actually want to capture a stack trace |
1089 // when constructing the initial Error prototytpes. | 1096 // when constructing the initial Error prototytpes. |
1090 var captureStackTrace = function captureStackTrace(obj, cons_opt) { | 1097 var captureStackTrace = function captureStackTrace(obj, cons_opt) { |
1091 // Define accessors first, as this may fail and throw. | 1098 // Define accessors first, as this may fail and throw. |
1092 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, | 1099 $objectDefineProperty(obj, 'stack', { get: StackTraceGetter, |
1093 set: StackTraceSetter, | 1100 set: StackTraceSetter, |
1094 configurable: true }); | 1101 configurable: true }); |
1095 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); | 1102 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); |
1096 } | 1103 } |
1097 | 1104 |
1098 | 1105 |
1099 // Define special error type constructors. | 1106 // Define special error type constructors. |
1100 function DefineError(f) { | 1107 function DefineError(f) { |
1101 // Store the error function in both the global object | 1108 // Store the error function in both the global object |
1102 // and the runtime object. The function is fetched | 1109 // and the runtime object. The function is fetched |
1103 // from the runtime object when throwing errors from | 1110 // from the runtime object when throwing errors from |
1104 // within the runtime system to avoid strange side | 1111 // within the runtime system to avoid strange side |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 } catch(e) { | 1215 } catch(e) { |
1209 // If this error message was encountered already return the empty | 1216 // If this error message was encountered already return the empty |
1210 // string for it instead of recursively formatting it. | 1217 // string for it instead of recursively formatting it. |
1211 if (e === cyclic_error_marker) { | 1218 if (e === cyclic_error_marker) { |
1212 return ''; | 1219 return ''; |
1213 } | 1220 } |
1214 throw e; | 1221 throw e; |
1215 } | 1222 } |
1216 } | 1223 } |
1217 | 1224 |
1218 InstallFunctions(GlobalError.prototype, DONT_ENUM, ['toString', ErrorToString]); | 1225 $installFunctions(GlobalError.prototype, DONT_ENUM, |
| 1226 ['toString', ErrorToString]); |
1219 | 1227 |
1220 $errorToString = ErrorToString; | 1228 $errorToString = ErrorToString; |
1221 $formatMessage = FormatMessage; | 1229 $formatMessage = FormatMessage; |
1222 $getStackTraceLine = GetStackTraceLine; | 1230 $getStackTraceLine = GetStackTraceLine; |
1223 $messageGetPositionInLine = GetPositionInLine; | 1231 $messageGetPositionInLine = GetPositionInLine; |
1224 $messageGetLineNumber = GetLineNumber; | 1232 $messageGetLineNumber = GetLineNumber; |
1225 $messageGetSourceLine = GetSourceLine; | 1233 $messageGetSourceLine = GetSourceLine; |
1226 $toDetailString = ToDetailString; | 1234 $toDetailString = ToDetailString; |
1227 | 1235 |
1228 $Error = GlobalError; | 1236 $Error = GlobalError; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 return MakeGenericError(GlobalTypeError, type, [arg]); | 1283 return MakeGenericError(GlobalTypeError, type, [arg]); |
1276 } | 1284 } |
1277 | 1285 |
1278 //Boilerplate for exceptions for stack overflows. Used from | 1286 //Boilerplate for exceptions for stack overflows. Used from |
1279 //Isolate::StackOverflow(). | 1287 //Isolate::StackOverflow(). |
1280 $stackOverflowBoilerplate = MakeRangeError(kStackOverflow); | 1288 $stackOverflowBoilerplate = MakeRangeError(kStackOverflow); |
1281 %DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack', | 1289 %DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack', |
1282 StackTraceGetter, StackTraceSetter, DONT_ENUM); | 1290 StackTraceGetter, StackTraceSetter, DONT_ENUM); |
1283 | 1291 |
1284 })(); | 1292 })(); |
OLD | NEW |