| 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 $internalErrorSymbol; | |
| 9 var $stackTraceSymbol; | |
| 10 var MakeError; | 8 var MakeError; |
| 11 var MakeEvalError; | 9 var MakeEvalError; |
| 12 var MakeRangeError; | 10 var MakeRangeError; |
| 13 var MakeReferenceError; | 11 var MakeReferenceError; |
| 14 var MakeSyntaxError; | 12 var MakeSyntaxError; |
| 15 var MakeTypeError; | 13 var MakeTypeError; |
| 16 var MakeURIError; | 14 var MakeURIError; |
| 17 | 15 |
| 18 (function(global, utils) { | 16 (function(global, utils) { |
| 19 | 17 |
| 20 %CheckIsBootstrapping(); | 18 %CheckIsBootstrapping(); |
| 21 | 19 |
| 22 // ------------------------------------------------------------------- | 20 // ------------------------------------------------------------------- |
| 23 // Imports | 21 // Imports |
| 24 | 22 |
| 25 var ArrayJoin; | 23 var ArrayJoin; |
| 26 var Bool16x8ToString; | 24 var Bool16x8ToString; |
| 27 var Bool32x4ToString; | 25 var Bool32x4ToString; |
| 28 var Bool8x16ToString; | 26 var Bool8x16ToString; |
| 27 var callSiteReceiverSymbol = |
| 28 utils.GetPrivateSymbol("call_site_receiver_symbol"); |
| 29 var callSiteFunctionSymbol = |
| 30 utils.GetPrivateSymbol("call_site_function_symbol"); |
| 31 var callSitePositionSymbol = |
| 32 utils.GetPrivateSymbol("call_site_position_symbol"); |
| 33 var callSiteStrictSymbol = utils.GetPrivateSymbol("call_site_strict_symbol"); |
| 29 var Float32x4ToString; | 34 var Float32x4ToString; |
| 35 var formattedStackTraceSymbol = |
| 36 utils.GetPrivateSymbol("formatted_stack_trace_symbol"); |
| 30 var FunctionSourceString | 37 var FunctionSourceString |
| 31 var GlobalObject = global.Object; | 38 var GlobalObject = global.Object; |
| 32 var Int16x8ToString; | 39 var Int16x8ToString; |
| 33 var Int32x4ToString; | 40 var Int32x4ToString; |
| 34 var Int8x16ToString; | 41 var Int8x16ToString; |
| 35 var InternalArray = utils.InternalArray; | 42 var InternalArray = utils.InternalArray; |
| 43 var internalErrorSymbol = utils.GetPrivateSymbol("internal_error_symbol"); |
| 36 var ObjectDefineProperty; | 44 var ObjectDefineProperty; |
| 37 var ObjectToString; | 45 var ObjectToString; |
| 46 var stackTraceSymbol = utils.GetPrivateSymbol("stack_trace_symbol"); |
| 38 var StringCharAt; | 47 var StringCharAt; |
| 39 var StringIndexOf; | 48 var StringIndexOf; |
| 40 var StringSubstring; | 49 var StringSubstring; |
| 41 var ToString; | 50 var ToString; |
| 42 | 51 |
| 43 utils.Import(function(from) { | 52 utils.Import(function(from) { |
| 44 ArrayJoin = from.ArrayJoin; | 53 ArrayJoin = from.ArrayJoin; |
| 45 Bool16x8ToString = from.Bool16x8ToString; | 54 Bool16x8ToString = from.Bool16x8ToString; |
| 46 Bool32x4ToString = from.Bool32x4ToString; | 55 Bool32x4ToString = from.Bool32x4ToString; |
| 47 Bool8x16ToString = from.Bool8x16ToString; | 56 Bool8x16ToString = from.Bool8x16ToString; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 return "#<" + constructorName + ">"; | 175 return "#<" + constructorName + ">"; |
| 167 } | 176 } |
| 168 } | 177 } |
| 169 } | 178 } |
| 170 return ToStringCheckErrorObject(obj); | 179 return ToStringCheckErrorObject(obj); |
| 171 } | 180 } |
| 172 | 181 |
| 173 | 182 |
| 174 function MakeGenericError(constructor, type, arg0, arg1, arg2) { | 183 function MakeGenericError(constructor, type, arg0, arg1, arg2) { |
| 175 var error = new constructor(FormatMessage(type, arg0, arg1, arg2)); | 184 var error = new constructor(FormatMessage(type, arg0, arg1, arg2)); |
| 176 error[$internalErrorSymbol] = true; | 185 error[internalErrorSymbol] = true; |
| 177 return error; | 186 return error; |
| 178 } | 187 } |
| 179 | 188 |
| 180 | 189 |
| 181 /** | 190 /** |
| 182 * Set up the Script function and constructor. | 191 * Set up the Script function and constructor. |
| 183 */ | 192 */ |
| 184 %FunctionSetInstanceClassName(Script, 'Script'); | 193 %FunctionSetInstanceClassName(Script, 'Script'); |
| 185 %AddNamedProperty(Script.prototype, 'constructor', Script, | 194 %AddNamedProperty(Script.prototype, 'constructor', Script, |
| 186 DONT_ENUM | DONT_DELETE | READ_ONLY); | 195 DONT_ENUM | DONT_DELETE | READ_ONLY); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 ); | 576 ); |
| 568 | 577 |
| 569 | 578 |
| 570 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 579 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
| 571 return new CallSite(recv, fun, pos, false).toString(); | 580 return new CallSite(recv, fun, pos, false).toString(); |
| 572 } | 581 } |
| 573 | 582 |
| 574 // ---------------------------------------------------------------------------- | 583 // ---------------------------------------------------------------------------- |
| 575 // Error implementation | 584 // Error implementation |
| 576 | 585 |
| 577 var CallSiteReceiverKey = NEW_PRIVATE("CallSite#receiver"); | |
| 578 var CallSiteFunctionKey = NEW_PRIVATE("CallSite#function"); | |
| 579 var CallSitePositionKey = NEW_PRIVATE("CallSite#position"); | |
| 580 var CallSiteStrictModeKey = NEW_PRIVATE("CallSite#strict_mode"); | |
| 581 | |
| 582 function CallSite(receiver, fun, pos, strict_mode) { | 586 function CallSite(receiver, fun, pos, strict_mode) { |
| 583 SET_PRIVATE(this, CallSiteReceiverKey, receiver); | 587 SET_PRIVATE(this, callSiteReceiverSymbol, receiver); |
| 584 SET_PRIVATE(this, CallSiteFunctionKey, fun); | 588 SET_PRIVATE(this, callSiteFunctionSymbol, fun); |
| 585 SET_PRIVATE(this, CallSitePositionKey, pos); | 589 SET_PRIVATE(this, callSitePositionSymbol, pos); |
| 586 SET_PRIVATE(this, CallSiteStrictModeKey, strict_mode); | 590 SET_PRIVATE(this, callSiteStrictSymbol, strict_mode); |
| 587 } | 591 } |
| 588 | 592 |
| 589 function CallSiteGetThis() { | 593 function CallSiteGetThis() { |
| 590 return GET_PRIVATE(this, CallSiteStrictModeKey) | 594 return GET_PRIVATE(this, callSiteStrictSymbol) |
| 591 ? UNDEFINED : GET_PRIVATE(this, CallSiteReceiverKey); | 595 ? UNDEFINED : GET_PRIVATE(this, callSiteReceiverSymbol); |
| 592 } | 596 } |
| 593 | 597 |
| 594 function CallSiteGetFunction() { | 598 function CallSiteGetFunction() { |
| 595 return GET_PRIVATE(this, CallSiteStrictModeKey) | 599 return GET_PRIVATE(this, callSiteStrictSymbol) |
| 596 ? UNDEFINED : GET_PRIVATE(this, CallSiteFunctionKey); | 600 ? UNDEFINED : GET_PRIVATE(this, callSiteFunctionSymbol); |
| 597 } | 601 } |
| 598 | 602 |
| 599 function CallSiteGetPosition() { | 603 function CallSiteGetPosition() { |
| 600 return GET_PRIVATE(this, CallSitePositionKey); | 604 return GET_PRIVATE(this, callSitePositionSymbol); |
| 601 } | 605 } |
| 602 | 606 |
| 603 function CallSiteGetTypeName() { | 607 function CallSiteGetTypeName() { |
| 604 return GetTypeName(GET_PRIVATE(this, CallSiteReceiverKey), false); | 608 return GetTypeName(GET_PRIVATE(this, callSiteReceiverSymbol), false); |
| 605 } | 609 } |
| 606 | 610 |
| 607 function CallSiteIsToplevel() { | 611 function CallSiteIsToplevel() { |
| 608 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 612 return %CallSiteIsToplevelRT(this); |
| 609 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 610 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 611 return %CallSiteIsToplevelRT(receiver, fun, pos); | |
| 612 } | 613 } |
| 613 | 614 |
| 614 function CallSiteIsEval() { | 615 function CallSiteIsEval() { |
| 615 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 616 return %CallSiteIsEvalRT(this); |
| 616 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 617 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 618 return %CallSiteIsEvalRT(receiver, fun, pos); | |
| 619 } | 617 } |
| 620 | 618 |
| 621 function CallSiteGetEvalOrigin() { | 619 function CallSiteGetEvalOrigin() { |
| 622 var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); | 620 var script = %FunctionGetScript(GET_PRIVATE(this, callSiteFunctionSymbol)); |
| 623 return FormatEvalOrigin(script); | 621 return FormatEvalOrigin(script); |
| 624 } | 622 } |
| 625 | 623 |
| 626 function CallSiteGetScriptNameOrSourceURL() { | 624 function CallSiteGetScriptNameOrSourceURL() { |
| 627 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 625 return %CallSiteGetScriptNameOrSourceUrlRT(this); |
| 628 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 629 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 630 return %CallSiteGetScriptNameOrSourceUrlRT(receiver, fun, pos); | |
| 631 } | 626 } |
| 632 | 627 |
| 633 function CallSiteGetFunctionName() { | 628 function CallSiteGetFunctionName() { |
| 634 // See if the function knows its own name | 629 // See if the function knows its own name |
| 635 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 630 return %CallSiteGetFunctionNameRT(this); |
| 636 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 637 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 638 return %CallSiteGetFunctionNameRT(receiver, fun, pos); | |
| 639 } | 631 } |
| 640 | 632 |
| 641 function CallSiteGetMethodName() { | 633 function CallSiteGetMethodName() { |
| 642 // See if we can find a unique property on the receiver that holds | 634 // See if we can find a unique property on the receiver that holds |
| 643 // this function. | 635 // this function. |
| 644 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 636 return %CallSiteGetMethodNameRT(this); |
| 645 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 646 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 647 return %CallSiteGetMethodNameRT(receiver, fun, pos); | |
| 648 } | 637 } |
| 649 | 638 |
| 650 function CallSiteGetFileName() { | 639 function CallSiteGetFileName() { |
| 651 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 640 return %CallSiteGetFileNameRT(this); |
| 652 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 653 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 654 return %CallSiteGetFileNameRT(receiver, fun, pos); | |
| 655 } | 641 } |
| 656 | 642 |
| 657 function CallSiteGetLineNumber() { | 643 function CallSiteGetLineNumber() { |
| 658 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 644 return %CallSiteGetLineNumberRT(this); |
| 659 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 660 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 661 return %CallSiteGetLineNumberRT(receiver, fun, pos); | |
| 662 } | 645 } |
| 663 | 646 |
| 664 function CallSiteGetColumnNumber() { | 647 function CallSiteGetColumnNumber() { |
| 665 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 648 return %CallSiteGetColumnNumberRT(this); |
| 666 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 667 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 668 return %CallSiteGetColumnNumberRT(receiver, fun, pos); | |
| 669 } | 649 } |
| 670 | 650 |
| 671 function CallSiteIsNative() { | 651 function CallSiteIsNative() { |
| 672 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 652 return %CallSiteIsNativeRT(this); |
| 673 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 674 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 675 return %CallSiteIsNativeRT(receiver, fun, pos); | |
| 676 } | 653 } |
| 677 | 654 |
| 678 function CallSiteIsConstructor() { | 655 function CallSiteIsConstructor() { |
| 679 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); | 656 return %CallSiteIsConstructorRT(this); |
| 680 var fun = GET_PRIVATE(this, CallSiteFunctionKey); | |
| 681 var pos = GET_PRIVATE(this, CallSitePositionKey); | |
| 682 return %CallSiteIsConstructorRT(receiver, fun, pos); | |
| 683 } | 657 } |
| 684 | 658 |
| 685 function CallSiteToString() { | 659 function CallSiteToString() { |
| 686 var fileName; | 660 var fileName; |
| 687 var fileLocation = ""; | 661 var fileLocation = ""; |
| 688 if (this.isNative()) { | 662 if (this.isNative()) { |
| 689 fileLocation = "native"; | 663 fileLocation = "native"; |
| 690 } else { | 664 } else { |
| 691 fileName = this.getScriptNameOrSourceURL(); | 665 fileName = this.getScriptNameOrSourceURL(); |
| 692 if (!fileName && this.isEval()) { | 666 if (!fileName && this.isEval()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 711 } | 685 } |
| 712 } | 686 } |
| 713 } | 687 } |
| 714 | 688 |
| 715 var line = ""; | 689 var line = ""; |
| 716 var functionName = this.getFunctionName(); | 690 var functionName = this.getFunctionName(); |
| 717 var addSuffix = true; | 691 var addSuffix = true; |
| 718 var isConstructor = this.isConstructor(); | 692 var isConstructor = this.isConstructor(); |
| 719 var isMethodCall = !(this.isToplevel() || isConstructor); | 693 var isMethodCall = !(this.isToplevel() || isConstructor); |
| 720 if (isMethodCall) { | 694 if (isMethodCall) { |
| 721 var typeName = GetTypeName(GET_PRIVATE(this, CallSiteReceiverKey), true); | 695 var typeName = GetTypeName(GET_PRIVATE(this, callSiteReceiverSymbol), true); |
| 722 var methodName = this.getMethodName(); | 696 var methodName = this.getMethodName(); |
| 723 if (functionName) { | 697 if (functionName) { |
| 724 if (typeName && | 698 if (typeName && |
| 725 %_CallFunction(functionName, typeName, StringIndexOf) != 0) { | 699 %_CallFunction(functionName, typeName, StringIndexOf) != 0) { |
| 726 line += typeName + "."; | 700 line += typeName + "."; |
| 727 } | 701 } |
| 728 line += functionName; | 702 line += functionName; |
| 729 if (methodName && | 703 if (methodName && |
| 730 (%_CallFunction(functionName, "." + methodName, StringIndexOf) != | 704 (%_CallFunction(functionName, "." + methodName, StringIndexOf) != |
| 731 functionName.length - methodName.length - 1)) { | 705 functionName.length - methodName.length - 1)) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 %_CallFunction(receiver, NoSideEffectsObjectToString); | 861 %_CallFunction(receiver, NoSideEffectsObjectToString); |
| 888 } | 862 } |
| 889 var constructorName = constructor.name; | 863 var constructorName = constructor.name; |
| 890 if (!constructorName) { | 864 if (!constructorName) { |
| 891 return requireConstructor ? null : | 865 return requireConstructor ? null : |
| 892 %_CallFunction(receiver, NoSideEffectsObjectToString); | 866 %_CallFunction(receiver, NoSideEffectsObjectToString); |
| 893 } | 867 } |
| 894 return constructorName; | 868 return constructorName; |
| 895 } | 869 } |
| 896 | 870 |
| 897 var formatted_stack_trace_symbol = NEW_PRIVATE("formatted stack trace"); | |
| 898 | |
| 899 | 871 |
| 900 // Format the stack trace if not yet done, and return it. | 872 // Format the stack trace if not yet done, and return it. |
| 901 // Cache the formatted stack trace on the holder. | 873 // Cache the formatted stack trace on the holder. |
| 902 var StackTraceGetter = function() { | 874 var StackTraceGetter = function() { |
| 903 var formatted_stack_trace = UNDEFINED; | 875 var formatted_stack_trace = UNDEFINED; |
| 904 var holder = this; | 876 var holder = this; |
| 905 while (holder) { | 877 while (holder) { |
| 906 var formatted_stack_trace = | 878 var formatted_stack_trace = |
| 907 GET_PRIVATE(holder, formatted_stack_trace_symbol); | 879 GET_PRIVATE(holder, formattedStackTraceSymbol); |
| 908 if (IS_UNDEFINED(formatted_stack_trace)) { | 880 if (IS_UNDEFINED(formatted_stack_trace)) { |
| 909 // No formatted stack trace available. | 881 // No formatted stack trace available. |
| 910 var stack_trace = GET_PRIVATE(holder, $stackTraceSymbol); | 882 var stack_trace = GET_PRIVATE(holder, stackTraceSymbol); |
| 911 if (IS_UNDEFINED(stack_trace)) { | 883 if (IS_UNDEFINED(stack_trace)) { |
| 912 // Neither formatted nor structured stack trace available. | 884 // Neither formatted nor structured stack trace available. |
| 913 // Look further up the prototype chain. | 885 // Look further up the prototype chain. |
| 914 holder = %_GetPrototype(holder); | 886 holder = %_GetPrototype(holder); |
| 915 continue; | 887 continue; |
| 916 } | 888 } |
| 917 formatted_stack_trace = FormatStackTrace(holder, stack_trace); | 889 formatted_stack_trace = FormatStackTrace(holder, stack_trace); |
| 918 SET_PRIVATE(holder, $stackTraceSymbol, UNDEFINED); | 890 SET_PRIVATE(holder, stackTraceSymbol, UNDEFINED); |
| 919 SET_PRIVATE(holder, formatted_stack_trace_symbol, formatted_stack_trace); | 891 SET_PRIVATE(holder, formattedStackTraceSymbol, formatted_stack_trace); |
| 920 } | 892 } |
| 921 return formatted_stack_trace; | 893 return formatted_stack_trace; |
| 922 } | 894 } |
| 923 return UNDEFINED; | 895 return UNDEFINED; |
| 924 }; | 896 }; |
| 925 | 897 |
| 926 | 898 |
| 927 // If the receiver equals the holder, set the formatted stack trace that the | 899 // If the receiver equals the holder, set the formatted stack trace that the |
| 928 // getter returns. | 900 // getter returns. |
| 929 var StackTraceSetter = function(v) { | 901 var StackTraceSetter = function(v) { |
| 930 if (HAS_PRIVATE(this, $stackTraceSymbol)) { | 902 if (HAS_PRIVATE(this, stackTraceSymbol)) { |
| 931 SET_PRIVATE(this, $stackTraceSymbol, UNDEFINED); | 903 SET_PRIVATE(this, stackTraceSymbol, UNDEFINED); |
| 932 SET_PRIVATE(this, formatted_stack_trace_symbol, v); | 904 SET_PRIVATE(this, formattedStackTraceSymbol, v); |
| 933 } | 905 } |
| 934 }; | 906 }; |
| 935 | 907 |
| 936 | 908 |
| 937 // Use a dummy function since we do not actually want to capture a stack trace | 909 // Use a dummy function since we do not actually want to capture a stack trace |
| 938 // when constructing the initial Error prototytpes. | 910 // when constructing the initial Error prototytpes. |
| 939 var captureStackTrace = function() {}; | 911 var captureStackTrace = function() {}; |
| 940 | 912 |
| 941 | 913 |
| 942 // Define special error type constructors. | 914 // Define special error type constructors. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 to.NoSideEffectToString = NoSideEffectToString; | 1028 to.NoSideEffectToString = NoSideEffectToString; |
| 1057 to.ToDetailString = ToDetailString; | 1029 to.ToDetailString = ToDetailString; |
| 1058 to.MakeError = MakeGenericError; | 1030 to.MakeError = MakeGenericError; |
| 1059 to.MessageGetLineNumber = GetLineNumber; | 1031 to.MessageGetLineNumber = GetLineNumber; |
| 1060 to.MessageGetColumnNumber = GetColumnNumber; | 1032 to.MessageGetColumnNumber = GetColumnNumber; |
| 1061 to.MessageGetSourceLine = GetSourceLine; | 1033 to.MessageGetSourceLine = GetSourceLine; |
| 1062 to.StackOverflowBoilerplate = StackOverflowBoilerplate; | 1034 to.StackOverflowBoilerplate = StackOverflowBoilerplate; |
| 1063 }); | 1035 }); |
| 1064 | 1036 |
| 1065 }); | 1037 }); |
| OLD | NEW |