fix(ngMock window.inject): Remove Error 'stack' property changes · angular/angular.js@7e91645 (original) (raw)
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree
2 files changed
lines changed
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2079,6 +2079,20 @@ if(window.jasmine | | window.mocha) { | |
2079 | 2079 | * |
2080 | 2080 | * @param {...Function} fns any number of functions which will be injected using the injector. |
2081 | 2081 | */ |
2082 | + | |
2083 | + | |
2084 | + | |
2085 | +var ErrorAddingDeclarationLocationStack = function(e, errorForStack) { | |
2086 | +this.message = e.message; | |
2087 | +this.name = e.name; | |
2088 | +if (e.line) this.line = e.line; | |
2089 | +if (e.sourceId) this.sourceId = e.sourceId; | |
2090 | +if (e.stack && errorForStack) | |
2091 | +this.stack = e.stack + '\n' + errorForStack.stack; | |
2092 | +if (e.stackArray) this.stackArray = e.stackArray; | |
2093 | +}; | |
2094 | +ErrorAddingDeclarationLocationStack.prototype.toString = Error.prototype.toString; | |
2095 | + | |
2082 | 2096 | window.inject = angular.mock.inject = function() { |
2083 | 2097 | var blockFns = Array.prototype.slice.call(arguments, 0); |
2084 | 2098 | var errorForStack = new Error('Declaration Location'); |
@@ -2099,7 +2113,9 @@ if(window.jasmine | | window.mocha) { | |
2099 | 2113 | injector.invoke(blockFns[i] | |
2100 | 2114 | /* jshint +W040 */ |
2101 | 2115 | } catch (e) { |
2102 | -if(e.stack && errorForStack) e.stack += '\n' + errorForStack.stack; | |
2116 | +if (e.stack && errorForStack) { | |
2117 | +throw new ErrorAddingDeclarationLocationStack(e, errorForStack); | |
2118 | +} | |
2103 | 2119 | throw e; |
2104 | 2120 | } finally { |
2105 | 2121 | errorForStack = null; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -862,6 +862,23 @@ describe('ngMock', function() { | ||
862 | 862 | expect(log).toEqual('module;inject;') |
863 | 863 | }); |
864 | 864 | }); |
865 | + | |
866 | +// We don't run the following tests on IE8. | |
867 | +// IE8 throws "Object does not support this property or method." error, | |
868 | +// when thrown from a function defined on window (which `inject` is). | |
869 | +if (msie <= 8) return; | |
870 | + | |
871 | +it('should not change thrown Errors', function() { | |
872 | +expect(function(){ | |
873 | +throw new Error('test message'); | |
874 | +}).toThrow('test message'); | |
875 | +}); | |
876 | + | |
877 | +it('should not change thrown strings', function(){ | |
878 | +expect(function(){ | |
879 | +throw 'test message'; | |
880 | +}).toThrow('test message'); | |
881 | +}); | |
865 | 882 | }); |
866 | 883 | }); |
867 | 884 |