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