Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: src/messages.js

Issue 7694029: Merge r8979 to 3.3 branch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/3.3
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/string.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 var kReplacementMarkers = [ "%0", "%1", "%2", "%3" ]; 51 var kReplacementMarkers = [ "%0", "%1", "%2", "%3" ];
52 52
53 function FormatString(format, message) { 53 function FormatString(format, message) {
54 var args = %MessageGetArguments(message); 54 var args = %MessageGetArguments(message);
55 var result = ""; 55 var result = "";
56 var arg_num = 0; 56 var arg_num = 0;
57 for (var i = 0; i < format.length; i++) { 57 for (var i = 0; i < format.length; i++) {
58 var str = format[i]; 58 var str = format[i];
59 for (arg_num = 0; arg_num < kReplacementMarkers.length; arg_num++) { 59 for (arg_num = 0; arg_num < kReplacementMarkers.length; arg_num++) {
60 if (format[i] !== kReplacementMarkers[arg_num]) continue; 60 if (str !== kReplacementMarkers[arg_num]) continue;
61 try { 61 try {
62 str = ToDetailString(args[arg_num]); 62 str = ToDetailString(args[arg_num]);
63 } catch (e) { 63 } catch (e) {
64 str = "#<error>"; 64 str = "#<error>";
65 } 65 }
66 } 66 }
67 result += str; 67 result += str;
68 } 68 }
69 return result; 69 return result;
70 } 70 }
(...skipping 22 matching lines...) Expand all
93 function ToStringCheckErrorObject(obj) { 93 function ToStringCheckErrorObject(obj) {
94 if (IsNativeErrorObject(obj)) { 94 if (IsNativeErrorObject(obj)) {
95 return %_CallFunction(obj, errorToString); 95 return %_CallFunction(obj, errorToString);
96 } else { 96 } else {
97 return ToString(obj); 97 return ToString(obj);
98 } 98 }
99 } 99 }
100 100
101 101
102 function ToDetailString(obj) { 102 function ToDetailString(obj) {
103 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri ng) { 103 if (obj != null && IS_OBJECT(obj) &&
104 obj.toString === $Object.prototype.toString) {
104 var constructor = obj.constructor; 105 var constructor = obj.constructor;
105 if (!constructor) return ToStringCheckErrorObject(obj); 106 if (!constructor) return ToStringCheckErrorObject(obj);
106 var constructorName = constructor.name; 107 var constructorName = constructor.name;
107 if (!constructorName || !IS_STRING(constructorName)) { 108 if (!constructorName || !IS_STRING(constructorName)) {
108 return ToStringCheckErrorObject(obj); 109 return ToStringCheckErrorObject(obj);
109 } 110 }
110 return "#<" + constructorName + ">"; 111 return "#<" + constructorName + ">";
111 } else { 112 } else {
112 return ToStringCheckErrorObject(obj); 113 return ToStringCheckErrorObject(obj);
113 } 114 }
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 */ 544 */
544 function SourceLocation(script, position, line, column, start, end) { 545 function SourceLocation(script, position, line, column, start, end) {
545 this.script = script; 546 this.script = script;
546 this.position = position; 547 this.position = position;
547 this.line = line; 548 this.line = line;
548 this.column = column; 549 this.column = column;
549 this.start = start; 550 this.start = start;
550 this.end = end; 551 this.end = end;
551 } 552 }
552 553
554 SourceLocation.prototype.__proto__ = null;
553 555
554 const kLineLengthLimit = 78; 556 const kLineLengthLimit = 78;
555 557
556 /** 558 /**
557 * Restrict source location start and end positions to make the source slice 559 * Restrict source location start and end positions to make the source slice
558 * no more that a certain number of characters wide. 560 * no more that a certain number of characters wide.
559 * @param {number} opt_limit The with limit of the source text with a default 561 * @param {number} opt_limit The with limit of the source text with a default
560 * of 78 562 * of 78
561 * @param {number} opt_before The number of characters to prefer before the 563 * @param {number} opt_before The number of characters to prefer before the
562 * position with a default value of 10 less that the limit 564 * position with a default value of 10 less that the limit
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 * @constructor 634 * @constructor
633 */ 635 */
634 function SourceSlice(script, from_line, to_line, from_position, to_position) { 636 function SourceSlice(script, from_line, to_line, from_position, to_position) {
635 this.script = script; 637 this.script = script;
636 this.from_line = from_line; 638 this.from_line = from_line;
637 this.to_line = to_line; 639 this.to_line = to_line;
638 this.from_position = from_position; 640 this.from_position = from_position;
639 this.to_position = to_position; 641 this.to_position = to_position;
640 } 642 }
641 643
644 SourceSlice.prototype.__proto__ = null;
642 645
643 /** 646 /**
644 * Get the source text for a SourceSlice 647 * Get the source text for a SourceSlice
645 * @return {String} Source text for this slice. The last line will include 648 * @return {String} Source text for this slice. The last line will include
646 * the line terminating characters (if any) 649 * the line terminating characters (if any)
647 */ 650 */
648 SourceSlice.prototype.sourceText = function () { 651 SourceSlice.prototype.sourceText = function () {
649 return %_CallFunction(this.script.source, 652 return %_CallFunction(this.script.source,
650 this.from_position, 653 this.from_position,
651 this.to_position, 654 this.to_position,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 value = v; 696 value = v;
694 }); 697 });
695 } 698 }
696 699
697 function CallSite(receiver, fun, pos) { 700 function CallSite(receiver, fun, pos) {
698 this.receiver = receiver; 701 this.receiver = receiver;
699 this.fun = fun; 702 this.fun = fun;
700 this.pos = pos; 703 this.pos = pos;
701 } 704 }
702 705
706 CallSite.prototype.__proto__ = null;
707
703 CallSite.prototype.getThis = function () { 708 CallSite.prototype.getThis = function () {
704 return this.receiver; 709 return this.receiver;
705 }; 710 };
706 711
707 CallSite.prototype.getTypeName = function () { 712 CallSite.prototype.getTypeName = function () {
708 var constructor = this.receiver.constructor; 713 var constructor = this.receiver.constructor;
709 if (!constructor) 714 if (!constructor) {
710 return %_CallFunction(this.receiver, ObjectToString); 715 return %_CallFunction(this.receiver, ObjectToString);
716 }
711 var constructorName = constructor.name; 717 var constructorName = constructor.name;
712 if (!constructorName) 718 if (!constructorName) {
713 return %_CallFunction(this.receiver, ObjectToString); 719 return %_CallFunction(this.receiver, ObjectToString);
720 }
714 return constructorName; 721 return constructorName;
715 }; 722 };
716 723
717 CallSite.prototype.isToplevel = function () { 724 CallSite.prototype.isToplevel = function () {
718 if (this.receiver == null) 725 if (this.receiver == null) {
719 return true; 726 return true;
727 }
720 return IS_GLOBAL(this.receiver); 728 return IS_GLOBAL(this.receiver);
721 }; 729 };
722 730
723 CallSite.prototype.isEval = function () { 731 CallSite.prototype.isEval = function () {
724 var script = %FunctionGetScript(this.fun); 732 var script = %FunctionGetScript(this.fun);
725 return script && script.compilation_type == COMPILATION_TYPE_EVAL; 733 return script && script.compilation_type == COMPILATION_TYPE_EVAL;
726 }; 734 };
727 735
728 CallSite.prototype.getEvalOrigin = function () { 736 CallSite.prototype.getEvalOrigin = function () {
729 var script = %FunctionGetScript(this.fun); 737 var script = %FunctionGetScript(this.fun);
(...skipping 12 matching lines...) Expand all
742 CallSite.prototype.getFunctionName = function () { 750 CallSite.prototype.getFunctionName = function () {
743 // See if the function knows its own name 751 // See if the function knows its own name
744 var name = this.fun.name; 752 var name = this.fun.name;
745 if (name) { 753 if (name) {
746 return name; 754 return name;
747 } else { 755 } else {
748 return %FunctionGetInferredName(this.fun); 756 return %FunctionGetInferredName(this.fun);
749 } 757 }
750 // Maybe this is an evaluation? 758 // Maybe this is an evaluation?
751 var script = %FunctionGetScript(this.fun); 759 var script = %FunctionGetScript(this.fun);
752 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) 760 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) {
753 return "eval"; 761 return "eval";
762 }
754 return null; 763 return null;
755 }; 764 };
756 765
757 CallSite.prototype.getMethodName = function () { 766 CallSite.prototype.getMethodName = function () {
758 // See if we can find a unique property on the receiver that holds 767 // See if we can find a unique property on the receiver that holds
759 // this function. 768 // this function.
760 var ownName = this.fun.name; 769 var ownName = this.fun.name;
761 if (ownName && this.receiver && 770 if (ownName && this.receiver &&
762 (%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun | | 771 (%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun | |
763 %_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun | | 772 %_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun | |
764 this.receiver[ownName] === this.fun)) { 773 this.receiver[ownName] === this.fun)) {
765 // To handle DontEnum properties we guess that the method has 774 // To handle DontEnum properties we guess that the method has
766 // the same name as the function. 775 // the same name as the function.
767 return ownName; 776 return ownName;
768 } 777 }
769 var name = null; 778 var name = null;
770 for (var prop in this.receiver) { 779 for (var prop in this.receiver) {
771 if (this.receiver.__lookupGetter__(prop) === this.fun || 780 if (this.receiver.__lookupGetter__(prop) === this.fun ||
772 this.receiver.__lookupSetter__(prop) === this.fun || 781 this.receiver.__lookupSetter__(prop) === this.fun ||
773 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f un)) { 782 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f un)) {
774 // If we find more than one match bail out to avoid confusion. 783 // If we find more than one match bail out to avoid confusion.
775 if (name) 784 if (name) {
776 return null; 785 return null;
786 }
777 name = prop; 787 name = prop;
778 } 788 }
779 } 789 }
780 if (name) 790 if (name) {
781 return name; 791 return name;
792 }
782 return null; 793 return null;
783 }; 794 };
784 795
785 CallSite.prototype.getFileName = function () { 796 CallSite.prototype.getFileName = function () {
786 var script = %FunctionGetScript(this.fun); 797 var script = %FunctionGetScript(this.fun);
787 return script ? script.name : null; 798 return script ? script.name : null;
788 }; 799 };
789 800
790 CallSite.prototype.getLineNumber = function () { 801 CallSite.prototype.getLineNumber = function () {
791 if (this.pos == -1) 802 if (this.pos == -1) {
792 return null; 803 return null;
804 }
793 var script = %FunctionGetScript(this.fun); 805 var script = %FunctionGetScript(this.fun);
794 var location = null; 806 var location = null;
795 if (script) { 807 if (script) {
796 location = script.locationFromPosition(this.pos, true); 808 location = script.locationFromPosition(this.pos, true);
797 } 809 }
798 return location ? location.line + 1 : null; 810 return location ? location.line + 1 : null;
799 }; 811 };
800 812
801 CallSite.prototype.getColumnNumber = function () { 813 CallSite.prototype.getColumnNumber = function () {
802 if (this.pos == -1) 814 if (this.pos == -1) {
803 return null; 815 return null;
816 }
804 var script = %FunctionGetScript(this.fun); 817 var script = %FunctionGetScript(this.fun);
805 var location = null; 818 var location = null;
806 if (script) { 819 if (script) {
807 location = script.locationFromPosition(this.pos, true); 820 location = script.locationFromPosition(this.pos, true);
808 } 821 }
809 return location ? location.column + 1: null; 822 return location ? location.column + 1: null;
810 }; 823 };
811 824
812 CallSite.prototype.isNative = function () { 825 CallSite.prototype.isNative = function () {
813 var script = %FunctionGetScript(this.fun); 826 var script = %FunctionGetScript(this.fun);
814 return script ? (script.type == TYPE_NATIVE) : false; 827 return script ? (script.type == TYPE_NATIVE) : false;
815 }; 828 };
816 829
817 CallSite.prototype.getPosition = function () { 830 CallSite.prototype.getPosition = function () {
818 return this.pos; 831 return this.pos;
819 }; 832 };
820 833
821 CallSite.prototype.isConstructor = function () { 834 CallSite.prototype.isConstructor = function () {
822 var constructor = this.receiver ? this.receiver.constructor : null; 835 var constructor = this.receiver ? this.receiver.constructor : null;
823 if (!constructor) 836 if (!constructor) {
824 return false; 837 return false;
838 }
825 return this.fun === constructor; 839 return this.fun === constructor;
826 }; 840 };
827 841
828 function FormatEvalOrigin(script) { 842 function FormatEvalOrigin(script) {
829 var sourceURL = script.nameOrSourceURL(); 843 var sourceURL = script.nameOrSourceURL();
830 if (sourceURL) 844 if (sourceURL) {
831 return sourceURL; 845 return sourceURL;
846 }
832 847
833 var eval_origin = "eval at "; 848 var eval_origin = "eval at ";
834 if (script.eval_from_function_name) { 849 if (script.eval_from_function_name) {
835 eval_origin += script.eval_from_function_name; 850 eval_origin += script.eval_from_function_name;
836 } else { 851 } else {
837 eval_origin += "<anonymous>"; 852 eval_origin += "<anonymous>";
838 } 853 }
839 854
840 var eval_from_script = script.eval_from_script; 855 var eval_from_script = script.eval_from_script;
841 if (eval_from_script) { 856 if (eval_from_script) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 captureStackTrace(this, f); 1031 captureStackTrace(this, f);
1017 } else { 1032 } else {
1018 return new f(m); 1033 return new f(m);
1019 } 1034 }
1020 }); 1035 });
1021 } 1036 }
1022 1037
1023 function captureStackTrace(obj, cons_opt) { 1038 function captureStackTrace(obj, cons_opt) {
1024 var stackTraceLimit = $Error.stackTraceLimit; 1039 var stackTraceLimit = $Error.stackTraceLimit;
1025 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; 1040 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return;
1026 if (stackTraceLimit < 0 || stackTraceLimit > 10000) 1041 if (stackTraceLimit < 0 || stackTraceLimit > 10000) {
1027 stackTraceLimit = 10000; 1042 stackTraceLimit = 10000;
1043 }
1028 var raw_stack = %CollectStackTrace(cons_opt 1044 var raw_stack = %CollectStackTrace(cons_opt
1029 ? cons_opt 1045 ? cons_opt
1030 : captureStackTrace, stackTraceLimit); 1046 : captureStackTrace, stackTraceLimit);
1031 DefineOneShotAccessor(obj, 'stack', function (obj) { 1047 DefineOneShotAccessor(obj, 'stack', function (obj) {
1032 return FormatRawStackTrace(obj, raw_stack); 1048 return FormatRawStackTrace(obj, raw_stack);
1033 }); 1049 });
1034 }; 1050 };
1035 1051
1036 $Math.__proto__ = global.Object.prototype; 1052 $Math.__proto__ = global.Object.prototype;
1037 1053
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 } 1093 }
1078 // This helper function is needed because access to properties on 1094 // This helper function is needed because access to properties on
1079 // the builtins object do not work inside of a catch clause. 1095 // the builtins object do not work inside of a catch clause.
1080 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } 1096 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; }
1081 1097
1082 try { 1098 try {
1083 return %_CallFunction(this, errorToStringDetectCycle); 1099 return %_CallFunction(this, errorToStringDetectCycle);
1084 } catch(e) { 1100 } catch(e) {
1085 // If this error message was encountered already return the empty 1101 // If this error message was encountered already return the empty
1086 // string for it instead of recursively formatting it. 1102 // string for it instead of recursively formatting it.
1087 if (isCyclicErrorMarker(e)) return ''; 1103 if (isCyclicErrorMarker(e)) {
1088 else throw e; 1104 return '';
1105 }
1106 throw e;
1089 } 1107 }
1090 } 1108 }
1091 1109
1092 1110
1093 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); 1111 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]);
1094 1112
1095 // Boilerplate for exceptions for stack overflows. Used from 1113 // Boilerplate for exceptions for stack overflows. Used from
1096 // Isolate::StackOverflow(). 1114 // Isolate::StackOverflow().
1097 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1115 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« no previous file with comments | « no previous file | src/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698