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

Side by Side Diff: src/js/messages.js

Issue 2159223004: Revert of Move Error methods to C++ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « src/isolate.cc ('k') | src/runtime/runtime.h » ('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 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
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");
33 var GlobalObject = global.Object; 35 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;
41 var Int16x8ToString; 36 var Int16x8ToString;
42 var Int32x4ToString; 37 var Int32x4ToString;
43 var Int8x16ToString; 38 var Int8x16ToString;
44 var InternalArray = utils.InternalArray; 39 var InternalArray = utils.InternalArray;
45 var internalErrorSymbol = utils.ImportNow("internal_error_symbol"); 40 var internalErrorSymbol = utils.ImportNow("internal_error_symbol");
46 var ObjectHasOwnProperty; 41 var ObjectHasOwnProperty;
47 var ObjectToString = utils.ImportNow("object_to_string"); 42 var ObjectToString = utils.ImportNow("object_to_string");
48 var Script = utils.ImportNow("Script"); 43 var Script = utils.ImportNow("Script");
49 var stackTraceSymbol = utils.ImportNow("stack_trace_symbol"); 44 var stackTraceSymbol = utils.ImportNow("stack_trace_symbol");
50 var StringIndexOf; 45 var StringIndexOf;
(...skipping 13 matching lines...) Expand all
64 Int8x16ToString = from.Int8x16ToString; 59 Int8x16ToString = from.Int8x16ToString;
65 ObjectHasOwnProperty = from.ObjectHasOwnProperty; 60 ObjectHasOwnProperty = from.ObjectHasOwnProperty;
66 StringIndexOf = from.StringIndexOf; 61 StringIndexOf = from.StringIndexOf;
67 Uint16x8ToString = from.Uint16x8ToString; 62 Uint16x8ToString = from.Uint16x8ToString;
68 Uint32x4ToString = from.Uint32x4ToString; 63 Uint32x4ToString = from.Uint32x4ToString;
69 Uint8x16ToString = from.Uint8x16ToString; 64 Uint8x16ToString = from.Uint8x16ToString;
70 }); 65 });
71 66
72 // ------------------------------------------------------------------- 67 // -------------------------------------------------------------------
73 68
69 var GlobalError;
70 var GlobalTypeError;
71 var GlobalRangeError;
72 var GlobalURIError;
73 var GlobalSyntaxError;
74 var GlobalReferenceError;
75 var GlobalEvalError;
74 76
75 77
76 function NoSideEffectsObjectToString() { 78 function NoSideEffectsObjectToString() {
77 if (IS_UNDEFINED(this)) return "[object Undefined]"; 79 if (IS_UNDEFINED(this)) return "[object Undefined]";
78 if (IS_NULL(this)) return "[object Null]"; 80 if (IS_NULL(this)) return "[object Null]";
79 var O = TO_OBJECT(this); 81 var O = TO_OBJECT(this);
80 var builtinTag = %_ClassOf(O); 82 var builtinTag = %_ClassOf(O);
81 var tag = %GetDataProperty(O, toStringTagSymbol); 83 var tag = %GetDataProperty(O, toStringTagSymbol);
82 if (!IS_STRING(tag)) { 84 if (!IS_STRING(tag)) {
83 tag = builtinTag; 85 tag = builtinTag;
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 return %_Call(ArrayJoin, lines, "\n"); 596 return %_Call(ArrayJoin, lines, "\n");
595 } 597 }
596 598
597 599
598 function GetTypeName(receiver, requireConstructor) { 600 function GetTypeName(receiver, requireConstructor) {
599 if (IS_NULL_OR_UNDEFINED(receiver)) return null; 601 if (IS_NULL_OR_UNDEFINED(receiver)) return null;
600 if (IS_PROXY(receiver)) return "Proxy"; 602 if (IS_PROXY(receiver)) return "Proxy";
601 return %GetConstructorName(receiver); 603 return %GetConstructorName(receiver);
602 } 604 }
603 605
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
604 function ErrorToString() { 692 function ErrorToString() {
605 if (!IS_RECEIVER(this)) { 693 if (!IS_RECEIVER(this)) {
606 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); 694 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString");
607 } 695 }
608 696
609 var name = this.name; 697 var name = this.name;
610 name = IS_UNDEFINED(name) ? "Error" : TO_STRING(name); 698 name = IS_UNDEFINED(name) ? "Error" : TO_STRING(name);
611 699
612 var message = this.message; 700 var message = this.message;
613 message = IS_UNDEFINED(message) ? "" : TO_STRING(message); 701 message = IS_UNDEFINED(message) ? "" : TO_STRING(message);
(...skipping 19 matching lines...) Expand all
633 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); 721 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2);
634 } 722 }
635 723
636 function MakeURIError() { 724 function MakeURIError() {
637 return MakeGenericError(GlobalURIError, kURIMalformed); 725 return MakeGenericError(GlobalURIError, kURIMalformed);
638 } 726 }
639 727
640 // Boilerplate for exceptions for stack overflows. Used from 728 // Boilerplate for exceptions for stack overflows. Used from
641 // Isolate::StackOverflow(). 729 // Isolate::StackOverflow().
642 var StackOverflowBoilerplate = MakeRangeError(kStackOverflow); 730 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;
643 744
644 %InstallToContext([ 745 %InstallToContext([
645 "error_format_stack_trace", FormatStackTrace,
646 "get_stack_trace_line_fun", GetStackTraceLine, 746 "get_stack_trace_line_fun", GetStackTraceLine,
647 "make_error_function", MakeGenericError, 747 "make_error_function", MakeGenericError,
648 "make_range_error", MakeRangeError, 748 "make_range_error", MakeRangeError,
649 "make_type_error", MakeTypeError, 749 "make_type_error", MakeTypeError,
650 "message_get_column_number", GetColumnNumber, 750 "message_get_column_number", GetColumnNumber,
651 "message_get_line_number", GetLineNumber, 751 "message_get_line_number", GetLineNumber,
652 "message_get_source_line", GetSourceLine, 752 "message_get_source_line", GetSourceLine,
653 "no_side_effects_to_string_fun", NoSideEffectsToString, 753 "no_side_effects_to_string_fun", NoSideEffectsToString,
654 "stack_overflow_boilerplate", StackOverflowBoilerplate, 754 "stack_overflow_boilerplate", StackOverflowBoilerplate,
655 ]); 755 ]);
656 756
657 utils.Export(function(to) { 757 utils.Export(function(to) {
658 to.ErrorToString = ErrorToString; 758 to.ErrorToString = ErrorToString;
659 to.MakeError = MakeError; 759 to.MakeError = MakeError;
660 to.MakeRangeError = MakeRangeError; 760 to.MakeRangeError = MakeRangeError;
661 to.MakeSyntaxError = MakeSyntaxError; 761 to.MakeSyntaxError = MakeSyntaxError;
662 to.MakeTypeError = MakeTypeError; 762 to.MakeTypeError = MakeTypeError;
663 to.MakeURIError = MakeURIError; 763 to.MakeURIError = MakeURIError;
664 }); 764 });
665 765
666 }); 766 });
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698