| 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 (function(global, utils) { | 7 (function(global, utils) { |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 // ------------------------------------------------------------------- | 11 // ------------------------------------------------------------------- |
| 12 // Imports | 12 // Imports |
| 13 | 13 |
| 14 var ArrayJoin; | 14 var ArrayJoin; |
| 15 var Bool16x8ToString; | 15 var Bool16x8ToString; |
| 16 var Bool32x4ToString; | 16 var Bool32x4ToString; |
| 17 var Bool8x16ToString; | 17 var Bool8x16ToString; |
| 18 var callSiteReceiverSymbol = | 18 var callSiteReceiverSymbol = |
| 19 utils.ImportNow("call_site_receiver_symbol"); | 19 utils.ImportNow("call_site_receiver_symbol"); |
| 20 var callSiteFunctionSymbol = | 20 var callSiteFunctionSymbol = |
| 21 utils.ImportNow("call_site_function_symbol"); | 21 utils.ImportNow("call_site_function_symbol"); |
| 22 var callSitePositionSymbol = | 22 var callSitePositionSymbol = |
| 23 utils.ImportNow("call_site_position_symbol"); | 23 utils.ImportNow("call_site_position_symbol"); |
| 24 var callSiteStrictSymbol = | 24 var callSiteStrictSymbol = |
| 25 utils.ImportNow("call_site_strict_symbol"); | 25 utils.ImportNow("call_site_strict_symbol"); |
| 26 var callSiteWasmObjectSymbol = |
| 27 utils.ImportNow("call_site_wasm_obj_symbol"); |
| 28 var callSiteWasmFunctionIndexSymbol = |
| 29 utils.ImportNow("call_site_wasm_func_index_symbol"); |
| 26 var Float32x4ToString; | 30 var Float32x4ToString; |
| 27 var formattedStackTraceSymbol = | 31 var formattedStackTraceSymbol = |
| 28 utils.ImportNow("formatted_stack_trace_symbol"); | 32 utils.ImportNow("formatted_stack_trace_symbol"); |
| 29 var GlobalObject = global.Object; | 33 var GlobalObject = global.Object; |
| 30 var Int16x8ToString; | 34 var Int16x8ToString; |
| 31 var Int32x4ToString; | 35 var Int32x4ToString; |
| 32 var Int8x16ToString; | 36 var Int8x16ToString; |
| 33 var InternalArray = utils.InternalArray; | 37 var InternalArray = utils.InternalArray; |
| 34 var internalErrorSymbol = utils.ImportNow("internal_error_symbol"); | 38 var internalErrorSymbol = utils.ImportNow("internal_error_symbol"); |
| 35 var ObjectDefineProperty; | 39 var ObjectDefineProperty; |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 552 |
| 549 | 553 |
| 550 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 554 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
| 551 return new CallSite(recv, fun, pos, false).toString(); | 555 return new CallSite(recv, fun, pos, false).toString(); |
| 552 } | 556 } |
| 553 | 557 |
| 554 // ---------------------------------------------------------------------------- | 558 // ---------------------------------------------------------------------------- |
| 555 // Error implementation | 559 // Error implementation |
| 556 | 560 |
| 557 function CallSite(receiver, fun, pos, strict_mode) { | 561 function CallSite(receiver, fun, pos, strict_mode) { |
| 558 if (!IS_FUNCTION(fun)) { | 562 if (!IS_FUNCTION(fun) && !IS_NUMBER(fun)) { |
| 559 throw MakeTypeError(kCallSiteExpectsFunction, typeof fun); | 563 throw MakeTypeError(kCallSiteExpectsFunction, typeof fun); |
| 560 } | 564 } |
| 561 | 565 |
| 562 if (IS_UNDEFINED(new.target)) { | 566 if (IS_UNDEFINED(new.target)) { |
| 563 return new CallSite(receiver, fun, pos, strict_mode); | 567 return new CallSite(receiver, fun, pos, strict_mode); |
| 564 } | 568 } |
| 565 | 569 |
| 566 SET_PRIVATE(this, callSiteReceiverSymbol, receiver); | 570 if (IS_FUNCTION(fun)) { |
| 567 SET_PRIVATE(this, callSiteFunctionSymbol, fun); | 571 SET_PRIVATE(this, callSiteReceiverSymbol, receiver); |
| 572 SET_PRIVATE(this, callSiteFunctionSymbol, fun); |
| 573 } else { |
| 574 SET_PRIVATE(this, callSiteWasmObjectSymbol, receiver); |
| 575 SET_PRIVATE(this, callSiteWasmFunctionIndexSymbol, TO_UINT32(fun)); |
| 576 } |
| 568 SET_PRIVATE(this, callSitePositionSymbol, TO_INT32(pos)); | 577 SET_PRIVATE(this, callSitePositionSymbol, TO_INT32(pos)); |
| 569 SET_PRIVATE(this, callSiteStrictSymbol, TO_BOOLEAN(strict_mode)); | 578 SET_PRIVATE(this, callSiteStrictSymbol, TO_BOOLEAN(strict_mode)); |
| 570 } | 579 } |
| 571 | 580 |
| 572 function CheckCallSite(obj, name) { | 581 function CheckCallSite(obj, name) { |
| 573 if (!IS_RECEIVER(obj) || !HAS_PRIVATE(obj, callSiteFunctionSymbol)) { | 582 if (!IS_RECEIVER(obj) || !HAS_PRIVATE(obj, callSitePositionSymbol)) { |
| 574 throw MakeTypeError(kCallSiteMethod, name); | 583 throw MakeTypeError(kCallSiteMethod, name); |
| 575 } | 584 } |
| 576 } | 585 } |
| 577 | 586 |
| 578 function CallSiteGetThis() { | 587 function CallSiteGetThis() { |
| 579 CheckCallSite(this, "getThis"); | 588 CheckCallSite(this, "getThis"); |
| 580 return GET_PRIVATE(this, callSiteStrictSymbol) | 589 return GET_PRIVATE(this, callSiteStrictSymbol) |
| 581 ? UNDEFINED : GET_PRIVATE(this, callSiteReceiverSymbol); | 590 ? UNDEFINED : GET_PRIVATE(this, callSiteReceiverSymbol); |
| 582 } | 591 } |
| 583 | 592 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 614 } | 623 } |
| 615 | 624 |
| 616 function CallSiteGetScriptNameOrSourceURL() { | 625 function CallSiteGetScriptNameOrSourceURL() { |
| 617 CheckCallSite(this, "getScriptNameOrSourceURL"); | 626 CheckCallSite(this, "getScriptNameOrSourceURL"); |
| 618 return %CallSiteGetScriptNameOrSourceUrlRT(this); | 627 return %CallSiteGetScriptNameOrSourceUrlRT(this); |
| 619 } | 628 } |
| 620 | 629 |
| 621 function CallSiteGetFunctionName() { | 630 function CallSiteGetFunctionName() { |
| 622 // See if the function knows its own name | 631 // See if the function knows its own name |
| 623 CheckCallSite(this, "getFunctionName"); | 632 CheckCallSite(this, "getFunctionName"); |
| 633 if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) { |
| 634 var wasm = GET_PRIVATE(this, callSiteWasmObjectSymbol); |
| 635 var func_index = GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol); |
| 636 return IS_UNDEFINED(wasm) ? "<WASM>" : |
| 637 IS_STRING(wasm) ? wasm : %WasmGetFunctionName(wasm, func_index); |
| 638 } |
| 624 return %CallSiteGetFunctionNameRT(this); | 639 return %CallSiteGetFunctionNameRT(this); |
| 625 } | 640 } |
| 626 | 641 |
| 627 function CallSiteGetMethodName() { | 642 function CallSiteGetMethodName() { |
| 628 // See if we can find a unique property on the receiver that holds | 643 // See if we can find a unique property on the receiver that holds |
| 629 // this function. | 644 // this function. |
| 630 CheckCallSite(this, "getMethodName"); | 645 CheckCallSite(this, "getMethodName"); |
| 631 return %CallSiteGetMethodNameRT(this); | 646 return %CallSiteGetMethodNameRT(this); |
| 632 } | 647 } |
| 633 | 648 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 649 function CallSiteIsNative() { | 664 function CallSiteIsNative() { |
| 650 CheckCallSite(this, "isNative"); | 665 CheckCallSite(this, "isNative"); |
| 651 return %CallSiteIsNativeRT(this); | 666 return %CallSiteIsNativeRT(this); |
| 652 } | 667 } |
| 653 | 668 |
| 654 function CallSiteIsConstructor() { | 669 function CallSiteIsConstructor() { |
| 655 CheckCallSite(this, "isConstructor"); | 670 CheckCallSite(this, "isConstructor"); |
| 656 return %CallSiteIsConstructorRT(this); | 671 return %CallSiteIsConstructorRT(this); |
| 657 } | 672 } |
| 658 | 673 |
| 674 function CallSiteIsWasm() { |
| 675 CheckCallSite(this, "isWasm"); |
| 676 return HAS_PRIVATE(this, callSiteWasmObjectSymbol); |
| 677 } |
| 678 |
| 679 function CallSiteGetWasmObject() { |
| 680 CheckCallSite(this, "getWasmObject"); |
| 681 return GET_PRIVATE(this, callSiteWasmObjectSymbol); |
| 682 } |
| 683 |
| 684 function CallSiteGetWasmFunctionIndex() { |
| 685 CheckCallSite(this, "getWasmFunctionIndex"); |
| 686 return GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol); |
| 687 } |
| 688 |
| 659 function CallSiteToString() { | 689 function CallSiteToString() { |
| 690 if (this.isWasm()) { |
| 691 return this.getFunctionName() + " (<WASM>:" + this.getPosition() + ")"; |
| 692 } |
| 693 |
| 660 var fileName; | 694 var fileName; |
| 661 var fileLocation = ""; | 695 var fileLocation = ""; |
| 662 if (this.isNative()) { | 696 if (this.isNative()) { |
| 663 fileLocation = "native"; | 697 fileLocation = "native"; |
| 664 } else { | 698 } else { |
| 665 fileName = this.getScriptNameOrSourceURL(); | 699 fileName = this.getScriptNameOrSourceURL(); |
| 666 if (!fileName && this.isEval()) { | 700 if (!fileName && this.isEval()) { |
| 667 fileLocation = this.getEvalOrigin(); | 701 fileLocation = this.getEvalOrigin(); |
| 668 fileLocation += ", "; // Expecting source position to follow. | 702 fileLocation += ", "; // Expecting source position to follow. |
| 669 } | 703 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, | 764 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, |
| 731 "getFunction", CallSiteGetFunction, | 765 "getFunction", CallSiteGetFunction, |
| 732 "getFunctionName", CallSiteGetFunctionName, | 766 "getFunctionName", CallSiteGetFunctionName, |
| 733 "getMethodName", CallSiteGetMethodName, | 767 "getMethodName", CallSiteGetMethodName, |
| 734 "getFileName", CallSiteGetFileName, | 768 "getFileName", CallSiteGetFileName, |
| 735 "getLineNumber", CallSiteGetLineNumber, | 769 "getLineNumber", CallSiteGetLineNumber, |
| 736 "getColumnNumber", CallSiteGetColumnNumber, | 770 "getColumnNumber", CallSiteGetColumnNumber, |
| 737 "isNative", CallSiteIsNative, | 771 "isNative", CallSiteIsNative, |
| 738 "getPosition", CallSiteGetPosition, | 772 "getPosition", CallSiteGetPosition, |
| 739 "isConstructor", CallSiteIsConstructor, | 773 "isConstructor", CallSiteIsConstructor, |
| 774 "isWasm", CallSiteIsWasm, |
| 775 "getWasmObject", CallSiteGetWasmObject, |
| 776 "getWasmFunctionIndex", CallSiteGetWasmFunctionIndex, |
| 740 "toString", CallSiteToString | 777 "toString", CallSiteToString |
| 741 ]); | 778 ]); |
| 742 | 779 |
| 743 | 780 |
| 744 function FormatEvalOrigin(script) { | 781 function FormatEvalOrigin(script) { |
| 745 var sourceURL = script.nameOrSourceURL(); | 782 var sourceURL = script.nameOrSourceURL(); |
| 746 if (sourceURL) { | 783 if (sourceURL) { |
| 747 return sourceURL; | 784 return sourceURL; |
| 748 } | 785 } |
| 749 | 786 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 831 |
| 795 | 832 |
| 796 function GetStackFrames(raw_stack) { | 833 function GetStackFrames(raw_stack) { |
| 797 var frames = new InternalArray(); | 834 var frames = new InternalArray(); |
| 798 var sloppy_frames = raw_stack[0]; | 835 var sloppy_frames = raw_stack[0]; |
| 799 for (var i = 1; i < raw_stack.length; i += 4) { | 836 for (var i = 1; i < raw_stack.length; i += 4) { |
| 800 var recv = raw_stack[i]; | 837 var recv = raw_stack[i]; |
| 801 var fun = raw_stack[i + 1]; | 838 var fun = raw_stack[i + 1]; |
| 802 var code = raw_stack[i + 2]; | 839 var code = raw_stack[i + 2]; |
| 803 var pc = raw_stack[i + 3]; | 840 var pc = raw_stack[i + 3]; |
| 804 var pos = %_IsSmi(code) ? code : %FunctionGetPositionForOffset(code, pc); | 841 var pos = %FunctionGetPositionForOffset(code, pc); |
| 805 sloppy_frames--; | 842 sloppy_frames--; |
| 806 frames.push(new CallSite(recv, fun, pos, (sloppy_frames < 0))); | 843 frames.push(new CallSite(recv, fun, pos, (sloppy_frames < 0))); |
| 807 } | 844 } |
| 808 return frames; | 845 return frames; |
| 809 } | 846 } |
| 810 | 847 |
| 811 | 848 |
| 812 // Flag to prevent recursive call of Error.prepareStackTrace. | 849 // Flag to prevent recursive call of Error.prepareStackTrace. |
| 813 var formatting_custom_stack_trace = false; | 850 var formatting_custom_stack_trace = false; |
| 814 | 851 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 utils.Export(function(to) { | 1054 utils.Export(function(to) { |
| 1018 to.ErrorToString = ErrorToString; | 1055 to.ErrorToString = ErrorToString; |
| 1019 to.MakeError = MakeError; | 1056 to.MakeError = MakeError; |
| 1020 to.MakeRangeError = MakeRangeError; | 1057 to.MakeRangeError = MakeRangeError; |
| 1021 to.MakeSyntaxError = MakeSyntaxError; | 1058 to.MakeSyntaxError = MakeSyntaxError; |
| 1022 to.MakeTypeError = MakeTypeError; | 1059 to.MakeTypeError = MakeTypeError; |
| 1023 to.MakeURIError = MakeURIError; | 1060 to.MakeURIError = MakeURIError; |
| 1024 }); | 1061 }); |
| 1025 | 1062 |
| 1026 }); | 1063 }); |
| OLD | NEW |