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}; | |
32 const kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, | |
33 h: true, f: true, l: true, m: true, n: true, r: true, s: true, x: true, | |
34 y: true}; | |
35 | |
36 function GetInstanceName(cons) { | 31 function GetInstanceName(cons) { |
37 if (cons.length == 0) { | 32 if (cons.length == 0) { |
38 return ""; | 33 return ""; |
39 } | 34 } |
40 var first = %StringToLowerCase(StringCharAt.call(cons, 0)); | 35 var first = %StringToLowerCase(StringCharAt.call(cons, 0)); |
41 var mapping = kVowelSounds; | 36 var vowel_mapping = {a: true, e: true, i: true, o: true, u: true, y: true}; |
Mads Ager (chromium)
2009/08/12 13:44:48
Should we do lazy initialization of these instead
| |
42 if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) { | 37 if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) { |
43 // First char is upper case | 38 // First char is upper case |
44 var second = %StringToLowerCase(StringCharAt.call(cons, 1)); | 39 var second = %StringToLowerCase(StringCharAt.call(cons, 1)); |
45 // Second char is upper case | 40 // Second char is upper case |
46 if (StringCharAt.call(cons, 1) != second) | 41 if (StringCharAt.call(cons, 1) != second) |
47 mapping = kCapitalVowelSounds; | 42 // Capital vowel sounds. |
43 vowel_mapping = {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, | |
45 y: true}; | |
46 | |
48 } | 47 } |
49 var s = mapping[first] ? "an " : "a "; | 48 var s = vowel_mapping[first] ? "an " : "a "; |
50 return s + cons; | 49 return s + cons; |
51 } | 50 } |
52 | 51 |
53 | 52 |
54 const kMessages = { | 53 // Lazily initialized array of messages. |
55 // Error | 54 var kMessages = 0; |
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 | 55 |
114 | 56 |
115 function FormatString(format, args) { | 57 function FormatString(format, args) { |
116 var result = format; | 58 var result = format; |
117 for (var i = 0; i < args.length; i++) { | 59 for (var i = 0; i < args.length; i++) { |
118 var str; | 60 var str; |
119 try { str = ToDetailString(args[i]); } | 61 try { str = ToDetailString(args[i]); } |
120 catch (e) { str = "#<error>"; } | 62 catch (e) { str = "#<error>"; } |
121 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); | 63 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); |
122 } | 64 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 %FunctionSetInstanceClassName(Script, 'Script'); | 96 %FunctionSetInstanceClassName(Script, 'Script'); |
155 %SetProperty(Script.prototype, 'constructor', Script, DONT_ENUM); | 97 %SetProperty(Script.prototype, 'constructor', Script, DONT_ENUM); |
156 %SetCode(Script, function(x) { | 98 %SetCode(Script, function(x) { |
157 // Script objects can only be created by the VM. | 99 // Script objects can only be created by the VM. |
158 throw new $Error("Not supported"); | 100 throw new $Error("Not supported"); |
159 }); | 101 }); |
160 | 102 |
161 | 103 |
162 // Helper functions; called from the runtime system. | 104 // Helper functions; called from the runtime system. |
163 function FormatMessage(message) { | 105 function FormatMessage(message) { |
106 if (kMessages == 0) { | |
107 kMessages = { | |
108 // Error | |
109 cyclic_proto: "Cyclic __proto__ value", | |
110 // TypeError | |
111 unexpected_token: "Unexpected token %0", | |
112 unexpected_token_number: "Unexpected number", | |
113 unexpected_token_string: "Unexpected string", | |
114 unexpected_token_identifier: "Unexpected identifier", | |
115 unexpected_eos: "Unexpected end of input", | |
116 malformed_regexp: "Invalid regular expression: /%0/: %1", | |
117 unterminated_regexp: "Invalid regular expression: missing /", | |
118 regexp_flags: "Cannot supply flags when constructing one R egExp from another", | |
119 invalid_lhs_in_assignment: "Invalid left-hand side in assignment", | |
120 invalid_lhs_in_for_in: "Invalid left-hand side in for-in", | |
121 invalid_lhs_in_postfix_op: "Invalid left-hand side expression in postfi x operation", | |
122 invalid_lhs_in_prefix_op: "Invalid left-hand side expression in prefix operation", | |
123 multiple_defaults_in_switch: "More than one default clause in switch stat ement", | |
124 newline_after_throw: "Illegal newline after throw", | |
125 redeclaration: "%0 '%1' has already been declared", | |
126 no_catch_or_finally: "Missing catch or finally after try", | |
127 unknown_label: "Undefined label '%0'", | |
128 uncaught_exception: "Uncaught %0", | |
129 stack_trace: "Stack Trace:\n%0", | |
130 called_non_callable: "%0 is not a function", | |
131 undefined_method: "Object %1 has no method '%0'", | |
132 property_not_function: "Property '%0' of object %1 is not a functio n", | |
133 cannot_convert_to_primitive: "Cannot convert object to primitive value", | |
134 not_constructor: "%0 is not a constructor", | |
135 not_defined: "%0 is not defined", | |
136 non_object_property_load: "Cannot read property '%0' of %1", | |
137 non_object_property_store: "Cannot set property '%0' of %1", | |
138 non_object_property_call: "Cannot call method '%0' of %1", | |
139 with_expression: "%0 has no properties", | |
140 illegal_invocation: "Illegal invocation", | |
141 no_setter_in_callback: "Cannot set property %0 of %1 which has only a getter", | |
142 apply_non_function: "Function.prototype.apply was called on %0, which is a %1 and not a function", | |
143 apply_wrong_args: "Function.prototype.apply: Arguments list ha s wrong type", | |
144 invalid_in_operator_use: "Cannot use 'in' operator to search for '%0' in %1", | |
145 instanceof_function_expected: "Expecting a function in instanceof check, b ut got %0", | |
146 instanceof_nonobject_proto: "Function has non-object prototype '%0' in i nstanceof check", | |
147 null_to_object: "Cannot convert null to object", | |
148 reduce_no_initial: "Reduce of empty array with no initial value ", | |
149 // RangeError | |
150 invalid_array_length: "Invalid array length", | |
151 stack_overflow: "Maximum call stack size exceeded", | |
152 apply_overflow: "Function.prototype.apply cannot support %0 arguments", | |
153 // SyntaxError | |
154 unable_to_parse: "Parse error", | |
155 duplicate_regexp_flag: "Duplicate RegExp flag %0", | |
156 invalid_regexp: "Invalid RegExp pattern /%0/", | |
157 illegal_break: "Illegal break statement", | |
158 illegal_continue: "Illegal continue statement", | |
159 illegal_return: "Illegal return statement", | |
160 error_loading_debugger: "Error loading debugger %0", | |
161 no_input_to_regexp: "No input to %0", | |
162 result_not_primitive: "Result of %0 must be a primitive, was %1", | |
163 invalid_json: "String '%0' is not valid JSON", | |
164 circular_structure: "Converting circular structure to JSON" | |
165 }; | |
166 } | |
164 var format = kMessages[message.type]; | 167 var format = kMessages[message.type]; |
165 if (!format) return "<unknown message " + message.type + ">"; | 168 if (!format) return "<unknown message " + message.type + ">"; |
166 return FormatString(format, message.args); | 169 return FormatString(format, message.args); |
167 } | 170 } |
168 | 171 |
169 | 172 |
170 function GetLineNumber(message) { | 173 function GetLineNumber(message) { |
171 if (message.startPos == -1) return -1; | 174 if (message.startPos == -1) return -1; |
172 var location = message.script.locationFromPosition(message.startPos, true); | 175 var location = message.script.locationFromPosition(message.startPos, true); |
173 if (location == null) return -1; | 176 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 } ); | 880 return this.name + ": " + FormatMessage({ type: type, args: this.arguments } ); |
878 } | 881 } |
879 var message = this.message; | 882 var message = this.message; |
880 return this.name + (message ? (": " + message) : ""); | 883 return this.name + (message ? (": " + message) : ""); |
881 }, DONT_ENUM); | 884 }, DONT_ENUM); |
882 | 885 |
883 | 886 |
884 // Boilerplate for exceptions for stack overflows. Used from | 887 // Boilerplate for exceptions for stack overflows. Used from |
885 // Top::StackOverflow(). | 888 // Top::StackOverflow(). |
886 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 889 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |