aboutsummaryrefslogtreecommitdiffstats
path: root/src/ngMock
diff options
context:
space:
mode:
authorAndrew C. Greenberg2013-11-19 22:53:33 -0800
committerVojta Jina2014-01-06 17:47:06 -0800
commit7e916455b36dc9ca4d4afc1e44cade90006d00e3 (patch)
tree8ab5de74af9a1768665103b3fe1859ed08493833 /src/ngMock
parentcdc4d485a6daa0c74e5d07d8def2a3ee68d93d13 (diff)
downloadangular.js-7e916455b36dc9ca4d4afc1e44cade90006d00e3.tar.bz2
fix(ngMock window.inject): Remove Error 'stack' property changes
Recent browsers, particularly PhantomJS 1.9.2 and Safari 7.0 treat the stack property as non-configurable and unwritable. Because window.inject captures the stack at the time of the inject, and attempts to insert it into a captured throw from the injected function by modifying e.stack, a meaningless error message and stack is thrown instead. This commit inserts two tests exposing the problem, and implements a proposed solution that builds a new error-like object that mimicks the old Error object, but with the additional stack information, and captures the toString function from the Error object prototype. This appears to work for the browsers suppoerted here.
Diffstat (limited to 'src/ngMock')
-rw-r--r--src/ngMock/angular-mocks.js18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js
index fb7ef057..b53b4e02 100644
--- a/src/ngMock/angular-mocks.js
+++ b/src/ngMock/angular-mocks.js
@@ -2079,6 +2079,20 @@ if(window.jasmine || window.mocha) {
*
* @param {...Function} fns any number of functions which will be injected using the injector.
*/
+
+
+
+ var ErrorAddingDeclarationLocationStack = function(e, errorForStack) {
+ this.message = e.message;
+ this.name = e.name;
+ if (e.line) this.line = e.line;
+ if (e.sourceId) this.sourceId = e.sourceId;
+ if (e.stack && errorForStack)
+ this.stack = e.stack + '\n' + errorForStack.stack;
+ if (e.stackArray) this.stackArray = e.stackArray;
+ };
+ ErrorAddingDeclarationLocationStack.prototype.toString = Error.prototype.toString;
+
window.inject = angular.mock.inject = function() {
var blockFns = Array.prototype.slice.call(arguments, 0);
var errorForStack = new Error('Declaration Location');
@@ -2099,7 +2113,9 @@ if(window.jasmine || window.mocha) {
injector.invoke(blockFns[i] || angular.noop, this);
/* jshint +W040 */
} catch (e) {
- if(e.stack && errorForStack) e.stack += '\n' + errorForStack.stack;
+ if (e.stack && errorForStack) {
+ throw new ErrorAddingDeclarationLocationStack(e, errorForStack);
+ }
throw e;
} finally {
errorForStack = null;