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

Side by Side Diff: src/messages.js

Issue 6606006: [Isolates] Merge 6500:6700 from bleeding_edge to isolates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 9 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 | « src/messages.cc ('k') | src/mirror-debugger.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 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 20 matching lines...) Expand all
31 // Matches Script::Type from objects.h 31 // Matches Script::Type from objects.h
32 var TYPE_NATIVE = 0; 32 var TYPE_NATIVE = 0;
33 var TYPE_EXTENSION = 1; 33 var TYPE_EXTENSION = 1;
34 var TYPE_NORMAL = 2; 34 var TYPE_NORMAL = 2;
35 35
36 // Matches Script::CompilationType from objects.h 36 // Matches Script::CompilationType from objects.h
37 var COMPILATION_TYPE_HOST = 0; 37 var COMPILATION_TYPE_HOST = 0;
38 var COMPILATION_TYPE_EVAL = 1; 38 var COMPILATION_TYPE_EVAL = 1;
39 var COMPILATION_TYPE_JSON = 2; 39 var COMPILATION_TYPE_JSON = 2;
40 40
41 // Lazily initialized.
42 var kVowelSounds = 0;
43 var kCapitalVowelSounds = 0;
44
45 // Matches Messages::kNoLineNumberInfo from v8.h 41 // Matches Messages::kNoLineNumberInfo from v8.h
46 var kNoLineNumberInfo = 0; 42 var kNoLineNumberInfo = 0;
47 43
48 // If this object gets passed to an error constructor the error will 44 // If this object gets passed to an error constructor the error will
49 // get an accessor for .message that constructs a descriptive error 45 // get an accessor for .message that constructs a descriptive error
50 // message on access. 46 // message on access.
51 var kAddMessageAccessorsMarker = { }; 47 var kAddMessageAccessorsMarker = { };
52 48
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; 49 var kMessages = 0;
79 50
51 var kReplacementMarkers = [ "%0", "%1", "%2", "%3" ];
80 52
81 function FormatString(format, args) { 53 function FormatString(format, message) {
82 var result = format; 54 var args = %MessageGetArguments(message);
83 for (var i = 0; i < args.length; i++) { 55 var result = "";
84 var str; 56 var arg_num = 0;
85 try { 57 for (var i = 0; i < format.length; i++) {
86 str = ToDetailString(args[i]); 58 var str = format[i];
87 } catch (e) { 59 for (arg_num = 0; arg_num < kReplacementMarkers.length; arg_num++) {
88 str = "#<error>"; 60 if (format[i] !== kReplacementMarkers[arg_num]) continue;
61 try {
62 str = ToDetailString(args[arg_num]);
63 } catch (e) {
64 str = "#<error>";
65 }
89 } 66 }
90 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); 67 result += str;
91 } 68 }
92 return result; 69 return result;
93 } 70 }
94 71
95 72
96 // To check if something is a native error we need to check the 73 // 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 74 // concrete native error types. It is not enough to check "obj
98 // instanceof $Error" because user code can replace 75 // instanceof $Error" because user code can replace
99 // NativeError.prototype.__proto__. User code cannot replace 76 // NativeError.prototype.__proto__. User code cannot replace
100 // NativeError.prototype though and therefore this is a safe test. 77 // NativeError.prototype though and therefore this is a safe test.
(...skipping 22 matching lines...) Expand all
123 100
124 101
125 function ToDetailString(obj) { 102 function ToDetailString(obj) {
126 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri ng) { 103 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri ng) {
127 var constructor = obj.constructor; 104 var constructor = obj.constructor;
128 if (!constructor) return ToStringCheckErrorObject(obj); 105 if (!constructor) return ToStringCheckErrorObject(obj);
129 var constructorName = constructor.name; 106 var constructorName = constructor.name;
130 if (!constructorName || !IS_STRING(constructorName)) { 107 if (!constructorName || !IS_STRING(constructorName)) {
131 return ToStringCheckErrorObject(obj); 108 return ToStringCheckErrorObject(obj);
132 } 109 }
133 return "#<" + GetInstanceName(constructorName) + ">"; 110 return "#<" + constructorName + ">";
134 } else { 111 } else {
135 return ToStringCheckErrorObject(obj); 112 return ToStringCheckErrorObject(obj);
136 } 113 }
137 } 114 }
138 115
139 116
140 function MakeGenericError(constructor, type, args) { 117 function MakeGenericError(constructor, type, args) {
141 if (IS_UNDEFINED(args)) { 118 if (IS_UNDEFINED(args)) {
142 args = []; 119 args = [];
143 } 120 }
(...skipping 13 matching lines...) Expand all
157 // Script objects can only be created by the VM. 134 // Script objects can only be created by the VM.
158 throw new $Error("Not supported"); 135 throw new $Error("Not supported");
159 }); 136 });
160 137
161 138
162 // Helper functions; called from the runtime system. 139 // Helper functions; called from the runtime system.
163 function FormatMessage(message) { 140 function FormatMessage(message) {
164 if (kMessages === 0) { 141 if (kMessages === 0) {
165 kMessages = { 142 kMessages = {
166 // Error 143 // Error
167 cyclic_proto: "Cyclic __proto__ value", 144 cyclic_proto: ["Cyclic __proto__ value"],
168 // TypeError 145 // TypeError
169 unexpected_token: "Unexpected token %0", 146 unexpected_token: ["Unexpected token ", "%0"],
170 unexpected_token_number: "Unexpected number", 147 unexpected_token_number: ["Unexpected number"],
171 unexpected_token_string: "Unexpected string", 148 unexpected_token_string: ["Unexpected string"],
172 unexpected_token_identifier: "Unexpected identifier", 149 unexpected_token_identifier: ["Unexpected identifier"],
173 unexpected_eos: "Unexpected end of input", 150 unexpected_strict_reserved: ["Unexpected strict mode reserved word"],
174 malformed_regexp: "Invalid regular expression: /%0/: %1", 151 unexpected_eos: ["Unexpected end of input"],
175 unterminated_regexp: "Invalid regular expression: missing /", 152 malformed_regexp: ["Invalid regular expression: /", "%0", "/: ", "%1"],
176 regexp_flags: "Cannot supply flags when constructing one R egExp from another", 153 unterminated_regexp: ["Invalid regular expression: missing /"],
177 incompatible_method_receiver: "Method %0 called on incompatible receiver % 1", 154 regexp_flags: ["Cannot supply flags when constructing one RegExp from another"],
178 invalid_lhs_in_assignment: "Invalid left-hand side in assignment", 155 incompatible_method_receiver: ["Method ", "%0", " called on incompatible r eceiver ", "%1"],
179 invalid_lhs_in_for_in: "Invalid left-hand side in for-in", 156 invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"],
180 invalid_lhs_in_postfix_op: "Invalid left-hand side expression in postfi x operation", 157 invalid_lhs_in_for_in: ["Invalid left-hand side in for-in"],
181 invalid_lhs_in_prefix_op: "Invalid left-hand side expression in prefix operation", 158 invalid_lhs_in_postfix_op: ["Invalid left-hand side expression in postf ix operation"],
182 multiple_defaults_in_switch: "More than one default clause in switch stat ement", 159 invalid_lhs_in_prefix_op: ["Invalid left-hand side expression in prefi x operation"],
183 newline_after_throw: "Illegal newline after throw", 160 multiple_defaults_in_switch: ["More than one default clause in switch sta tement"],
184 redeclaration: "%0 '%1' has already been declared", 161 newline_after_throw: ["Illegal newline after throw"],
185 no_catch_or_finally: "Missing catch or finally after try", 162 redeclaration: ["%0", " '", "%1", "' has already been decla red"],
186 unknown_label: "Undefined label '%0'", 163 no_catch_or_finally: ["Missing catch or finally after try"],
187 uncaught_exception: "Uncaught %0", 164 unknown_label: ["Undefined label '", "%0", "'"],
188 stack_trace: "Stack Trace:\n%0", 165 uncaught_exception: ["Uncaught ", "%0"],
189 called_non_callable: "%0 is not a function", 166 stack_trace: ["Stack Trace:\n", "%0"],
190 undefined_method: "Object %1 has no method '%0'", 167 called_non_callable: ["%0", " is not a function"],
191 property_not_function: "Property '%0' of object %1 is not a functio n", 168 undefined_method: ["Object ", "%1", " has no method '", "%0", "'"],
192 cannot_convert_to_primitive: "Cannot convert object to primitive value", 169 property_not_function: ["Property '", "%0", "' of object ", "%1", " is not a function"],
193 not_constructor: "%0 is not a constructor", 170 cannot_convert_to_primitive: ["Cannot convert object to primitive value"] ,
194 not_defined: "%0 is not defined", 171 not_constructor: ["%0", " is not a constructor"],
195 non_object_property_load: "Cannot read property '%0' of %1", 172 not_defined: ["%0", " is not defined"],
196 non_object_property_store: "Cannot set property '%0' of %1", 173 non_object_property_load: ["Cannot read property '", "%0", "' of ", "% 1"],
197 non_object_property_call: "Cannot call method '%0' of %1", 174 non_object_property_store: ["Cannot set property '", "%0", "' of ", "%1 "],
198 with_expression: "%0 has no properties", 175 non_object_property_call: ["Cannot call method '", "%0", "' of ", "%1" ],
199 illegal_invocation: "Illegal invocation", 176 with_expression: ["%0", " has no properties"],
200 no_setter_in_callback: "Cannot set property %0 of %1 which has only a getter", 177 illegal_invocation: ["Illegal invocation"],
201 apply_non_function: "Function.prototype.apply was called on %0, which is a %1 and not a function", 178 no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1", " which has only a getter"],
202 apply_wrong_args: "Function.prototype.apply: Arguments list ha s wrong type", 179 apply_non_function: ["Function.prototype.apply was called on ", "%0", ", which is a ", "%1", " and not a function"],
203 invalid_in_operator_use: "Cannot use 'in' operator to search for '%0' in %1", 180 apply_wrong_args: ["Function.prototype.apply: Arguments list h as wrong type"],
204 instanceof_function_expected: "Expecting a function in instanceof check, b ut got %0", 181 invalid_in_operator_use: ["Cannot use 'in' operator to search for '", "%0", "' in ", "%1"],
205 instanceof_nonobject_proto: "Function has non-object prototype '%0' in i nstanceof check", 182 instanceof_function_expected: ["Expecting a function in instanceof check, but got ", "%0"],
206 null_to_object: "Cannot convert null to object", 183 instanceof_nonobject_proto: ["Function has non-object prototype '", "%0" , "' in instanceof check"],
207 reduce_no_initial: "Reduce of empty array with no initial value ", 184 null_to_object: ["Cannot convert null to object"],
208 getter_must_be_callable: "Getter must be a function: %0", 185 reduce_no_initial: ["Reduce of empty array with no initial valu e"],
209 setter_must_be_callable: "Setter must be a function: %0", 186 getter_must_be_callable: ["Getter 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", 187 setter_must_be_callable: ["Setter must be a function: ", "%0"],
211 proto_object_or_null: "Object prototype may only be an Object or n ull", 188 value_and_accessor: ["Invalid property. A property cannot both have accessors and be writable or have a value: ", "%0"],
212 property_desc_object: "Property description must be an object: %0" , 189 proto_object_or_null: ["Object prototype may only be an Object or null"],
213 redefine_disallowed: "Cannot redefine property: %0", 190 property_desc_object: ["Property description must be an object: ", "%0"],
214 define_disallowed: "Cannot define property, object is not exten sible: %0", 191 redefine_disallowed: ["Cannot redefine property: ", "%0"],
192 define_disallowed: ["Cannot define property, object is not exte nsible: ", "%0"],
215 // RangeError 193 // RangeError
216 invalid_array_length: "Invalid array length", 194 invalid_array_length: ["Invalid array length"],
217 stack_overflow: "Maximum call stack size exceeded", 195 stack_overflow: ["Maximum call stack size exceeded"],
218 // SyntaxError 196 // SyntaxError
219 unable_to_parse: "Parse error", 197 unable_to_parse: ["Parse error"],
220 duplicate_regexp_flag: "Duplicate RegExp flag %0", 198 duplicate_regexp_flag: ["Duplicate RegExp flag ", "%0"],
221 invalid_regexp: "Invalid RegExp pattern /%0/", 199 invalid_regexp: ["Invalid RegExp pattern /", "%0", "/"],
222 illegal_break: "Illegal break statement", 200 illegal_break: ["Illegal break statement"],
223 illegal_continue: "Illegal continue statement", 201 illegal_continue: ["Illegal continue statement"],
224 illegal_return: "Illegal return statement", 202 illegal_return: ["Illegal return statement"],
225 error_loading_debugger: "Error loading debugger", 203 error_loading_debugger: ["Error loading debugger"],
226 no_input_to_regexp: "No input to %0", 204 no_input_to_regexp: ["No input to ", "%0"],
227 invalid_json: "String '%0' is not valid JSON", 205 invalid_json: ["String '", "%0", "' is not valid JSON"],
228 circular_structure: "Converting circular structure to JSON", 206 circular_structure: ["Converting circular structure to JSON"],
229 obj_ctor_property_non_object: "Object.%0 called on non-object", 207 obj_ctor_property_non_object: ["Object.", "%0", " called on non-object"],
230 array_indexof_not_defined: "Array.getIndexOf: Argument undefined", 208 array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"],
231 object_not_extensible: "Can't add property %0, object is not extens ible", 209 object_not_extensible: ["Can't add property ", "%0", ", object is n ot extensible"],
232 illegal_access: "Illegal access", 210 illegal_access: ["Illegal access"],
233 invalid_preparser_data: "Invalid preparser data for function %0", 211 invalid_preparser_data: ["Invalid preparser data for function ", "%0 "],
234 strict_mode_with: "Strict mode code may not include a with sta tement", 212 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", 213 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", 214 too_many_parameters: ["Too many parameters in function definition "],
237 strict_param_dupe: "Strict mode function may not have duplicate parameter names", 215 strict_param_name: ["Parameter name eval or arguments is not al lowed in strict mode"],
238 strict_var_name: "Variable name may not be eval or arguments in strict mode", 216 strict_param_dupe: ["Strict mode function may not have duplicat e parameter names"],
239 strict_function_name: "Function name may not be eval or arguments in strict mode", 217 strict_var_name: ["Variable name may not be eval or arguments in strict mode"],
240 strict_octal_literal: "Octal literals are not allowed in strict mo de.", 218 strict_function_name: ["Function name may not be eval or arguments in strict mode"],
241 strict_duplicate_property: "Duplicate data property in object literal n ot allowed in strict mode", 219 strict_octal_literal: ["Octal literals are not allowed in strict m ode."],
242 accessor_data_property: "Object literal may not have data and access or property with the same name", 220 strict_duplicate_property: ["Duplicate data property in object literal not allowed in strict mode"],
243 accessor_get_set: "Object literal may not have multiple get/se t accessors with the same name", 221 accessor_data_property: ["Object literal may not have data and acces sor property with the same name"],
222 accessor_get_set: ["Object literal may not have multiple get/s et accessors with the same name"],
223 strict_lhs_assignment: ["Assignment to eval or arguments is not all owed in strict mode"],
224 strict_lhs_postfix: ["Postfix increment/decrement may not have e val or arguments operand in strict mode"],
225 strict_lhs_prefix: ["Prefix increment/decrement may not have ev al or arguments operand in strict mode"],
226 strict_reserved_word: ["Use of future reserved word in strict mode "],
244 }; 227 };
245 } 228 }
246 var format = kMessages[message.type]; 229 var message_type = %MessageGetType(message);
247 if (!format) return "<unknown message " + message.type + ">"; 230 var format = kMessages[message_type];
248 return FormatString(format, message.args); 231 if (!format) return "<unknown message " + message_type + ">";
232 return FormatString(format, message);
249 } 233 }
250 234
251 235
252 function GetLineNumber(message) { 236 function GetLineNumber(message) {
253 if (message.startPos == -1) return kNoLineNumberInfo; 237 var start_position = %MessageGetStartPosition(message);
254 var location = message.script.locationFromPosition(message.startPos, true); 238 if (start_position == -1) return kNoLineNumberInfo;
239 var script = %MessageGetScript(message);
240 var location = script.locationFromPosition(start_position, true);
255 if (location == null) return kNoLineNumberInfo; 241 if (location == null) return kNoLineNumberInfo;
256 return location.line + 1; 242 return location.line + 1;
257 } 243 }
258 244
259 245
260 // Returns the source code line containing the given source 246 // Returns the source code line containing the given source
261 // position, or the empty string if the position is invalid. 247 // position, or the empty string if the position is invalid.
262 function GetSourceLine(message) { 248 function GetSourceLine(message) {
263 var location = message.script.locationFromPosition(message.startPos, true); 249 var script = %MessageGetScript(message);
250 var start_position = %MessageGetStartPosition(message);
251 var location = script.locationFromPosition(start_position, true);
264 if (location == null) return ""; 252 if (location == null) return "";
265 location.restrict(); 253 location.restrict();
266 return location.sourceText(); 254 return location.sourceText();
267 } 255 }
268 256
269 257
270 function MakeTypeError(type, args) { 258 function MakeTypeError(type, args) {
271 return MakeGenericError($TypeError, type, args); 259 return MakeGenericError($TypeError, type, args);
272 } 260 }
273 261
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 var i = (lower + upper) >> 1; 310 var i = (lower + upper) >> 1;
323 311
324 if (position > line_ends[i]) { 312 if (position > line_ends[i]) {
325 lower = i + 1; 313 lower = i + 1;
326 } else if (position <= line_ends[i - 1]) { 314 } else if (position <= line_ends[i - 1]) {
327 upper = i - 1; 315 upper = i - 1;
328 } else { 316 } else {
329 return i; 317 return i;
330 } 318 }
331 } 319 }
320
332 return -1; 321 return -1;
333 } 322 }
334 323
335 /** 324 /**
336 * Get information on a specific source position. 325 * Get information on a specific source position.
337 * @param {number} position The source position 326 * @param {number} position The source position
338 * @param {boolean} include_resource_offset Set to true to have the resource 327 * @param {boolean} include_resource_offset Set to true to have the resource
339 * offset added to the location 328 * offset added to the location
340 * @return {SourceLocation} 329 * @return {SourceLocation}
341 * If line is negative or not in the source null is returned. 330 * If line is negative or not in the source null is returned.
342 */ 331 */
343 Script.prototype.locationFromPosition = function (position, 332 Script.prototype.locationFromPosition = function (position,
344 include_resource_offset) { 333 include_resource_offset) {
345 var line = this.lineFromPosition(position); 334 var line = this.lineFromPosition(position);
346 if (line == -1) return null; 335 if (line == -1) return null;
347 336
348 // Determine start, end and column. 337 // Determine start, end and column.
349 var line_ends = this.line_ends; 338 var line_ends = this.line_ends;
350 var start = line == 0 ? 0 : line_ends[line - 1] + 1; 339 var start = line == 0 ? 0 : line_ends[line - 1] + 1;
351 var end = line_ends[line]; 340 var end = line_ends[line];
352 if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--; 341 if (end > 0 && %_CallFunction(this.source, end - 1, StringCharAt) == '\r') end --;
353 var column = position - start; 342 var column = position - start;
354 343
355 // Adjust according to the offset within the resource. 344 // Adjust according to the offset within the resource.
356 if (include_resource_offset) { 345 if (include_resource_offset) {
357 line += this.line_offset; 346 line += this.line_offset;
358 if (line == this.line_offset) { 347 if (line == this.line_offset) {
359 column += this.column_offset; 348 column += this.column_offset;
360 } 349 }
361 } 350 }
362 351
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 446
458 // Check parameter. 447 // Check parameter.
459 if (line < 0 || this.lineCount() <= line) { 448 if (line < 0 || this.lineCount() <= line) {
460 return null; 449 return null;
461 } 450 }
462 451
463 // Return the source line. 452 // Return the source line.
464 var line_ends = this.line_ends; 453 var line_ends = this.line_ends;
465 var start = line == 0 ? 0 : line_ends[line - 1] + 1; 454 var start = line == 0 ? 0 : line_ends[line - 1] + 1;
466 var end = line_ends[line]; 455 var end = line_ends[line];
467 return StringSubstring.call(this.source, start, end); 456 return %_CallFunction(this.source, start, end, StringSubstring);
468 } 457 }
469 458
470 459
471 /** 460 /**
472 * Returns the number of source lines. 461 * Returns the number of source lines.
473 * @return {number} 462 * @return {number}
474 * Number of source lines. 463 * Number of source lines.
475 */ 464 */
476 Script.prototype.lineCount = function() { 465 Script.prototype.lineCount = function() {
477 // Return number of source lines. 466 // Return number of source lines.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 } 574 }
586 }; 575 };
587 576
588 577
589 /** 578 /**
590 * Get the source text for a SourceLocation 579 * Get the source text for a SourceLocation
591 * @return {String} 580 * @return {String}
592 * Source text for this location. 581 * Source text for this location.
593 */ 582 */
594 SourceLocation.prototype.sourceText = function () { 583 SourceLocation.prototype.sourceText = function () {
595 return StringSubstring.call(this.script.source, this.start, this.end); 584 return %_CallFunction(this.script.source, this.start, this.end, StringSubstrin g);
596 }; 585 };
597 586
598 587
599 /** 588 /**
600 * Class for a source slice. A source slice is a part of a script source with 589 * Class for a source slice. A source slice is a part of a script source with
601 * the following properties: 590 * the following properties:
602 * script : script object for the source 591 * script : script object for the source
603 * from_line : line number for the first line in the slice 592 * from_line : line number for the first line in the slice
604 * to_line : source line number for the last line in the slice 593 * to_line : source line number for the last line in the slice
605 * from_position : position of the first character in the slice 594 * from_position : position of the first character in the slice
(...skipping 16 matching lines...) Expand all
622 this.to_position = to_position; 611 this.to_position = to_position;
623 } 612 }
624 613
625 614
626 /** 615 /**
627 * Get the source text for a SourceSlice 616 * Get the source text for a SourceSlice
628 * @return {String} Source text for this slice. The last line will include 617 * @return {String} Source text for this slice. The last line will include
629 * the line terminating characters (if any) 618 * the line terminating characters (if any)
630 */ 619 */
631 SourceSlice.prototype.sourceText = function () { 620 SourceSlice.prototype.sourceText = function () {
632 return StringSubstring.call(this.script.source, this.from_position, this.to_po sition); 621 return %_CallFunction(this.script.source,
622 this.from_position,
623 this.to_position,
624 StringSubstring);
633 }; 625 };
634 626
635 627
636 // Returns the offset of the given position within the containing 628 // Returns the offset of the given position within the containing
637 // line. 629 // line.
638 function GetPositionInLine(message) { 630 function GetPositionInLine(message) {
639 var location = message.script.locationFromPosition(message.startPos, false); 631 var script = %MessageGetScript(message);
632 var start_position = %MessageGetStartPosition(message);
633 var location = script.locationFromPosition(start_position, false);
640 if (location == null) return -1; 634 if (location == null) return -1;
641 location.restrict(); 635 location.restrict();
642 return message.startPos - location.start; 636 return start_position - location.start;
643 }
644
645
646 function ErrorMessage(type, args, startPos, endPos, script, stackTrace,
647 stackFrames) {
648 this.startPos = startPos;
649 this.endPos = endPos;
650 this.type = type;
651 this.args = args;
652 this.script = script;
653 this.stackTrace = stackTrace;
654 this.stackFrames = stackFrames;
655 }
656
657
658 function MakeMessage(type, args, startPos, endPos, script, stackTrace,
659 stackFrames) {
660 return new ErrorMessage(type, args, startPos, endPos, script, stackTrace,
661 stackFrames);
662 } 637 }
663 638
664 639
665 function GetStackTraceLine(recv, fun, pos, isGlobal) { 640 function GetStackTraceLine(recv, fun, pos, isGlobal) {
666 return FormatSourcePosition(new CallSite(recv, fun, pos)); 641 return FormatSourcePosition(new CallSite(recv, fun, pos));
667 } 642 }
668 643
669 // ---------------------------------------------------------------------------- 644 // ----------------------------------------------------------------------------
670 // Error implementation 645 // Error implementation
671 646
(...skipping 25 matching lines...) Expand all
697 this.pos = pos; 672 this.pos = pos;
698 } 673 }
699 674
700 CallSite.prototype.getThis = function () { 675 CallSite.prototype.getThis = function () {
701 return this.receiver; 676 return this.receiver;
702 }; 677 };
703 678
704 CallSite.prototype.getTypeName = function () { 679 CallSite.prototype.getTypeName = function () {
705 var constructor = this.receiver.constructor; 680 var constructor = this.receiver.constructor;
706 if (!constructor) 681 if (!constructor)
707 return $Object.prototype.toString.call(this.receiver); 682 return %_CallFunction(this.receiver, ObjectToString);
708 var constructorName = constructor.name; 683 var constructorName = constructor.name;
709 if (!constructorName) 684 if (!constructorName)
710 return $Object.prototype.toString.call(this.receiver); 685 return %_CallFunction(this.receiver, ObjectToString);
711 return constructorName; 686 return constructorName;
712 }; 687 };
713 688
714 CallSite.prototype.isToplevel = function () { 689 CallSite.prototype.isToplevel = function () {
715 if (this.receiver == null) 690 if (this.receiver == null)
716 return true; 691 return true;
717 return IS_GLOBAL(this.receiver); 692 return IS_GLOBAL(this.receiver);
718 }; 693 };
719 694
720 CallSite.prototype.isEval = function () { 695 CallSite.prototype.isEval = function () {
(...skipping 28 matching lines...) Expand all
749 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) 724 if (script && script.compilation_type == COMPILATION_TYPE_EVAL)
750 return "eval"; 725 return "eval";
751 return null; 726 return null;
752 }; 727 };
753 728
754 CallSite.prototype.getMethodName = function () { 729 CallSite.prototype.getMethodName = function () {
755 // See if we can find a unique property on the receiver that holds 730 // See if we can find a unique property on the receiver that holds
756 // this function. 731 // this function.
757 var ownName = this.fun.name; 732 var ownName = this.fun.name;
758 if (ownName && this.receiver && 733 if (ownName && this.receiver &&
759 (ObjectLookupGetter.call(this.receiver, ownName) === this.fun || 734 (%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun | |
760 ObjectLookupSetter.call(this.receiver, ownName) === this.fun || 735 %_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun | |
761 this.receiver[ownName] === this.fun)) { 736 this.receiver[ownName] === this.fun)) {
762 // To handle DontEnum properties we guess that the method has 737 // To handle DontEnum properties we guess that the method has
763 // the same name as the function. 738 // the same name as the function.
764 return ownName; 739 return ownName;
765 } 740 }
766 var name = null; 741 var name = null;
767 for (var prop in this.receiver) { 742 for (var prop in this.receiver) {
768 if (this.receiver.__lookupGetter__(prop) === this.fun || 743 if (this.receiver.__lookupGetter__(prop) === this.fun ||
769 this.receiver.__lookupSetter__(prop) === this.fun || 744 this.receiver.__lookupSetter__(prop) === this.fun ||
770 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f un)) { 745 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f un)) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 // Define all the expected properties directly on the error 973 // Define all the expected properties directly on the error
999 // object. This avoids going through getters and setters defined 974 // object. This avoids going through getters and setters defined
1000 // on prototype objects. 975 // on prototype objects.
1001 %IgnoreAttributesAndSetProperty(this, 'stack', void 0); 976 %IgnoreAttributesAndSetProperty(this, 'stack', void 0);
1002 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0); 977 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0);
1003 %IgnoreAttributesAndSetProperty(this, 'type', void 0); 978 %IgnoreAttributesAndSetProperty(this, 'type', void 0);
1004 if (m === kAddMessageAccessorsMarker) { 979 if (m === kAddMessageAccessorsMarker) {
1005 // DefineOneShotAccessor always inserts a message property and 980 // DefineOneShotAccessor always inserts a message property and
1006 // ignores setters. 981 // ignores setters.
1007 DefineOneShotAccessor(this, 'message', function (obj) { 982 DefineOneShotAccessor(this, 'message', function (obj) {
1008 return FormatMessage({type: obj.type, args: obj.arguments}); 983 return FormatMessage(%NewMessageObject(obj.type, obj.arguments));
1009 }); 984 });
1010 } else if (!IS_UNDEFINED(m)) { 985 } else if (!IS_UNDEFINED(m)) {
1011 %IgnoreAttributesAndSetProperty(this, 'message', ToString(m)); 986 %IgnoreAttributesAndSetProperty(this, 'message', ToString(m));
1012 } 987 }
1013 captureStackTrace(this, f); 988 captureStackTrace(this, f);
1014 } else { 989 } else {
1015 return new f(m); 990 return new f(m);
1016 } 991 }
1017 }); 992 });
1018 } 993 }
1019 994
1020 function captureStackTrace(obj, cons_opt) { 995 function captureStackTrace(obj, cons_opt) {
1021 var stackTraceLimit = $Error.stackTraceLimit; 996 var stackTraceLimit = $Error.stackTraceLimit;
1022 if (!stackTraceLimit) return; 997 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return;
1023 if (stackTraceLimit < 0 || stackTraceLimit > 10000) 998 if (stackTraceLimit < 0 || stackTraceLimit > 10000)
1024 stackTraceLimit = 10000; 999 stackTraceLimit = 10000;
1025 var raw_stack = %CollectStackTrace(cons_opt ? cons_opt : captureStackTrace, 1000 var raw_stack = %CollectStackTrace(cons_opt
1026 stackTraceLimit); 1001 ? cons_opt
1002 : captureStackTrace, stackTraceLimit);
1027 DefineOneShotAccessor(obj, 'stack', function (obj) { 1003 DefineOneShotAccessor(obj, 'stack', function (obj) {
1028 return FormatRawStackTrace(obj, raw_stack); 1004 return FormatRawStackTrace(obj, raw_stack);
1029 }); 1005 });
1030 }; 1006 };
1031 1007
1032 $Math.__proto__ = global.Object.prototype; 1008 $Math.__proto__ = global.Object.prototype;
1033 1009
1034 DefineError(function Error() { }); 1010 DefineError(function Error() { });
1035 DefineError(function TypeError() { }); 1011 DefineError(function TypeError() { });
1036 DefineError(function RangeError() { }); 1012 DefineError(function RangeError() { });
1037 DefineError(function SyntaxError() { }); 1013 DefineError(function SyntaxError() { });
1038 DefineError(function ReferenceError() { }); 1014 DefineError(function ReferenceError() { });
1039 DefineError(function EvalError() { }); 1015 DefineError(function EvalError() { });
1040 DefineError(function URIError() { }); 1016 DefineError(function URIError() { });
1041 1017
1042 $Error.captureStackTrace = captureStackTrace; 1018 $Error.captureStackTrace = captureStackTrace;
1043 1019
1044 // Setup extra properties of the Error.prototype object. 1020 // Setup extra properties of the Error.prototype object.
1045 $Error.prototype.message = ''; 1021 $Error.prototype.message = '';
1046 1022
1047 // Global list of error objects visited during errorToString. This is 1023 // Global list of error objects visited during errorToString. This is
1048 // used to detect cycles in error toString formatting. 1024 // used to detect cycles in error toString formatting.
1049 var visited_errors = new $Array(); 1025 var visited_errors = new $Array();
1050 var cyclic_error_marker = new $Object(); 1026 var cyclic_error_marker = new $Object();
1051 1027
1052 function errorToStringDetectCycle() { 1028 function errorToStringDetectCycle() {
1053 if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker; 1029 if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker;
1054 try { 1030 try {
1055 var type = this.type; 1031 var type = this.type;
1056 if (type && !this.hasOwnProperty("message")) { 1032 if (type && !%_CallFunction(this, "message", ObjectHasOwnProperty)) {
1057 var formatted = FormatMessage({ type: type, args: this.arguments }); 1033 var formatted = FormatMessage(%NewMessageObject(type, this.arguments));
1058 return this.name + ": " + formatted; 1034 return this.name + ": " + formatted;
1059 } 1035 }
1060 var message = this.hasOwnProperty("message") ? (": " + this.message) : ""; 1036 var message = %_CallFunction(this, "message", ObjectHasOwnProperty)
1037 ? (": " + this.message)
1038 : "";
1061 return this.name + message; 1039 return this.name + message;
1062 } finally { 1040 } finally {
1063 visited_errors.pop(); 1041 visited_errors.length = visited_errors.length - 1;
1064 } 1042 }
1065 } 1043 }
1066 1044
1067 function errorToString() { 1045 function errorToString() {
1068 // This helper function is needed because access to properties on 1046 // This helper function is needed because access to properties on
1069 // the builtins object do not work inside of a catch clause. 1047 // the builtins object do not work inside of a catch clause.
1070 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } 1048 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; }
1071 1049
1072 try { 1050 try {
1073 return %_CallFunction(this, errorToStringDetectCycle); 1051 return %_CallFunction(this, errorToStringDetectCycle);
1074 } catch(e) { 1052 } catch(e) {
1075 // If this error message was encountered already return the empty 1053 // If this error message was encountered already return the empty
1076 // string for it instead of recursively formatting it. 1054 // string for it instead of recursively formatting it.
1077 if (isCyclicErrorMarker(e)) return ''; 1055 if (isCyclicErrorMarker(e)) return '';
1078 else throw e; 1056 else throw e;
1079 } 1057 }
1080 } 1058 }
1081 1059
1082 %FunctionSetName(errorToString, 'toString'); 1060 %FunctionSetName(errorToString, 'toString');
1083 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); 1061 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM);
1084 1062
1085 // Boilerplate for exceptions for stack overflows. Used from 1063 // Boilerplate for exceptions for stack overflows. Used from
1086 // Isolate::StackOverflow(). 1064 // Isolate::StackOverflow().
1087 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1065 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« no previous file with comments | « src/messages.cc ('k') | src/mirror-debugger.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698