| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // ------------------------------------------------------------------- | 5 // ------------------------------------------------------------------- |
| 6 | 6 |
| 7 (function(global, utils) { | 7 (function(global, utils) { |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 ); | 249 ); |
| 250 | 250 |
| 251 | 251 |
| 252 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 252 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
| 253 return new CallSite(recv, fun, pos, false).toString(); | 253 return new CallSite(recv, fun, pos, false).toString(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 // ---------------------------------------------------------------------------- | 256 // ---------------------------------------------------------------------------- |
| 257 // Error implementation | 257 // Error implementation |
| 258 | 258 |
| 259 | |
| 260 function FormatErrorString(error) { | |
| 261 try { | |
| 262 return %_Call(ErrorToString, error); | |
| 263 } catch (e) { | |
| 264 try { | |
| 265 return "<error: " + e + ">"; | |
| 266 } catch (ee) { | |
| 267 return "<error>"; | |
| 268 } | |
| 269 } | |
| 270 } | |
| 271 | |
| 272 | |
| 273 function GetStackFrames(raw_stack) { | |
| 274 var internal_raw_stack = new InternalArray(); | |
| 275 %MoveArrayContents(raw_stack, internal_raw_stack); | |
| 276 var frames = new InternalArray(); | |
| 277 var sloppy_frames = internal_raw_stack[0]; | |
| 278 for (var i = 1; i < internal_raw_stack.length; i += 4) { | |
| 279 var recv = internal_raw_stack[i]; | |
| 280 var fun = internal_raw_stack[i + 1]; | |
| 281 var code = internal_raw_stack[i + 2]; | |
| 282 var pc = internal_raw_stack[i + 3]; | |
| 283 // For traps in wasm, the bytecode offset is passed as (-1 - offset). | |
| 284 // Otherwise, lookup the position from the pc. | |
| 285 var pos = IS_NUMBER(fun) && pc < 0 ? (-1 - pc) : | |
| 286 %FunctionGetPositionForOffset(code, pc); | |
| 287 sloppy_frames--; | |
| 288 frames.push(new CallSite(recv, fun, pos, (sloppy_frames < 0))); | |
| 289 } | |
| 290 return frames; | |
| 291 } | |
| 292 | |
| 293 | |
| 294 // Flag to prevent recursive call of Error.prepareStackTrace. | |
| 295 var formatting_custom_stack_trace = false; | |
| 296 | |
| 297 | |
| 298 function FormatStackTrace(obj, raw_stack) { | |
| 299 var frames = GetStackFrames(raw_stack); | |
| 300 if (IS_FUNCTION(GlobalError.prepareStackTrace) && | |
| 301 !formatting_custom_stack_trace) { | |
| 302 var array = []; | |
| 303 %MoveArrayContents(frames, array); | |
| 304 formatting_custom_stack_trace = true; | |
| 305 var stack_trace = UNDEFINED; | |
| 306 try { | |
| 307 stack_trace = GlobalError.prepareStackTrace(obj, array); | |
| 308 } catch (e) { | |
| 309 throw e; // The custom formatting function threw. Rethrow. | |
| 310 } finally { | |
| 311 formatting_custom_stack_trace = false; | |
| 312 } | |
| 313 return stack_trace; | |
| 314 } | |
| 315 | |
| 316 var lines = new InternalArray(); | |
| 317 lines.push(FormatErrorString(obj)); | |
| 318 for (var i = 0; i < frames.length; i++) { | |
| 319 var frame = frames[i]; | |
| 320 var line; | |
| 321 try { | |
| 322 line = frame.toString(); | |
| 323 } catch (e) { | |
| 324 try { | |
| 325 line = "<error: " + e + ">"; | |
| 326 } catch (ee) { | |
| 327 // Any code that reaches this point is seriously nasty! | |
| 328 line = "<error>"; | |
| 329 } | |
| 330 } | |
| 331 lines.push(" at " + line); | |
| 332 } | |
| 333 return %_Call(ArrayJoin, lines, "\n"); | |
| 334 } | |
| 335 | |
| 336 | |
| 337 function GetTypeName(receiver, requireConstructor) { | |
| 338 if (IS_NULL_OR_UNDEFINED(receiver)) return null; | |
| 339 if (IS_PROXY(receiver)) return "Proxy"; | |
| 340 return %GetConstructorName(receiver); | |
| 341 } | |
| 342 | |
| 343 function ErrorToString() { | 259 function ErrorToString() { |
| 344 if (!IS_RECEIVER(this)) { | 260 if (!IS_RECEIVER(this)) { |
| 345 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); | 261 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); |
| 346 } | 262 } |
| 347 | 263 |
| 348 var name = this.name; | 264 var name = this.name; |
| 349 name = IS_UNDEFINED(name) ? "Error" : TO_STRING(name); | 265 name = IS_UNDEFINED(name) ? "Error" : TO_STRING(name); |
| 350 | 266 |
| 351 var message = this.message; | 267 var message = this.message; |
| 352 message = IS_UNDEFINED(message) ? "" : TO_STRING(message); | 268 message = IS_UNDEFINED(message) ? "" : TO_STRING(message); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 370 | 286 |
| 371 function MakeTypeError(type, arg0, arg1, arg2) { | 287 function MakeTypeError(type, arg0, arg1, arg2) { |
| 372 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); | 288 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); |
| 373 } | 289 } |
| 374 | 290 |
| 375 function MakeURIError() { | 291 function MakeURIError() { |
| 376 return MakeGenericError(GlobalURIError, kURIMalformed); | 292 return MakeGenericError(GlobalURIError, kURIMalformed); |
| 377 } | 293 } |
| 378 | 294 |
| 379 %InstallToContext([ | 295 %InstallToContext([ |
| 380 "error_format_stack_trace", FormatStackTrace, | |
| 381 "get_stack_trace_line_fun", GetStackTraceLine, | 296 "get_stack_trace_line_fun", GetStackTraceLine, |
| 382 "make_error_function", MakeGenericError, | 297 "make_error_function", MakeGenericError, |
| 383 "make_range_error", MakeRangeError, | 298 "make_range_error", MakeRangeError, |
| 384 "make_type_error", MakeTypeError, | 299 "make_type_error", MakeTypeError, |
| 385 "message_get_column_number", GetColumnNumber, | 300 "message_get_column_number", GetColumnNumber, |
| 386 "message_get_line_number", GetLineNumber, | 301 "message_get_line_number", GetLineNumber, |
| 387 "message_get_source_line", GetSourceLine, | 302 "message_get_source_line", GetSourceLine, |
| 388 "no_side_effects_to_string_fun", NoSideEffectsToString, | 303 "no_side_effects_to_string_fun", NoSideEffectsToString, |
| 389 ]); | 304 ]); |
| 390 | 305 |
| 391 utils.Export(function(to) { | 306 utils.Export(function(to) { |
| 392 to.ErrorToString = ErrorToString; | 307 to.ErrorToString = ErrorToString; |
| 393 to.MakeError = MakeError; | 308 to.MakeError = MakeError; |
| 394 to.MakeRangeError = MakeRangeError; | 309 to.MakeRangeError = MakeRangeError; |
| 395 to.MakeSyntaxError = MakeSyntaxError; | 310 to.MakeSyntaxError = MakeSyntaxError; |
| 396 to.MakeTypeError = MakeTypeError; | 311 to.MakeTypeError = MakeTypeError; |
| 397 to.MakeURIError = MakeURIError; | 312 to.MakeURIError = MakeURIError; |
| 398 }); | 313 }); |
| 399 | 314 |
| 400 }); | 315 }); |
| OLD | NEW |