fix($injector): ensure functions with overridden toString() are annotated properly
Closes #14361
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user