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