fix($injector): add workaround for class stringification in Chrome v50/51

Partially fixes #14240.

Closes #14531
This commit is contained in:
Georgios Kalpakas
2016-04-28 13:16:01 +03:00
parent 3dcc01646a
commit afcedff34c
2 changed files with 28 additions and 3 deletions
+7 -3
View File
@@ -70,12 +70,16 @@ var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var $injectorMinErr = minErr('$injector');
function extractArgs(fn) {
function stringifyFn(fn) {
// Support: Chrome 50-51 only
// Creating a new string by adding `' '` at the end, to hack around some bug in Chrome v50/51
// (See https://github.com/angular/angular.js/issues/14487.)
// TODO (gkalpak): Remove workaround when Chrome v52 is released
var fnText = Function.prototype.toString.call(fn).replace(STRIP_COMMENTS, '') + ' ',
return Function.prototype.toString.call(fn) + ' ';
}
function extractArgs(fn) {
var fnText = stringifyFn(fn).replace(STRIP_COMMENTS, ''),
args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
return args;
}
@@ -849,7 +853,7 @@ function createInjector(modulesToLoad, strictDi) {
if (!isBoolean(result)) {
// Workaround for MS Edge.
// Check https://connect.microsoft.com/IE/Feedback/Details/2211653
result = func.$$ngIsClass = /^(?:class\s|constructor\()/.test(Function.prototype.toString.call(func));
result = func.$$ngIsClass = /^(?:class\s|constructor\()/.test(stringifyFn(func));
}
return result;
}
+21
View File
@@ -283,6 +283,14 @@ describe('injector', function() {
it('should take args before first arrow', function() {
expect(annotate(eval('a => b => b'))).toEqual(['a']);
});
// Support: Chrome 50-51 only
// TODO (gkalpak): Remove when Chrome v52 is relased.
// it('should be able to inject fat-arrow function', function() {
// inject(($injector) => {
// expect($injector).toBeDefined();
// });
// });
}
if (support.classes) {
@@ -293,6 +301,19 @@ describe('injector', function() {
expect(instance).toEqual(new Clazz('a-value'));
expect(instance.aVal()).toEqual('a-value');
});
// Support: Chrome 50-51 only
// TODO (gkalpak): Remove when Chrome v52 is relased.
// it('should be able to invoke classes', function() {
// class Test {
// constructor($injector) {
// this.$injector = $injector;
// }
// }
// var instance = injector.invoke(Test, null, null, 'Test');
// expect(instance.$injector).toBe(injector);
// });
}
/*jshint +W061 */
});