| 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 12 matching lines...) Expand all Loading... |
| 23 utils.ImportNow("call_site_function_symbol"); | 23 utils.ImportNow("call_site_function_symbol"); |
| 24 var callSitePositionSymbol = | 24 var callSitePositionSymbol = |
| 25 utils.ImportNow("call_site_position_symbol"); | 25 utils.ImportNow("call_site_position_symbol"); |
| 26 var callSiteStrictSymbol = | 26 var callSiteStrictSymbol = |
| 27 utils.ImportNow("call_site_strict_symbol"); | 27 utils.ImportNow("call_site_strict_symbol"); |
| 28 var callSiteWasmObjectSymbol = | 28 var callSiteWasmObjectSymbol = |
| 29 utils.ImportNow("call_site_wasm_obj_symbol"); | 29 utils.ImportNow("call_site_wasm_obj_symbol"); |
| 30 var callSiteWasmFunctionIndexSymbol = | 30 var callSiteWasmFunctionIndexSymbol = |
| 31 utils.ImportNow("call_site_wasm_func_index_symbol"); | 31 utils.ImportNow("call_site_wasm_func_index_symbol"); |
| 32 var Float32x4ToString; | 32 var Float32x4ToString; |
| 33 var formattedStackTraceSymbol = | |
| 34 utils.ImportNow("formatted_stack_trace_symbol"); | |
| 35 var GlobalObject = global.Object; | 33 var GlobalObject = global.Object; |
| 34 var GlobalError = global.Error; |
| 35 var GlobalEvalError = global.EvalError; |
| 36 var GlobalRangeError = global.RangeError; |
| 37 var GlobalReferenceError = global.ReferenceError; |
| 38 var GlobalSyntaxError = global.SyntaxError; |
| 39 var GlobalTypeError = global.TypeError; |
| 40 var GlobalURIError = global.URIError; |
| 36 var Int16x8ToString; | 41 var Int16x8ToString; |
| 37 var Int32x4ToString; | 42 var Int32x4ToString; |
| 38 var Int8x16ToString; | 43 var Int8x16ToString; |
| 39 var InternalArray = utils.InternalArray; | 44 var InternalArray = utils.InternalArray; |
| 40 var internalErrorSymbol = utils.ImportNow("internal_error_symbol"); | 45 var internalErrorSymbol = utils.ImportNow("internal_error_symbol"); |
| 41 var ObjectHasOwnProperty; | 46 var ObjectHasOwnProperty; |
| 42 var ObjectToString = utils.ImportNow("object_to_string"); | 47 var ObjectToString = utils.ImportNow("object_to_string"); |
| 43 var Script = utils.ImportNow("Script"); | 48 var Script = utils.ImportNow("Script"); |
| 44 var stackTraceSymbol = utils.ImportNow("stack_trace_symbol"); | 49 var stackTraceSymbol = utils.ImportNow("stack_trace_symbol"); |
| 45 var StringIndexOf; | 50 var StringIndexOf; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 59 Int8x16ToString = from.Int8x16ToString; | 64 Int8x16ToString = from.Int8x16ToString; |
| 60 ObjectHasOwnProperty = from.ObjectHasOwnProperty; | 65 ObjectHasOwnProperty = from.ObjectHasOwnProperty; |
| 61 StringIndexOf = from.StringIndexOf; | 66 StringIndexOf = from.StringIndexOf; |
| 62 Uint16x8ToString = from.Uint16x8ToString; | 67 Uint16x8ToString = from.Uint16x8ToString; |
| 63 Uint32x4ToString = from.Uint32x4ToString; | 68 Uint32x4ToString = from.Uint32x4ToString; |
| 64 Uint8x16ToString = from.Uint8x16ToString; | 69 Uint8x16ToString = from.Uint8x16ToString; |
| 65 }); | 70 }); |
| 66 | 71 |
| 67 // ------------------------------------------------------------------- | 72 // ------------------------------------------------------------------- |
| 68 | 73 |
| 69 var GlobalError; | |
| 70 var GlobalTypeError; | |
| 71 var GlobalRangeError; | |
| 72 var GlobalURIError; | |
| 73 var GlobalSyntaxError; | |
| 74 var GlobalReferenceError; | |
| 75 var GlobalEvalError; | |
| 76 | 74 |
| 77 | 75 |
| 78 function NoSideEffectsObjectToString() { | 76 function NoSideEffectsObjectToString() { |
| 79 if (IS_UNDEFINED(this)) return "[object Undefined]"; | 77 if (IS_UNDEFINED(this)) return "[object Undefined]"; |
| 80 if (IS_NULL(this)) return "[object Null]"; | 78 if (IS_NULL(this)) return "[object Null]"; |
| 81 var O = TO_OBJECT(this); | 79 var O = TO_OBJECT(this); |
| 82 var builtinTag = %_ClassOf(O); | 80 var builtinTag = %_ClassOf(O); |
| 83 var tag = %GetDataProperty(O, toStringTagSymbol); | 81 var tag = %GetDataProperty(O, toStringTagSymbol); |
| 84 if (!IS_STRING(tag)) { | 82 if (!IS_STRING(tag)) { |
| 85 tag = builtinTag; | 83 tag = builtinTag; |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 return %_Call(ArrayJoin, lines, "\n"); | 594 return %_Call(ArrayJoin, lines, "\n"); |
| 597 } | 595 } |
| 598 | 596 |
| 599 | 597 |
| 600 function GetTypeName(receiver, requireConstructor) { | 598 function GetTypeName(receiver, requireConstructor) { |
| 601 if (IS_NULL_OR_UNDEFINED(receiver)) return null; | 599 if (IS_NULL_OR_UNDEFINED(receiver)) return null; |
| 602 if (IS_PROXY(receiver)) return "Proxy"; | 600 if (IS_PROXY(receiver)) return "Proxy"; |
| 603 return %GetConstructorName(receiver); | 601 return %GetConstructorName(receiver); |
| 604 } | 602 } |
| 605 | 603 |
| 606 | |
| 607 // Format the stack trace if not yet done, and return it. | |
| 608 // Cache the formatted stack trace on the holder. | |
| 609 var StackTraceGetter = function() { | |
| 610 var formatted_stack_trace = UNDEFINED; | |
| 611 var holder = this; | |
| 612 while (holder) { | |
| 613 var formatted_stack_trace = | |
| 614 GET_PRIVATE(holder, formattedStackTraceSymbol); | |
| 615 if (IS_UNDEFINED(formatted_stack_trace)) { | |
| 616 // No formatted stack trace available. | |
| 617 var stack_trace = GET_PRIVATE(holder, stackTraceSymbol); | |
| 618 if (IS_UNDEFINED(stack_trace)) { | |
| 619 // Neither formatted nor structured stack trace available. | |
| 620 // Look further up the prototype chain. | |
| 621 holder = %object_get_prototype_of(holder); | |
| 622 continue; | |
| 623 } | |
| 624 formatted_stack_trace = FormatStackTrace(holder, stack_trace); | |
| 625 SET_PRIVATE(holder, stackTraceSymbol, UNDEFINED); | |
| 626 SET_PRIVATE(holder, formattedStackTraceSymbol, formatted_stack_trace); | |
| 627 } | |
| 628 return formatted_stack_trace; | |
| 629 } | |
| 630 return UNDEFINED; | |
| 631 }; | |
| 632 | |
| 633 | |
| 634 // If the receiver equals the holder, set the formatted stack trace that the | |
| 635 // getter returns. | |
| 636 var StackTraceSetter = function(v) { | |
| 637 if (IsErrorObject(this)) { | |
| 638 SET_PRIVATE(this, stackTraceSymbol, UNDEFINED); | |
| 639 SET_PRIVATE(this, formattedStackTraceSymbol, v); | |
| 640 } | |
| 641 }; | |
| 642 | |
| 643 | |
| 644 // Use a dummy function since we do not actually want to capture a stack trace | |
| 645 // when constructing the initial Error prototytpes. | |
| 646 var captureStackTrace = function() {}; | |
| 647 | |
| 648 | |
| 649 // Set up special error type constructors. | |
| 650 function SetUpError(error_function) { | |
| 651 %FunctionSetInstanceClassName(error_function, 'Error'); | |
| 652 var name = error_function.name; | |
| 653 var prototype = new GlobalObject(); | |
| 654 if (name !== 'Error') { | |
| 655 %InternalSetPrototype(error_function, GlobalError); | |
| 656 %InternalSetPrototype(prototype, GlobalError.prototype); | |
| 657 } | |
| 658 %FunctionSetPrototype(error_function, prototype); | |
| 659 | |
| 660 %AddNamedProperty(error_function.prototype, 'name', name, DONT_ENUM); | |
| 661 %AddNamedProperty(error_function.prototype, 'message', '', DONT_ENUM); | |
| 662 %AddNamedProperty( | |
| 663 error_function.prototype, 'constructor', error_function, DONT_ENUM); | |
| 664 | |
| 665 %SetCode(error_function, function(m) { | |
| 666 if (IS_UNDEFINED(new.target)) return new error_function(m); | |
| 667 | |
| 668 try { captureStackTrace(this, error_function); } catch (e) { } | |
| 669 // Define all the expected properties directly on the error | |
| 670 // object. This avoids going through getters and setters defined | |
| 671 // on prototype objects. | |
| 672 if (!IS_UNDEFINED(m)) { | |
| 673 %AddNamedProperty(this, 'message', TO_STRING(m), DONT_ENUM); | |
| 674 } | |
| 675 }); | |
| 676 | |
| 677 %SetNativeFlag(error_function); | |
| 678 return error_function; | |
| 679 }; | |
| 680 | |
| 681 GlobalError = SetUpError(global.Error); | |
| 682 GlobalEvalError = SetUpError(global.EvalError); | |
| 683 GlobalRangeError = SetUpError(global.RangeError); | |
| 684 GlobalReferenceError = SetUpError(global.ReferenceError); | |
| 685 GlobalSyntaxError = SetUpError(global.SyntaxError); | |
| 686 GlobalTypeError = SetUpError(global.TypeError); | |
| 687 GlobalURIError = SetUpError(global.URIError); | |
| 688 | |
| 689 utils.InstallFunctions(GlobalError.prototype, DONT_ENUM, | |
| 690 ['toString', ErrorToString]); | |
| 691 | |
| 692 function ErrorToString() { | 604 function ErrorToString() { |
| 693 if (!IS_RECEIVER(this)) { | 605 if (!IS_RECEIVER(this)) { |
| 694 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); | 606 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); |
| 695 } | 607 } |
| 696 | 608 |
| 697 var name = this.name; | 609 var name = this.name; |
| 698 name = IS_UNDEFINED(name) ? "Error" : TO_STRING(name); | 610 name = IS_UNDEFINED(name) ? "Error" : TO_STRING(name); |
| 699 | 611 |
| 700 var message = this.message; | 612 var message = this.message; |
| 701 message = IS_UNDEFINED(message) ? "" : TO_STRING(message); | 613 message = IS_UNDEFINED(message) ? "" : TO_STRING(message); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 721 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); | 633 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); |
| 722 } | 634 } |
| 723 | 635 |
| 724 function MakeURIError() { | 636 function MakeURIError() { |
| 725 return MakeGenericError(GlobalURIError, kURIMalformed); | 637 return MakeGenericError(GlobalURIError, kURIMalformed); |
| 726 } | 638 } |
| 727 | 639 |
| 728 // Boilerplate for exceptions for stack overflows. Used from | 640 // Boilerplate for exceptions for stack overflows. Used from |
| 729 // Isolate::StackOverflow(). | 641 // Isolate::StackOverflow(). |
| 730 var StackOverflowBoilerplate = MakeRangeError(kStackOverflow); | 642 var StackOverflowBoilerplate = MakeRangeError(kStackOverflow); |
| 731 utils.InstallGetterSetter(StackOverflowBoilerplate, 'stack', | |
| 732 StackTraceGetter, StackTraceSetter) | |
| 733 | |
| 734 // Define actual captureStackTrace function after everything has been set up. | |
| 735 captureStackTrace = function captureStackTrace(obj, cons_opt) { | |
| 736 // Define accessors first, as this may fail and throw. | |
| 737 %object_define_property(obj, 'stack', { get: StackTraceGetter, | |
| 738 set: StackTraceSetter, | |
| 739 configurable: true }); | |
| 740 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); | |
| 741 }; | |
| 742 | |
| 743 GlobalError.captureStackTrace = captureStackTrace; | |
| 744 | 643 |
| 745 %InstallToContext([ | 644 %InstallToContext([ |
| 645 "error_format_stack_trace", FormatStackTrace, |
| 746 "get_stack_trace_line_fun", GetStackTraceLine, | 646 "get_stack_trace_line_fun", GetStackTraceLine, |
| 747 "make_error_function", MakeGenericError, | 647 "make_error_function", MakeGenericError, |
| 748 "make_range_error", MakeRangeError, | 648 "make_range_error", MakeRangeError, |
| 749 "make_type_error", MakeTypeError, | 649 "make_type_error", MakeTypeError, |
| 750 "message_get_column_number", GetColumnNumber, | 650 "message_get_column_number", GetColumnNumber, |
| 751 "message_get_line_number", GetLineNumber, | 651 "message_get_line_number", GetLineNumber, |
| 752 "message_get_source_line", GetSourceLine, | 652 "message_get_source_line", GetSourceLine, |
| 753 "no_side_effects_to_string_fun", NoSideEffectsToString, | 653 "no_side_effects_to_string_fun", NoSideEffectsToString, |
| 754 "stack_overflow_boilerplate", StackOverflowBoilerplate, | 654 "stack_overflow_boilerplate", StackOverflowBoilerplate, |
| 755 ]); | 655 ]); |
| 756 | 656 |
| 757 utils.Export(function(to) { | 657 utils.Export(function(to) { |
| 758 to.ErrorToString = ErrorToString; | 658 to.ErrorToString = ErrorToString; |
| 759 to.MakeError = MakeError; | 659 to.MakeError = MakeError; |
| 760 to.MakeRangeError = MakeRangeError; | 660 to.MakeRangeError = MakeRangeError; |
| 761 to.MakeSyntaxError = MakeSyntaxError; | 661 to.MakeSyntaxError = MakeSyntaxError; |
| 762 to.MakeTypeError = MakeTypeError; | 662 to.MakeTypeError = MakeTypeError; |
| 763 to.MakeURIError = MakeURIError; | 663 to.MakeURIError = MakeURIError; |
| 764 }); | 664 }); |
| 765 | 665 |
| 766 }); | 666 }); |
| OLD | NEW |