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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 var kCapitalVowelSounds = 0; | 43 var kCapitalVowelSounds = 0; |
44 | 44 |
45 // Matches Messages::kNoLineNumberInfo from v8.h | 45 // Matches Messages::kNoLineNumberInfo from v8.h |
46 var kNoLineNumberInfo = 0; | 46 var kNoLineNumberInfo = 0; |
47 | 47 |
48 // If this object gets passed to an error constructor the error will | 48 // If this object gets passed to an error constructor the error will |
49 // get an accessor for .message that constructs a descriptive error | 49 // get an accessor for .message that constructs a descriptive error |
50 // message on access. | 50 // message on access. |
51 var kAddMessageAccessorsMarker = { }; | 51 var kAddMessageAccessorsMarker = { }; |
52 | 52 |
53 | |
54 function GetInstanceName(cons) { | |
55 if (cons.length == 0) { | |
56 return ""; | |
57 } | |
58 var first = %StringToLowerCase(StringCharAt.call(cons, 0)); | |
59 if (kVowelSounds === 0) { | |
60 kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true}; | |
61 kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, h: true, | |
62 f: true, l: true, m: true, n: true, r: true, s: true, x: true, y: true}; | |
63 } | |
64 var vowel_mapping = kVowelSounds; | |
65 if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) { | |
66 // First char is upper case | |
67 var second = %StringToLowerCase(StringCharAt.call(cons, 1)); | |
68 // Second char is upper case | |
69 if (StringCharAt.call(cons, 1) != second) { | |
70 vowel_mapping = kCapitalVowelSounds; | |
71 } | |
72 } | |
73 var s = vowel_mapping[first] ? "an " : "a "; | |
74 return s + cons; | |
75 } | |
76 | |
77 | |
78 var kMessages = 0; | 53 var kMessages = 0; |
79 | 54 |
| 55 var kReplacementMarkers = |
| 56 [ "%0", "%1", "%2", "%3" ] |
80 | 57 |
81 function FormatString(format, args) { | 58 function FormatString(format, args) { |
82 var result = format; | 59 var result = ""; |
83 for (var i = 0; i < args.length; i++) { | 60 var arg_num = 0; |
84 var str; | 61 for (var i = 0; i < format.length; i++) { |
85 try { | 62 var str = format[i]; |
86 str = ToDetailString(args[i]); | 63 for (arg_num = 0; arg_num < kReplacementMarkers.length; arg_num++) { |
87 } catch (e) { | 64 if (format[i] !== kReplacementMarkers[arg_num]) continue; |
88 str = "#<error>"; | 65 try { |
| 66 str = ToDetailString(args[arg_num]); |
| 67 } catch (e) { |
| 68 str = "#<error>"; |
| 69 } |
89 } | 70 } |
90 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); | 71 result += str; |
91 } | 72 } |
92 return result; | 73 return result; |
93 } | 74 } |
94 | 75 |
95 | 76 |
96 // To check if something is a native error we need to check the | 77 // To check if something is a native error we need to check the |
97 // concrete native error types. It is not enough to check "obj | 78 // concrete native error types. It is not enough to check "obj |
98 // instanceof $Error" because user code can replace | 79 // instanceof $Error" because user code can replace |
99 // NativeError.prototype.__proto__. User code cannot replace | 80 // NativeError.prototype.__proto__. User code cannot replace |
100 // NativeError.prototype though and therefore this is a safe test. | 81 // NativeError.prototype though and therefore this is a safe test. |
(...skipping 22 matching lines...) Expand all Loading... |
123 | 104 |
124 | 105 |
125 function ToDetailString(obj) { | 106 function ToDetailString(obj) { |
126 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri
ng) { | 107 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri
ng) { |
127 var constructor = obj.constructor; | 108 var constructor = obj.constructor; |
128 if (!constructor) return ToStringCheckErrorObject(obj); | 109 if (!constructor) return ToStringCheckErrorObject(obj); |
129 var constructorName = constructor.name; | 110 var constructorName = constructor.name; |
130 if (!constructorName || !IS_STRING(constructorName)) { | 111 if (!constructorName || !IS_STRING(constructorName)) { |
131 return ToStringCheckErrorObject(obj); | 112 return ToStringCheckErrorObject(obj); |
132 } | 113 } |
133 return "#<" + GetInstanceName(constructorName) + ">"; | 114 return "#<" + constructorName + ">"; |
134 } else { | 115 } else { |
135 return ToStringCheckErrorObject(obj); | 116 return ToStringCheckErrorObject(obj); |
136 } | 117 } |
137 } | 118 } |
138 | 119 |
139 | 120 |
140 function MakeGenericError(constructor, type, args) { | 121 function MakeGenericError(constructor, type, args) { |
141 if (IS_UNDEFINED(args)) { | 122 if (IS_UNDEFINED(args)) { |
142 args = []; | 123 args = []; |
143 } | 124 } |
(...skipping 13 matching lines...) Expand all Loading... |
157 // Script objects can only be created by the VM. | 138 // Script objects can only be created by the VM. |
158 throw new $Error("Not supported"); | 139 throw new $Error("Not supported"); |
159 }); | 140 }); |
160 | 141 |
161 | 142 |
162 // Helper functions; called from the runtime system. | 143 // Helper functions; called from the runtime system. |
163 function FormatMessage(message) { | 144 function FormatMessage(message) { |
164 if (kMessages === 0) { | 145 if (kMessages === 0) { |
165 kMessages = { | 146 kMessages = { |
166 // Error | 147 // Error |
167 cyclic_proto: "Cyclic __proto__ value", | 148 cyclic_proto: ["Cyclic __proto__ value"], |
168 // TypeError | 149 // TypeError |
169 unexpected_token: "Unexpected token %0", | 150 unexpected_token: ["Unexpected token ", "%0"], |
170 unexpected_token_number: "Unexpected number", | 151 unexpected_token_number: ["Unexpected number"], |
171 unexpected_token_string: "Unexpected string", | 152 unexpected_token_string: ["Unexpected string"], |
172 unexpected_token_identifier: "Unexpected identifier", | 153 unexpected_token_identifier: ["Unexpected identifier"], |
173 unexpected_eos: "Unexpected end of input", | 154 unexpected_eos: ["Unexpected end of input"], |
174 malformed_regexp: "Invalid regular expression: /%0/: %1", | 155 malformed_regexp: ["Invalid regular expression: /", "%0", "/:
", "%1"], |
175 unterminated_regexp: "Invalid regular expression: missing /", | 156 unterminated_regexp: ["Invalid regular expression: missing /"], |
176 regexp_flags: "Cannot supply flags when constructing one R
egExp from another", | 157 regexp_flags: ["Cannot supply flags when constructing one
RegExp from another"], |
177 incompatible_method_receiver: "Method %0 called on incompatible receiver %
1", | 158 incompatible_method_receiver: ["Method ", "%0", " called on incompatible r
eceiver ", "%1"], |
178 invalid_lhs_in_assignment: "Invalid left-hand side in assignment", | 159 invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"], |
179 invalid_lhs_in_for_in: "Invalid left-hand side in for-in", | 160 invalid_lhs_in_for_in: ["Invalid left-hand side in for-in"], |
180 invalid_lhs_in_postfix_op: "Invalid left-hand side expression in postfi
x operation", | 161 invalid_lhs_in_postfix_op: ["Invalid left-hand side expression in postf
ix operation"], |
181 invalid_lhs_in_prefix_op: "Invalid left-hand side expression in prefix
operation", | 162 invalid_lhs_in_prefix_op: ["Invalid left-hand side expression in prefi
x operation"], |
182 multiple_defaults_in_switch: "More than one default clause in switch stat
ement", | 163 multiple_defaults_in_switch: ["More than one default clause in switch sta
tement"], |
183 newline_after_throw: "Illegal newline after throw", | 164 newline_after_throw: ["Illegal newline after throw"], |
184 redeclaration: "%0 '%1' has already been declared", | 165 redeclaration: ["%0", " '", "%1", "' has already been decla
red"], |
185 no_catch_or_finally: "Missing catch or finally after try", | 166 no_catch_or_finally: ["Missing catch or finally after try"], |
186 unknown_label: "Undefined label '%0'", | 167 unknown_label: ["Undefined label '", "%0", "'"], |
187 uncaught_exception: "Uncaught %0", | 168 uncaught_exception: ["Uncaught ", "%0"], |
188 stack_trace: "Stack Trace:\n%0", | 169 stack_trace: ["Stack Trace:\n", "%0"], |
189 called_non_callable: "%0 is not a function", | 170 called_non_callable: ["%0", " is not a function"], |
190 undefined_method: "Object %1 has no method '%0'", | 171 undefined_method: ["Object ", "%1", " has no method '", "%0",
"'"], |
191 property_not_function: "Property '%0' of object %1 is not a functio
n", | 172 property_not_function: ["Property '", "%0", "' of object ", "%1", "
is not a function"], |
192 cannot_convert_to_primitive: "Cannot convert object to primitive value", | 173 cannot_convert_to_primitive: ["Cannot convert object to primitive value"]
, |
193 not_constructor: "%0 is not a constructor", | 174 not_constructor: ["%0", " is not a constructor"], |
194 not_defined: "%0 is not defined", | 175 not_defined: ["%0", " is not defined"], |
195 non_object_property_load: "Cannot read property '%0' of %1", | 176 non_object_property_load: ["Cannot read property '", "%0", "' of ", "%
1"], |
196 non_object_property_store: "Cannot set property '%0' of %1", | 177 non_object_property_store: ["Cannot set property '", "%0", "' of ", "%1
"], |
197 non_object_property_call: "Cannot call method '%0' of %1", | 178 non_object_property_call: ["Cannot call method '", "%0", "' of ", "%1"
], |
198 with_expression: "%0 has no properties", | 179 with_expression: ["%0", " has no properties"], |
199 illegal_invocation: "Illegal invocation", | 180 illegal_invocation: ["Illegal invocation"], |
200 no_setter_in_callback: "Cannot set property %0 of %1 which has only
a getter", | 181 no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1",
" which has only a getter"], |
201 apply_non_function: "Function.prototype.apply was called on %0,
which is a %1 and not a function", | 182 apply_non_function: ["Function.prototype.apply was called on ",
"%0", ", which is a ", "%1", " and not a function"], |
202 apply_wrong_args: "Function.prototype.apply: Arguments list ha
s wrong type", | 183 apply_wrong_args: ["Function.prototype.apply: Arguments list h
as wrong type"], |
203 invalid_in_operator_use: "Cannot use 'in' operator to search for '%0'
in %1", | 184 invalid_in_operator_use: ["Cannot use 'in' operator to search for '",
"%0", "' in ", "%1"], |
204 instanceof_function_expected: "Expecting a function in instanceof check, b
ut got %0", | 185 instanceof_function_expected: ["Expecting a function in instanceof check,
but got ", "%0"], |
205 instanceof_nonobject_proto: "Function has non-object prototype '%0' in i
nstanceof check", | 186 instanceof_nonobject_proto: ["Function has non-object prototype '", "%0"
, "' in instanceof check"], |
206 null_to_object: "Cannot convert null to object", | 187 null_to_object: ["Cannot convert null to object"], |
207 reduce_no_initial: "Reduce of empty array with no initial value
", | 188 reduce_no_initial: ["Reduce of empty array with no initial valu
e"], |
208 getter_must_be_callable: "Getter must be a function: %0", | 189 getter_must_be_callable: ["Getter must be a function: ", "%0"], |
209 setter_must_be_callable: "Setter must be a function: %0", | 190 setter_must_be_callable: ["Setter must be a function: ", "%0"], |
210 value_and_accessor: "Invalid property. A property cannot both h
ave accessors and be writable or have a value: %0", | 191 value_and_accessor: ["Invalid property. A property cannot both
have accessors and be writable or have a value: ", "%0"], |
211 proto_object_or_null: "Object prototype may only be an Object or n
ull", | 192 proto_object_or_null: ["Object prototype may only be an Object or
null"], |
212 property_desc_object: "Property description must be an object: %0"
, | 193 property_desc_object: ["Property description must be an object: ",
"%0"], |
213 redefine_disallowed: "Cannot redefine property: %0", | 194 redefine_disallowed: ["Cannot redefine property: ", "%0"], |
214 define_disallowed: "Cannot define property, object is not exten
sible: %0", | 195 define_disallowed: ["Cannot define property, object is not exte
nsible: ", "%0"], |
215 // RangeError | 196 // RangeError |
216 invalid_array_length: "Invalid array length", | 197 invalid_array_length: ["Invalid array length"], |
217 stack_overflow: "Maximum call stack size exceeded", | 198 stack_overflow: ["Maximum call stack size exceeded"], |
218 // SyntaxError | 199 // SyntaxError |
219 unable_to_parse: "Parse error", | 200 unable_to_parse: ["Parse error"], |
220 duplicate_regexp_flag: "Duplicate RegExp flag %0", | 201 duplicate_regexp_flag: ["Duplicate RegExp flag ", "%0"], |
221 invalid_regexp: "Invalid RegExp pattern /%0/", | 202 invalid_regexp: ["Invalid RegExp pattern /", "%0", "/"], |
222 illegal_break: "Illegal break statement", | 203 illegal_break: ["Illegal break statement"], |
223 illegal_continue: "Illegal continue statement", | 204 illegal_continue: ["Illegal continue statement"], |
224 illegal_return: "Illegal return statement", | 205 illegal_return: ["Illegal return statement"], |
225 error_loading_debugger: "Error loading debugger", | 206 error_loading_debugger: ["Error loading debugger"], |
226 no_input_to_regexp: "No input to %0", | 207 no_input_to_regexp: ["No input to ", "%0"], |
227 invalid_json: "String '%0' is not valid JSON", | 208 invalid_json: ["String '", "%0", "' is not valid JSON"], |
228 circular_structure: "Converting circular structure to JSON", | 209 circular_structure: ["Converting circular structure to JSON"], |
229 obj_ctor_property_non_object: "Object.%0 called on non-object", | 210 obj_ctor_property_non_object: ["Object.", "%0", " called on non-object"], |
230 array_indexof_not_defined: "Array.getIndexOf: Argument undefined", | 211 array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"], |
231 object_not_extensible: "Can't add property %0, object is not extens
ible", | 212 object_not_extensible: ["Can't add property ", "%0", ", object is n
ot extensible"], |
232 illegal_access: "Illegal access", | 213 illegal_access: ["Illegal access"], |
233 invalid_preparser_data: "Invalid preparser data for function %0", | 214 invalid_preparser_data: ["Invalid preparser data for function ", "%0
"], |
234 strict_mode_with: "Strict mode code may not include a with sta
tement", | 215 strict_mode_with: ["Strict mode code may not include a with st
atement"], |
235 strict_catch_variable: "Catch variable may not be eval or arguments
in strict mode", | 216 strict_catch_variable: ["Catch variable may not be eval or argument
s in strict mode"], |
236 strict_param_name: "Parameter name eval or arguments is not all
owed in strict mode", | 217 strict_param_name: ["Parameter name eval or arguments is not al
lowed in strict mode"], |
237 strict_param_dupe: "Strict mode function may not have duplicate
parameter names", | 218 strict_param_dupe: ["Strict mode function may not have duplicat
e parameter names"], |
238 strict_var_name: "Variable name may not be eval or arguments
in strict mode", | 219 strict_var_name: ["Variable name may not be eval or arguments
in strict mode"], |
239 strict_function_name: "Function name may not be eval or arguments
in strict mode", | 220 strict_function_name: ["Function name may not be eval or arguments
in strict mode"], |
240 strict_octal_literal: "Octal literals are not allowed in strict mo
de.", | 221 strict_octal_literal: ["Octal literals are not allowed in strict m
ode."], |
241 strict_duplicate_property: "Duplicate data property in object literal n
ot allowed in strict mode", | 222 strict_duplicate_property: ["Duplicate data property in object literal
not allowed in strict mode"], |
242 accessor_data_property: "Object literal may not have data and access
or property with the same name", | 223 accessor_data_property: ["Object literal may not have data and acces
sor property with the same name"], |
243 accessor_get_set: "Object literal may not have multiple get/se
t accessors with the same name", | 224 accessor_get_set: ["Object literal may not have multiple get/s
et accessors with the same name"], |
244 strict_lhs_eval_assignment: "Assignment to eval or arguments is not allo
wed in strict mode", | 225 strict_lhs_eval_assignment: ["Assignment to eval or arguments is not all
owed in strict mode"], |
245 strict_lhs_postfix: "Postfix increment/decrement may not have ev
al or arguments operand in strict mode", | 226 strict_lhs_postfix: ["Postfix increment/decrement may not have e
val or arguments operand in strict mode"], |
246 strict_lhs_prefix: "Prefix increment/decrement may not have eva
l or arguments operand in strict mode", | 227 strict_lhs_prefix: ["Prefix increment/decrement may not have ev
al or arguments operand in strict mode"], |
247 }; | 228 }; |
248 } | 229 } |
249 var format = kMessages[message.type]; | 230 var format = kMessages[message.type]; |
250 if (!format) return "<unknown message " + message.type + ">"; | 231 if (!format) return "<unknown message " + message.type + ">"; |
251 return FormatString(format, message.args); | 232 return FormatString(format, message.args); |
252 } | 233 } |
253 | 234 |
254 | 235 |
255 function GetLineNumber(message) { | 236 function GetLineNumber(message) { |
256 if (message.startPos == -1) return kNoLineNumberInfo; | 237 if (message.startPos == -1) return kNoLineNumberInfo; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 */ | 326 */ |
346 Script.prototype.locationFromPosition = function (position, | 327 Script.prototype.locationFromPosition = function (position, |
347 include_resource_offset) { | 328 include_resource_offset) { |
348 var line = this.lineFromPosition(position); | 329 var line = this.lineFromPosition(position); |
349 if (line == -1) return null; | 330 if (line == -1) return null; |
350 | 331 |
351 // Determine start, end and column. | 332 // Determine start, end and column. |
352 var line_ends = this.line_ends; | 333 var line_ends = this.line_ends; |
353 var start = line == 0 ? 0 : line_ends[line - 1] + 1; | 334 var start = line == 0 ? 0 : line_ends[line - 1] + 1; |
354 var end = line_ends[line]; | 335 var end = line_ends[line]; |
355 if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--; | 336 if (end > 0 && %_CallFunction(this.source, end - 1, StringCharAt) == '\r') end
--; |
356 var column = position - start; | 337 var column = position - start; |
357 | 338 |
358 // Adjust according to the offset within the resource. | 339 // Adjust according to the offset within the resource. |
359 if (include_resource_offset) { | 340 if (include_resource_offset) { |
360 line += this.line_offset; | 341 line += this.line_offset; |
361 if (line == this.line_offset) { | 342 if (line == this.line_offset) { |
362 column += this.column_offset; | 343 column += this.column_offset; |
363 } | 344 } |
364 } | 345 } |
365 | 346 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 441 |
461 // Check parameter. | 442 // Check parameter. |
462 if (line < 0 || this.lineCount() <= line) { | 443 if (line < 0 || this.lineCount() <= line) { |
463 return null; | 444 return null; |
464 } | 445 } |
465 | 446 |
466 // Return the source line. | 447 // Return the source line. |
467 var line_ends = this.line_ends; | 448 var line_ends = this.line_ends; |
468 var start = line == 0 ? 0 : line_ends[line - 1] + 1; | 449 var start = line == 0 ? 0 : line_ends[line - 1] + 1; |
469 var end = line_ends[line]; | 450 var end = line_ends[line]; |
470 return StringSubstring.call(this.source, start, end); | 451 return %_CallFunction(this.source, start, end, StringSubstring); |
471 } | 452 } |
472 | 453 |
473 | 454 |
474 /** | 455 /** |
475 * Returns the number of source lines. | 456 * Returns the number of source lines. |
476 * @return {number} | 457 * @return {number} |
477 * Number of source lines. | 458 * Number of source lines. |
478 */ | 459 */ |
479 Script.prototype.lineCount = function() { | 460 Script.prototype.lineCount = function() { |
480 // Return number of source lines. | 461 // Return number of source lines. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 } | 569 } |
589 }; | 570 }; |
590 | 571 |
591 | 572 |
592 /** | 573 /** |
593 * Get the source text for a SourceLocation | 574 * Get the source text for a SourceLocation |
594 * @return {String} | 575 * @return {String} |
595 * Source text for this location. | 576 * Source text for this location. |
596 */ | 577 */ |
597 SourceLocation.prototype.sourceText = function () { | 578 SourceLocation.prototype.sourceText = function () { |
598 return StringSubstring.call(this.script.source, this.start, this.end); | 579 return %_CallFunction(this.script.source, this.start, this.end, StringSubstrin
g); |
599 }; | 580 }; |
600 | 581 |
601 | 582 |
602 /** | 583 /** |
603 * Class for a source slice. A source slice is a part of a script source with | 584 * Class for a source slice. A source slice is a part of a script source with |
604 * the following properties: | 585 * the following properties: |
605 * script : script object for the source | 586 * script : script object for the source |
606 * from_line : line number for the first line in the slice | 587 * from_line : line number for the first line in the slice |
607 * to_line : source line number for the last line in the slice | 588 * to_line : source line number for the last line in the slice |
608 * from_position : position of the first character in the slice | 589 * from_position : position of the first character in the slice |
(...skipping 16 matching lines...) Expand all Loading... |
625 this.to_position = to_position; | 606 this.to_position = to_position; |
626 } | 607 } |
627 | 608 |
628 | 609 |
629 /** | 610 /** |
630 * Get the source text for a SourceSlice | 611 * Get the source text for a SourceSlice |
631 * @return {String} Source text for this slice. The last line will include | 612 * @return {String} Source text for this slice. The last line will include |
632 * the line terminating characters (if any) | 613 * the line terminating characters (if any) |
633 */ | 614 */ |
634 SourceSlice.prototype.sourceText = function () { | 615 SourceSlice.prototype.sourceText = function () { |
635 return StringSubstring.call(this.script.source, this.from_position, this.to_po
sition); | 616 return %_CallFunction(this.script.source, |
| 617 this.from_position, |
| 618 this.to_position, |
| 619 StringSubstring); |
636 }; | 620 }; |
637 | 621 |
638 | 622 |
639 // Returns the offset of the given position within the containing | 623 // Returns the offset of the given position within the containing |
640 // line. | 624 // line. |
641 function GetPositionInLine(message) { | 625 function GetPositionInLine(message) { |
642 var location = message.script.locationFromPosition(message.startPos, false); | 626 var location = message.script.locationFromPosition(message.startPos, false); |
643 if (location == null) return -1; | 627 if (location == null) return -1; |
644 location.restrict(); | 628 location.restrict(); |
645 return message.startPos - location.start; | 629 return message.startPos - location.start; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 this.pos = pos; | 684 this.pos = pos; |
701 } | 685 } |
702 | 686 |
703 CallSite.prototype.getThis = function () { | 687 CallSite.prototype.getThis = function () { |
704 return this.receiver; | 688 return this.receiver; |
705 }; | 689 }; |
706 | 690 |
707 CallSite.prototype.getTypeName = function () { | 691 CallSite.prototype.getTypeName = function () { |
708 var constructor = this.receiver.constructor; | 692 var constructor = this.receiver.constructor; |
709 if (!constructor) | 693 if (!constructor) |
710 return $Object.prototype.toString.call(this.receiver); | 694 return %_CallFunction(this.receiver, ObjectToString); |
711 var constructorName = constructor.name; | 695 var constructorName = constructor.name; |
712 if (!constructorName) | 696 if (!constructorName) |
713 return $Object.prototype.toString.call(this.receiver); | 697 return %_CallFunction(this.receiver, ObjectToString); |
714 return constructorName; | 698 return constructorName; |
715 }; | 699 }; |
716 | 700 |
717 CallSite.prototype.isToplevel = function () { | 701 CallSite.prototype.isToplevel = function () { |
718 if (this.receiver == null) | 702 if (this.receiver == null) |
719 return true; | 703 return true; |
720 return IS_GLOBAL(this.receiver); | 704 return IS_GLOBAL(this.receiver); |
721 }; | 705 }; |
722 | 706 |
723 CallSite.prototype.isEval = function () { | 707 CallSite.prototype.isEval = function () { |
(...skipping 28 matching lines...) Expand all Loading... |
752 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) | 736 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) |
753 return "eval"; | 737 return "eval"; |
754 return null; | 738 return null; |
755 }; | 739 }; |
756 | 740 |
757 CallSite.prototype.getMethodName = function () { | 741 CallSite.prototype.getMethodName = function () { |
758 // See if we can find a unique property on the receiver that holds | 742 // See if we can find a unique property on the receiver that holds |
759 // this function. | 743 // this function. |
760 var ownName = this.fun.name; | 744 var ownName = this.fun.name; |
761 if (ownName && this.receiver && | 745 if (ownName && this.receiver && |
762 (ObjectLookupGetter.call(this.receiver, ownName) === this.fun || | 746 (%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun |
| |
763 ObjectLookupSetter.call(this.receiver, ownName) === this.fun || | 747 %_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun |
| |
764 this.receiver[ownName] === this.fun)) { | 748 this.receiver[ownName] === this.fun)) { |
765 // To handle DontEnum properties we guess that the method has | 749 // To handle DontEnum properties we guess that the method has |
766 // the same name as the function. | 750 // the same name as the function. |
767 return ownName; | 751 return ownName; |
768 } | 752 } |
769 var name = null; | 753 var name = null; |
770 for (var prop in this.receiver) { | 754 for (var prop in this.receiver) { |
771 if (this.receiver.__lookupGetter__(prop) === this.fun || | 755 if (this.receiver.__lookupGetter__(prop) === this.fun || |
772 this.receiver.__lookupSetter__(prop) === this.fun || | 756 this.receiver.__lookupSetter__(prop) === this.fun || |
773 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f
un)) { | 757 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f
un)) { |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 | 1033 |
1050 // Global list of error objects visited during errorToString. This is | 1034 // Global list of error objects visited during errorToString. This is |
1051 // used to detect cycles in error toString formatting. | 1035 // used to detect cycles in error toString formatting. |
1052 var visited_errors = new $Array(); | 1036 var visited_errors = new $Array(); |
1053 var cyclic_error_marker = new $Object(); | 1037 var cyclic_error_marker = new $Object(); |
1054 | 1038 |
1055 function errorToStringDetectCycle() { | 1039 function errorToStringDetectCycle() { |
1056 if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker; | 1040 if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker; |
1057 try { | 1041 try { |
1058 var type = this.type; | 1042 var type = this.type; |
1059 if (type && !this.hasOwnProperty("message")) { | 1043 if (type && !%_CallFunction(this, "message", ObjectHasOwnProperty)) { |
1060 var formatted = FormatMessage({ type: type, args: this.arguments }); | 1044 var formatted = FormatMessage({ type: type, args: this.arguments }); |
1061 return this.name + ": " + formatted; | 1045 return this.name + ": " + formatted; |
1062 } | 1046 } |
1063 var message = this.hasOwnProperty("message") ? (": " + this.message) : ""; | 1047 var message = %_CallFunction(this, "message", ObjectHasOwnProperty) |
| 1048 ? (": " + this.message) |
| 1049 : ""; |
1064 return this.name + message; | 1050 return this.name + message; |
1065 } finally { | 1051 } finally { |
1066 visited_errors.pop(); | 1052 visited_errors.length = visited_errors.length - 1; |
1067 } | 1053 } |
1068 } | 1054 } |
1069 | 1055 |
1070 function errorToString() { | 1056 function errorToString() { |
1071 // This helper function is needed because access to properties on | 1057 // This helper function is needed because access to properties on |
1072 // the builtins object do not work inside of a catch clause. | 1058 // the builtins object do not work inside of a catch clause. |
1073 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } | 1059 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } |
1074 | 1060 |
1075 try { | 1061 try { |
1076 return %_CallFunction(this, errorToStringDetectCycle); | 1062 return %_CallFunction(this, errorToStringDetectCycle); |
1077 } catch(e) { | 1063 } catch(e) { |
1078 // If this error message was encountered already return the empty | 1064 // If this error message was encountered already return the empty |
1079 // string for it instead of recursively formatting it. | 1065 // string for it instead of recursively formatting it. |
1080 if (isCyclicErrorMarker(e)) return ''; | 1066 if (isCyclicErrorMarker(e)) return ''; |
1081 else throw e; | 1067 else throw e; |
1082 } | 1068 } |
1083 } | 1069 } |
1084 | 1070 |
1085 %FunctionSetName(errorToString, 'toString'); | 1071 %FunctionSetName(errorToString, 'toString'); |
1086 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); | 1072 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); |
1087 | 1073 |
1088 // Boilerplate for exceptions for stack overflows. Used from | 1074 // Boilerplate for exceptions for stack overflows. Used from |
1089 // Top::StackOverflow(). | 1075 // Top::StackOverflow(). |
1090 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1076 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |