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