diff --git a/lib/htmlparser/htmlparser.js b/lib/htmlparser/htmlparser.js index 46a3da08313e..ab7241e48c30 100644 --- a/lib/htmlparser/htmlparser.js +++ b/lib/htmlparser/htmlparser.js @@ -118,7 +118,7 @@ } if ( html == last ) - throw "Parse Error: " + html; + throw new Error("Parse Error: ") + html; last = html; } diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 090cac87f433..8e5a766415ce 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -193,7 +193,7 @@ angular.mock.$Browser.prototype = { * * inject(function($log, $exceptionHandler, $timeout) { * $timeout(function() { $log.log(1); }); - * $timeout(function() { $log.log(2); throw 'banana peel'; }); + * $timeout(function() { $log.log(2); throw new Error('banana peel'); }); * $timeout(function() { $log.log(3); }); * expect($exceptionHandler.errors).toEqual([]); * expect($log.assertEmpty()); diff --git a/src/ngScenario/Application.js b/src/ngScenario/Application.js index 86e53ad7fca9..b83feaa06cae 100644 --- a/src/ngScenario/Application.js +++ b/src/ngScenario/Application.js @@ -35,7 +35,7 @@ angular.scenario.Application.prototype.getFrame_ = function() { angular.scenario.Application.prototype.getWindow_ = function() { var contentWindow = this.getFrame_().prop('contentWindow'); if (!contentWindow) { - throw 'Frame window is not accessible.'; + throw new Error('Frame window is not accessible.'); } return contentWindow; }; @@ -113,7 +113,7 @@ angular.scenario.Application.prototype.executeAction = function(action) { var self = this; var $window = this.getWindow_(); if (!$window.document) { - throw 'Sandbox Error: Application document not accessible.'; + throw new Error('Sandbox Error: Application document not accessible.'); } if (!$window.angular) { return action.call(this, $window, _jQuery($window.document)); diff --git a/src/ngScenario/ObjectModel.js b/src/ngScenario/ObjectModel.js index 84466f0952c8..b6fa82534d93 100644 --- a/src/ngScenario/ObjectModel.js +++ b/src/ngScenario/ObjectModel.js @@ -77,7 +77,7 @@ angular.scenario.ObjectModel = function(runner) { var it = self.getSpec(spec.id); var step = it.getLastStep(); if (step.name !== step.name) { - throw 'Events fired in the wrong order. Step names don\'t match.'; + throw new Error('Events fired in the wrong order. Step names don\'t match.'); } complete(step); diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index cff2ec5b0e7b..62658501652f 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -667,7 +667,7 @@ describe('injector', function() { it('should handle exceptions', function() { expect(function() { createInjector([function() { - throw 'MyError'; + throw new Error('MyError'); }], {}); }).toThrowMinErr('$injector', 'modulerr', /Failed to instantiate module .+ due to:\n.*MyError/); }); @@ -891,7 +891,7 @@ describe('injector', function() { it('should handle constructor exception', function() { expect(function() { - $injector.instantiate(function() { throw 'MyError'; }); + $injector.instantiate(function() { throw new Error('MyError'); }); }).toThrow('MyError'); }); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 253ae6e50028..73882595730d 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -528,11 +528,11 @@ describe('$compile', function() { it('should handle exceptions', function() { module(function($exceptionHandlerProvider) { $exceptionHandlerProvider.mode('log'); - directive('factoryError', function() { throw 'FactoryError'; }); + directive('factoryError', function() { throw new Error('FactoryError'); }); directive('templateError', - valueFn({ compile: function() { throw 'TemplateError'; } })); + valueFn({ compile: function() { throw new Error('TemplateError'); } })); directive('linkingError', - valueFn(function() { throw 'LinkingError'; })); + valueFn(function() { throw new Error('LinkingError'); })); }); inject(function($rootScope, $compile, $exceptionHandler) { element = $compile('
')($rootScope); diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 3c92625a1b43..f269dad4c7eb 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -479,7 +479,7 @@ describe('input', function() { it('should report error on assignment error', function() { expect(function() { var inputElm = helper.compileInput(''); - }).toThrowMinErr("$parse", "syntax", "Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw ''] starting at ['']."); + }).toThrowMinErr("$parse", "syntax", "Syntax Error: Token '''' is an unexpected token at column 7 of the expression [throw new Error(''] starting at [''].")); }); diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index ab4a9f43e878..b4ad036feaf8 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -30,7 +30,7 @@ describe('$http', function() { }); if ($exceptionHandler.errors.length) { - throw 'Unhandled exceptions trapped in $exceptionHandler!'; + throw new Error('Unhandled exceptions trapped in $exceptionHandler!'); } $rootScope.$digest(); diff --git a/test/ng/intervalSpec.js b/test/ng/intervalSpec.js index 2bc2de321a18..37eb4051755d 100644 --- a/test/ng/intervalSpec.js +++ b/test/ng/intervalSpec.js @@ -214,7 +214,7 @@ describe('$interval', function() { it('should delegate exception to the $exceptionHandler service', inject( function($interval, $exceptionHandler, $window) { - $interval(function() { throw "Test Error"; }, 1000); + $interval(function() { throw new Error("Test Error"); }, 1000); expect($exceptionHandler.errors).toEqual([]); $window.flush(1000); @@ -229,7 +229,7 @@ describe('$interval', function() { function($interval, $rootScope, $window) { var applySpy = spyOn($rootScope, '$apply').andCallThrough(); - $interval(function() { throw "Test Error"; }, 1000); + $interval(function() { throw new Error("Test Error"); }, 1000); expect(applySpy).not.toHaveBeenCalled(); $window.flush(1000); @@ -240,7 +240,7 @@ describe('$interval', function() { it('should still update the interval promise when an exception is thrown', inject(function($interval, $window) { var log = [], - promise = $interval(function() { throw "Some Error"; }, 1000); + promise = $interval(function() { throw new Error("Some Error"); }, 1000); promise.then(function(value) { log.push('promise success: ' + value); }, function(err) { log.push('promise error: ' + err); }, diff --git a/test/ng/parseSpec.js b/test/ng/parseSpec.js index 321cff48f93a..aa870b8939d6 100644 --- a/test/ng/parseSpec.js +++ b/test/ng/parseSpec.js @@ -2183,7 +2183,7 @@ describe('parser', function() { it('should short-circuit AND operator', function() { scope.run = function() { - throw "IT SHOULD NOT HAVE RUN"; + throw new Error("IT SHOULD NOT HAVE RUN"); }; expect(scope.$eval('false && run()')).toBe(false); expect(scope.$eval('false && true && run()')).toBe(false); @@ -2191,7 +2191,7 @@ describe('parser', function() { it('should short-circuit OR operator', function() { scope.run = function() { - throw "IT SHOULD NOT HAVE RUN"; + throw new Error("IT SHOULD NOT HAVE RUN"); }; expect(scope.$eval('true || run()')).toBe(true); expect(scope.$eval('true || false || run()')).toBe(true); diff --git a/test/ng/qSpec.js b/test/ng/qSpec.js index dbafc18fcfca..712e6e37ec4c 100644 --- a/test/ng/qSpec.js +++ b/test/ng/qSpec.js @@ -2099,7 +2099,7 @@ describe('q', function() { it('should still reject the promise, when exception is thrown in success handler, even if exceptionHandler rethrows', function() { - deferred.promise.then(function() { throw 'reject'; }).then(null, errorSpy); + deferred.promise.then(function() { throw new Error('reject'); }).then(null, errorSpy); deferred.resolve('resolve'); mockNextTick.flush(); expect(exceptionExceptionSpy).toHaveBeenCalled(); @@ -2108,7 +2108,7 @@ describe('q', function() { it('should still reject the promise, when exception is thrown in error handler, even if exceptionHandler rethrows', function() { - deferred.promise.then(null, function() { throw 'reject again'; }).then(null, errorSpy); + deferred.promise.then(null, function() { throw new Error('reject again'); }).then(null, errorSpy); deferred.reject('reject'); mockNextTick.flush(); expect(exceptionExceptionSpy).toHaveBeenCalled(); diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 3e405b2006b5..df5769b779fc 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -1589,7 +1589,7 @@ describe('Scope', function() { it('should pass thrown exceptions to $exceptionHandler', inject(function($rootScope, $browser, $exceptionHandler) { $rootScope.$applyAsync(function() { - throw 'OOPS'; + throw new Error('OOPS'); }); $browser.defer.flush(); @@ -1601,7 +1601,7 @@ describe('Scope', function() { it('should evaluate subsequent expressions after an exception is thrown', inject(function($rootScope, $browser) { $rootScope.$applyAsync(function() { - throw 'OOPS'; + throw new Error('OOPS'); }); $rootScope.$applyAsync('x = "All good!"'); @@ -1799,7 +1799,7 @@ describe('Scope', function() { it('should dispatch exceptions to the $exceptionHandler', inject(function($exceptionHandler) { - child.$on('myEvent', function() { throw 'bubbleException'; }); + child.$on('myEvent', function() { throw new Error('bubbleException'); }); grandChild.$emit('myEvent'); expect(log).toEqual('2>1>0>'); expect($exceptionHandler.errors).toEqual(['bubbleException']); diff --git a/test/ng/timeoutSpec.js b/test/ng/timeoutSpec.js index 2aed8b743a5f..39f2e58e47e7 100644 --- a/test/ng/timeoutSpec.js +++ b/test/ng/timeoutSpec.js @@ -161,7 +161,7 @@ describe('$timeout', function() { it('should delegate exception to the $exceptionHandler service', inject( function($timeout, $exceptionHandler) { - $timeout(function() { throw "Test Error"; }); + $timeout(function() { throw new Error("Test Error"); }); expect($exceptionHandler.errors).toEqual([]); $timeout.flush(); @@ -173,7 +173,7 @@ describe('$timeout', function() { function($timeout, $rootScope) { var applySpy = spyOn($rootScope, '$apply').andCallThrough(); - $timeout(function() { throw "Test Error"; }); + $timeout(function() { throw new Error("Test Error"); }); expect(applySpy).not.toHaveBeenCalled(); $timeout.flush(); @@ -183,7 +183,7 @@ describe('$timeout', function() { it('should reject the timeout promise when an exception is thrown in the timeout callback', inject(function($timeout, log) { - var promise = $timeout(function() { throw "Some Error"; }); + var promise = $timeout(function() { throw new Error("Some Error"); }); promise.then(log.fn('success'), function(reason) { log('error: ' + reason); }); $timeout.flush(); @@ -216,7 +216,7 @@ describe('$timeout', function() { // $browser.defer.cancel is only called on cancel if the deferred object is still referenced var cancelSpy = spyOn($browser.defer, 'cancel').andCallThrough(); - var promise = $timeout(function() { throw "Test Error"; }, 0, false); + var promise = $timeout(function() { throw new Error("Test Error"); }, 0, false); $timeout.flush(); expect(cancelSpy).not.toHaveBeenCalled(); diff --git a/test/ngCookies/cookieWriterSpec.js b/test/ngCookies/cookieWriterSpec.js index e94f2b16e7c7..57bd5d893e16 100644 --- a/test/ngCookies/cookieWriterSpec.js +++ b/test/ngCookies/cookieWriterSpec.js @@ -141,7 +141,7 @@ describe('cookie options', function() { if (prev === undefined) { return pair[1] === undefined ? true : pair[1]; } else { - throw 'duplicate key in cookie string'; + throw new Error('duplicate key in cookie string'); } } else { return prev; diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index f9c7587e86cc..16fed1c5815b 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -424,7 +424,7 @@ describe('ngMock', function() { it('should delegate exception to the $exceptionHandler service', inject( function($interval, $exceptionHandler) { - $interval(function() { throw "Test Error"; }, 1000); + $interval(function() { throw new Error("Test Error"); }, 1000); expect($exceptionHandler.errors).toEqual([]); $interval.flush(1000); @@ -439,7 +439,7 @@ describe('ngMock', function() { function($interval, $rootScope) { var applySpy = spyOn($rootScope, '$apply').andCallThrough(); - $interval(function() { throw "Test Error"; }, 1000); + $interval(function() { throw new Error("Test Error"); }, 1000); expect(applySpy).not.toHaveBeenCalled(); $interval.flush(1000); @@ -450,7 +450,7 @@ describe('ngMock', function() { it('should still update the interval promise when an exception is thrown', inject(function($interval) { var log = [], - promise = $interval(function() { throw "Some Error"; }, 1000); + promise = $interval(function() { throw new Error("Some Error"); }, 1000); promise.then(function(value) { log.push('promise success: ' + value); }, function(err) { log.push('promise error: ' + err); }, @@ -921,7 +921,7 @@ describe('ngMock', function() { it('should not change thrown strings', inject(function($sniffer) { expect(function() { inject(function() { - throw 'test message'; + throw new Error('test message'); }); }).toThrow('test message'); })); diff --git a/test/ngScenario/SpecRunnerSpec.js b/test/ngScenario/SpecRunnerSpec.js index 6a207450b5f7..2e102ae2ea98 100644 --- a/test/ngScenario/SpecRunnerSpec.js +++ b/test/ngScenario/SpecRunnerSpec.js @@ -94,7 +94,7 @@ describe('angular.scenario.SpecRunner', function() { it('should execute notify UI on spec setup error', function() { var finished; var spec = createSpec('test spec', function() { - throw 'message'; + throw new Error('message'); }); runner.run(spec, function() { finished = true; @@ -130,7 +130,7 @@ describe('angular.scenario.SpecRunner', function() { var finished; var spec = createSpec('test spec', function() { this.addFuture('test future', function(done) { - throw 'error message'; + throw new Error('error message'); }); }); runner.run(spec, function() { @@ -150,7 +150,7 @@ describe('angular.scenario.SpecRunner', function() { var finished, after; var spec = createSpec('test spec', function() { this.addFuture('body', function(done) { - throw 'error message'; + throw new Error('error message'); }); }); spec.after = function() {