Skip to content

Commit a0b5e1a

Browse files
a510gkalpak
authored andcommitted
fix($injector): ensure functions with overridden toString() are annotated properly
Closes angular#14361
1 parent 74eb468 commit a0b5e1a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/auto/injector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
7171
var $injectorMinErr = minErr('$injector');
7272

7373
function extractArgs(fn) {
74-
var fnText = fn.toString().replace(STRIP_COMMENTS, ''),
74+
var fnText = Function.prototype.toString.call(fn).replace(STRIP_COMMENTS, ''),
7575
args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
7676
return args;
7777
}

test/auto/injectorSpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ describe('injector', function() {
241241
expect($f_n0.$inject).toEqual(['$a_']);
242242
});
243243

244+
it('should handle functions with overridden toString', function() {
245+
function fn(a) {}
246+
fn.toString = function() { return 'fn'; };
247+
expect(annotate(fn)).toEqual(['a']);
248+
expect(fn.$inject).toEqual(['a']);
249+
});
244250

245251
it('should throw on non function arg', function() {
246252
expect(function() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy