fix($injector): ensure functions with overridden toString() are annotated properly

Closes #14361
This commit is contained in:
a510
2016-04-01 23:13:35 +02:00
committed by Georgios Kalpakas
parent 74eb4684dc
commit a0b5e1a858
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var $injectorMinErr = minErr('$injector');
function extractArgs(fn) {
var fnText = fn.toString().replace(STRIP_COMMENTS, ''),
var fnText = Function.prototype.toString.call(fn).replace(STRIP_COMMENTS, ''),
args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
return args;
}
+6
View File
@@ -241,6 +241,12 @@ describe('injector', function() {
expect($f_n0.$inject).toEqual(['$a_']);
});
it('should handle functions with overridden toString', function() {
function fn(a) {}
fn.toString = function() { return 'fn'; };
expect(annotate(fn)).toEqual(['a']);
expect(fn.$inject).toEqual(['a']);
});
it('should throw on non function arg', function() {
expect(function() {