|
37 | 37 | modern: function(target, constructor) { |
38 | 38 | Error.captureStackTrace(target, constructor); |
39 | 39 | }, |
40 | | - legancy: function(target, constructor, exception) { |
41 | | - target.stack = (new exception()).stack; |
| 40 | + fixLegancyStackTrace: function(stack, stringified) { |
| 41 | + var st = stack; |
| 42 | + if (typeof(stack) !== 'string') { |
| 43 | + // On IE the stack field is empty so setting to toString() :-/ |
| 44 | + st = stringified; |
| 45 | + } |
| 46 | + // Hands down, if all fails, just replace Error with nice Eid string |
| 47 | + if (st.indexOf(stringified) < 0) { |
| 48 | + st = st.replace(/^(?:Error\n)?/, stringified + "\n").trim(); |
| 49 | + } |
| 50 | + return st; |
| 51 | + }, |
| 52 | + legancy: function(target, constructor, exceptionConstructor) { |
| 53 | + // Hacks for IE an Edge |
| 54 | + var stringified = target.toString(); |
| 55 | + // try to fetch stacktrace from JS standard Error |
| 56 | + var st = (new exceptionConstructor()).stack; |
| 57 | + target.stack = CorrectStackTrace.fixLegancyStackTrace(st, stringified); |
42 | 58 | } |
43 | 59 | }; |
| 60 | + CorrectStackTrace.fixLegancyStackTrace('Error\n'); |
44 | 61 | CorrectStackTrace.legancy({}, null, Object); |
45 | 62 |
|
46 | 63 | var correctStackTrace = function(target, constructor) { |
|
73 | 90 | var tmp = Error.apply(this, [message]); |
74 | 91 | tmp.name = this.name = 'EidRuntimeException'; |
75 | 92 | this.message = tmp.message; |
| 93 | + this.eid = eid; |
76 | 94 | correctStackTrace(this, EidRuntimeException); |
77 | 95 |
|
78 | 96 | return this; |
79 | 97 | } |
80 | | - var IntermediateInheritor = function() {}; |
81 | | - IntermediateInheritor.prototype = Error.prototype; |
82 | | - EidRuntimeException.prototype = new IntermediateInheritor(); |
| 98 | + EidRuntimeException.prototype = Object.create(Error.prototype, { |
| 99 | + constructor: { value: EidRuntimeException } |
| 100 | + }); |
83 | 101 |
|
84 | 102 | /** |
85 | 103 | * <strong>This class shouldn't be used in any public API or library.</strong> It is designed to be used for in-house development |
|
0 commit comments