OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 | 28 |
29 // ------------------------------------------------------------------- | 29 // ------------------------------------------------------------------- |
30 | 30 |
31 const kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true}; | 31 // Lazily initialized. |
32 const kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, | 32 var kVowelSounds = 0; |
33 h: true, f: true, l: true, m: true, n: true, r: true, s: true, x: true, | 33 var kCapitalVowelSounds = 0; |
34 y: true}; | 34 |
35 | 35 |
36 function GetInstanceName(cons) { | 36 function GetInstanceName(cons) { |
37 if (cons.length == 0) { | 37 if (cons.length == 0) { |
38 return ""; | 38 return ""; |
39 } | 39 } |
40 var first = %StringToLowerCase(StringCharAt.call(cons, 0)); | 40 var first = %StringToLowerCase(StringCharAt.call(cons, 0)); |
41 var mapping = kVowelSounds; | 41 if (kVowelSounds === 0) { |
| 42 kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true}; |
| 43 kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, h: true, |
| 44 f: true, l: true, m: true, n: true, r: true, s: true, x: true, y: true}; |
| 45 } |
| 46 var vowel_mapping = kVowelSounds; |
42 if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) { | 47 if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) { |
43 // First char is upper case | 48 // First char is upper case |
44 var second = %StringToLowerCase(StringCharAt.call(cons, 1)); | 49 var second = %StringToLowerCase(StringCharAt.call(cons, 1)); |
45 // Second char is upper case | 50 // Second char is upper case |
46 if (StringCharAt.call(cons, 1) != second) | 51 if (StringCharAt.call(cons, 1) != second) { |
47 mapping = kCapitalVowelSounds; | 52 vowel_mapping = kCapitalVowelSounds; |
| 53 } |
48 } | 54 } |
49 var s = mapping[first] ? "an " : "a "; | 55 var s = vowel_mapping[first] ? "an " : "a "; |
50 return s + cons; | 56 return s + cons; |
51 } | 57 } |
52 | 58 |
53 | 59 |
54 const kMessages = { | 60 var kMessages = 0; |
55 // Error | |
56 cyclic_proto: "Cyclic __proto__ value", | |
57 // TypeError | |
58 unexpected_token: "Unexpected token %0", | |
59 unexpected_token_number: "Unexpected number", | |
60 unexpected_token_string: "Unexpected string", | |
61 unexpected_token_identifier: "Unexpected identifier", | |
62 unexpected_eos: "Unexpected end of input", | |
63 malformed_regexp: "Invalid regular expression: /%0/: %1", | |
64 unterminated_regexp: "Invalid regular expression: missing /", | |
65 regexp_flags: "Cannot supply flags when constructing one RegEx
p from another", | |
66 invalid_lhs_in_assignment: "Invalid left-hand side in assignment", | |
67 invalid_lhs_in_for_in: "Invalid left-hand side in for-in", | |
68 invalid_lhs_in_postfix_op: "Invalid left-hand side expression in postfix op
eration", | |
69 invalid_lhs_in_prefix_op: "Invalid left-hand side expression in prefix ope
ration", | |
70 multiple_defaults_in_switch: "More than one default clause in switch statemen
t", | |
71 newline_after_throw: "Illegal newline after throw", | |
72 redeclaration: "%0 '%1' has already been declared", | |
73 no_catch_or_finally: "Missing catch or finally after try", | |
74 unknown_label: "Undefined label '%0'", | |
75 uncaught_exception: "Uncaught %0", | |
76 stack_trace: "Stack Trace:\n%0", | |
77 called_non_callable: "%0 is not a function", | |
78 undefined_method: "Object %1 has no method '%0'", | |
79 property_not_function: "Property '%0' of object %1 is not a function", | |
80 cannot_convert_to_primitive: "Cannot convert object to primitive value", | |
81 not_constructor: "%0 is not a constructor", | |
82 not_defined: "%0 is not defined", | |
83 non_object_property_load: "Cannot read property '%0' of %1", | |
84 non_object_property_store: "Cannot set property '%0' of %1", | |
85 non_object_property_call: "Cannot call method '%0' of %1", | |
86 with_expression: "%0 has no properties", | |
87 illegal_invocation: "Illegal invocation", | |
88 no_setter_in_callback: "Cannot set property %0 of %1 which has only a g
etter", | |
89 apply_non_function: "Function.prototype.apply was called on %0, whic
h is a %1 and not a function", | |
90 apply_wrong_args: "Function.prototype.apply: Arguments list has wr
ong type", | |
91 invalid_in_operator_use: "Cannot use 'in' operator to search for '%0' in
%1", | |
92 instanceof_function_expected: "Expecting a function in instanceof check, but g
ot %0", | |
93 instanceof_nonobject_proto: "Function has non-object prototype '%0' in insta
nceof check", | |
94 null_to_object: "Cannot convert null to object", | |
95 reduce_no_initial: "Reduce of empty array with no initial value", | |
96 // RangeError | |
97 invalid_array_length: "Invalid array length", | |
98 stack_overflow: "Maximum call stack size exceeded", | |
99 apply_overflow: "Function.prototype.apply cannot support %0 argu
ments", | |
100 // SyntaxError | |
101 unable_to_parse: "Parse error", | |
102 duplicate_regexp_flag: "Duplicate RegExp flag %0", | |
103 invalid_regexp: "Invalid RegExp pattern /%0/", | |
104 illegal_break: "Illegal break statement", | |
105 illegal_continue: "Illegal continue statement", | |
106 illegal_return: "Illegal return statement", | |
107 error_loading_debugger: "Error loading debugger %0", | |
108 no_input_to_regexp: "No input to %0", | |
109 result_not_primitive: "Result of %0 must be a primitive, was %1", | |
110 invalid_json: "String '%0' is not valid JSON", | |
111 circular_structure: "Converting circular structure to JSON" | |
112 }; | |
113 | 61 |
114 | 62 |
115 function FormatString(format, args) { | 63 function FormatString(format, args) { |
116 var result = format; | 64 var result = format; |
117 for (var i = 0; i < args.length; i++) { | 65 for (var i = 0; i < args.length; i++) { |
118 var str; | 66 var str; |
119 try { str = ToDetailString(args[i]); } | 67 try { str = ToDetailString(args[i]); } |
120 catch (e) { str = "#<error>"; } | 68 catch (e) { str = "#<error>"; } |
121 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); | 69 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); |
122 } | 70 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 %FunctionSetInstanceClassName(Script, 'Script'); | 102 %FunctionSetInstanceClassName(Script, 'Script'); |
155 %SetProperty(Script.prototype, 'constructor', Script, DONT_ENUM); | 103 %SetProperty(Script.prototype, 'constructor', Script, DONT_ENUM); |
156 %SetCode(Script, function(x) { | 104 %SetCode(Script, function(x) { |
157 // Script objects can only be created by the VM. | 105 // Script objects can only be created by the VM. |
158 throw new $Error("Not supported"); | 106 throw new $Error("Not supported"); |
159 }); | 107 }); |
160 | 108 |
161 | 109 |
162 // Helper functions; called from the runtime system. | 110 // Helper functions; called from the runtime system. |
163 function FormatMessage(message) { | 111 function FormatMessage(message) { |
| 112 if (kMessages === 0) { |
| 113 kMessages = { |
| 114 // Error |
| 115 cyclic_proto: "Cyclic __proto__ value", |
| 116 // TypeError |
| 117 unexpected_token: "Unexpected token %0", |
| 118 unexpected_token_number: "Unexpected number", |
| 119 unexpected_token_string: "Unexpected string", |
| 120 unexpected_token_identifier: "Unexpected identifier", |
| 121 unexpected_eos: "Unexpected end of input", |
| 122 malformed_regexp: "Invalid regular expression: /%0/: %1", |
| 123 unterminated_regexp: "Invalid regular expression: missing /", |
| 124 regexp_flags: "Cannot supply flags when constructing one R
egExp from another", |
| 125 invalid_lhs_in_assignment: "Invalid left-hand side in assignment", |
| 126 invalid_lhs_in_for_in: "Invalid left-hand side in for-in", |
| 127 invalid_lhs_in_postfix_op: "Invalid left-hand side expression in postfi
x operation", |
| 128 invalid_lhs_in_prefix_op: "Invalid left-hand side expression in prefix
operation", |
| 129 multiple_defaults_in_switch: "More than one default clause in switch stat
ement", |
| 130 newline_after_throw: "Illegal newline after throw", |
| 131 redeclaration: "%0 '%1' has already been declared", |
| 132 no_catch_or_finally: "Missing catch or finally after try", |
| 133 unknown_label: "Undefined label '%0'", |
| 134 uncaught_exception: "Uncaught %0", |
| 135 stack_trace: "Stack Trace:\n%0", |
| 136 called_non_callable: "%0 is not a function", |
| 137 undefined_method: "Object %1 has no method '%0'", |
| 138 property_not_function: "Property '%0' of object %1 is not a functio
n", |
| 139 cannot_convert_to_primitive: "Cannot convert object to primitive value", |
| 140 not_constructor: "%0 is not a constructor", |
| 141 not_defined: "%0 is not defined", |
| 142 non_object_property_load: "Cannot read property '%0' of %1", |
| 143 non_object_property_store: "Cannot set property '%0' of %1", |
| 144 non_object_property_call: "Cannot call method '%0' of %1", |
| 145 with_expression: "%0 has no properties", |
| 146 illegal_invocation: "Illegal invocation", |
| 147 no_setter_in_callback: "Cannot set property %0 of %1 which has only
a getter", |
| 148 apply_non_function: "Function.prototype.apply was called on %0,
which is a %1 and not a function", |
| 149 apply_wrong_args: "Function.prototype.apply: Arguments list ha
s wrong type", |
| 150 invalid_in_operator_use: "Cannot use 'in' operator to search for '%0'
in %1", |
| 151 instanceof_function_expected: "Expecting a function in instanceof check, b
ut got %0", |
| 152 instanceof_nonobject_proto: "Function has non-object prototype '%0' in i
nstanceof check", |
| 153 null_to_object: "Cannot convert null to object", |
| 154 reduce_no_initial: "Reduce of empty array with no initial value
", |
| 155 // RangeError |
| 156 invalid_array_length: "Invalid array length", |
| 157 stack_overflow: "Maximum call stack size exceeded", |
| 158 apply_overflow: "Function.prototype.apply cannot support %0
arguments", |
| 159 // SyntaxError |
| 160 unable_to_parse: "Parse error", |
| 161 duplicate_regexp_flag: "Duplicate RegExp flag %0", |
| 162 invalid_regexp: "Invalid RegExp pattern /%0/", |
| 163 illegal_break: "Illegal break statement", |
| 164 illegal_continue: "Illegal continue statement", |
| 165 illegal_return: "Illegal return statement", |
| 166 error_loading_debugger: "Error loading debugger %0", |
| 167 no_input_to_regexp: "No input to %0", |
| 168 result_not_primitive: "Result of %0 must be a primitive, was %1", |
| 169 invalid_json: "String '%0' is not valid JSON", |
| 170 circular_structure: "Converting circular structure to JSON" |
| 171 }; |
| 172 } |
164 var format = kMessages[message.type]; | 173 var format = kMessages[message.type]; |
165 if (!format) return "<unknown message " + message.type + ">"; | 174 if (!format) return "<unknown message " + message.type + ">"; |
166 return FormatString(format, message.args); | 175 return FormatString(format, message.args); |
167 } | 176 } |
168 | 177 |
169 | 178 |
170 function GetLineNumber(message) { | 179 function GetLineNumber(message) { |
171 if (message.startPos == -1) return -1; | 180 if (message.startPos == -1) return -1; |
172 var location = message.script.locationFromPosition(message.startPos, true); | 181 var location = message.script.locationFromPosition(message.startPos, true); |
173 if (location == null) return -1; | 182 if (location == null) return -1; |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); | 886 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); |
878 } | 887 } |
879 var message = this.message; | 888 var message = this.message; |
880 return this.name + (message ? (": " + message) : ""); | 889 return this.name + (message ? (": " + message) : ""); |
881 }, DONT_ENUM); | 890 }, DONT_ENUM); |
882 | 891 |
883 | 892 |
884 // Boilerplate for exceptions for stack overflows. Used from | 893 // Boilerplate for exceptions for stack overflows. Used from |
885 // Top::StackOverflow(). | 894 // Top::StackOverflow(). |
886 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 895 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |