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)); | |
Yang
2016/05/03 18:59:07
I don't think we need to do the TO_UINT32 conversi
Clemens Hammacher
2016/05/04 09:06:20
I though this is more for expressing the intent. I
Yang
2016/05/04 12:04:27
I see. Alright. Can you add a comment so that peop
| |
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); | |
Yang
2016/05/03 18:59:07
This is the same weirdness where we store a string
Clemens Hammacher
2016/05/04 09:06:20
This is done only for testing, where we don't alwa
Yang
2016/05/04 12:04:27
I'm just not really happy with the fact that we ar
| |
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 |
632 function CallSiteGetFileName() { | 647 function CallSiteGetFileName() { |
633 CheckCallSite(this, "getFileName"); | 648 CheckCallSite(this, "getFileName"); |
634 return %CallSiteGetFileNameRT(this); | 649 return %CallSiteGetFileNameRT(this); |
635 } | 650 } |
636 | 651 |
637 function CallSiteGetLineNumber() { | 652 function CallSiteGetLineNumber() { |
653 if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) { | |
654 return GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol); | |
655 } | |
638 CheckCallSite(this, "getLineNumber"); | 656 CheckCallSite(this, "getLineNumber"); |
639 return %CallSiteGetLineNumberRT(this); | 657 return %CallSiteGetLineNumberRT(this); |
640 } | 658 } |
641 | 659 |
642 function CallSiteGetColumnNumber() { | 660 function CallSiteGetColumnNumber() { |
643 CheckCallSite(this, "getColumnNumber"); | 661 CheckCallSite(this, "getColumnNumber"); |
644 return %CallSiteGetColumnNumberRT(this); | 662 return %CallSiteGetColumnNumberRT(this); |
645 } | 663 } |
646 | 664 |
647 function CallSiteIsNative() { | 665 function CallSiteIsNative() { |
648 CheckCallSite(this, "isNative"); | 666 CheckCallSite(this, "isNative"); |
649 return %CallSiteIsNativeRT(this); | 667 return %CallSiteIsNativeRT(this); |
650 } | 668 } |
651 | 669 |
652 function CallSiteIsConstructor() { | 670 function CallSiteIsConstructor() { |
653 CheckCallSite(this, "isConstructor"); | 671 CheckCallSite(this, "isConstructor"); |
654 return %CallSiteIsConstructorRT(this); | 672 return %CallSiteIsConstructorRT(this); |
655 } | 673 } |
656 | 674 |
657 function CallSiteToString() { | 675 function CallSiteToString() { |
676 if (HAS_PRIVATE(this, callSiteWasmObjectSymbol)) { | |
677 var funName = this.getFunctionName(); | |
678 var funcIndex = GET_PRIVATE(this, callSiteWasmFunctionIndexSymbol); | |
679 var pos = this.getPosition(); | |
680 return funName + " (<WASM>:" + funcIndex + ":" + pos + ")"; | |
681 } | |
682 | |
658 var fileName; | 683 var fileName; |
659 var fileLocation = ""; | 684 var fileLocation = ""; |
660 if (this.isNative()) { | 685 if (this.isNative()) { |
661 fileLocation = "native"; | 686 fileLocation = "native"; |
662 } else { | 687 } else { |
663 fileName = this.getScriptNameOrSourceURL(); | 688 fileName = this.getScriptNameOrSourceURL(); |
664 if (!fileName && this.isEval()) { | 689 if (!fileName && this.isEval()) { |
665 fileLocation = this.getEvalOrigin(); | 690 fileLocation = this.getEvalOrigin(); |
666 fileLocation += ", "; // Expecting source position to follow. | 691 fileLocation += ", "; // Expecting source position to follow. |
667 } | 692 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 | 817 |
793 | 818 |
794 function GetStackFrames(raw_stack) { | 819 function GetStackFrames(raw_stack) { |
795 var frames = new InternalArray(); | 820 var frames = new InternalArray(); |
796 var sloppy_frames = raw_stack[0]; | 821 var sloppy_frames = raw_stack[0]; |
797 for (var i = 1; i < raw_stack.length; i += 4) { | 822 for (var i = 1; i < raw_stack.length; i += 4) { |
798 var recv = raw_stack[i]; | 823 var recv = raw_stack[i]; |
799 var fun = raw_stack[i + 1]; | 824 var fun = raw_stack[i + 1]; |
800 var code = raw_stack[i + 2]; | 825 var code = raw_stack[i + 2]; |
801 var pc = raw_stack[i + 3]; | 826 var pc = raw_stack[i + 3]; |
802 var pos = %_IsSmi(code) ? code : %FunctionGetPositionForOffset(code, pc); | 827 var pos = %FunctionGetPositionForOffset(code, pc); |
803 sloppy_frames--; | 828 sloppy_frames--; |
804 frames.push(new CallSite(recv, fun, pos, (sloppy_frames < 0))); | 829 frames.push(new CallSite(recv, fun, pos, (sloppy_frames < 0))); |
805 } | 830 } |
806 return frames; | 831 return frames; |
807 } | 832 } |
808 | 833 |
809 | 834 |
810 // Flag to prevent recursive call of Error.prepareStackTrace. | 835 // Flag to prevent recursive call of Error.prepareStackTrace. |
811 var formatting_custom_stack_trace = false; | 836 var formatting_custom_stack_trace = false; |
812 | 837 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1015 utils.Export(function(to) { | 1040 utils.Export(function(to) { |
1016 to.ErrorToString = ErrorToString; | 1041 to.ErrorToString = ErrorToString; |
1017 to.MakeError = MakeError; | 1042 to.MakeError = MakeError; |
1018 to.MakeRangeError = MakeRangeError; | 1043 to.MakeRangeError = MakeRangeError; |
1019 to.MakeSyntaxError = MakeSyntaxError; | 1044 to.MakeSyntaxError = MakeSyntaxError; |
1020 to.MakeTypeError = MakeTypeError; | 1045 to.MakeTypeError = MakeTypeError; |
1021 to.MakeURIError = MakeURIError; | 1046 to.MakeURIError = MakeURIError; |
1022 }); | 1047 }); |
1023 | 1048 |
1024 }); | 1049 }); |
OLD | NEW |