Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 11bc943

Browse files
committed
fix($injector): Add support for native Safari classes
Change the mechanism to detect if a function is a class so it is compatible with Safari 9.
1 parent 52ea411 commit 11bc943

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

src/auto/injector.js

+5-21
Original file line numberDiff line numberDiff line change
@@ -821,17 +821,6 @@ function createInjector(modulesToLoad, strictDi) {
821821
return args;
822822
}
823823

824-
function isClass(func) {
825-
// IE 9-11 do not support classes and IE9 leaks with the code below.
826-
if (msie <= 11) {
827-
return false;
828-
}
829-
// Workaround for MS Edge.
830-
// Check https://connect.microsoft.com/IE/Feedback/Details/2211653
831-
return typeof func === 'function'
832-
&& /^(?:class\s|constructor\()/.test(Function.prototype.toString.call(func));
833-
}
834-
835824
function invoke(fn, self, locals, serviceName) {
836825
if (typeof locals === 'string') {
837826
serviceName = locals;
@@ -843,15 +832,12 @@ function createInjector(modulesToLoad, strictDi) {
843832
fn = fn[fn.length - 1];
844833
}
845834

846-
if (!isClass(fn)) {
835+
try {
847836
// http://jsperf.com/angularjs-invoke-apply-vs-switch
848-
// #5388
849837
return fn.apply(self, args);
850-
} else {
851-
args.unshift(null);
852-
/*jshint -W058 */ // Applying a constructor without immediate parentheses is the point here.
853-
return new (Function.prototype.bind.apply(fn, args));
854-
/*jshint +W058 */
838+
} catch (e) {
839+
// if `fn` is a class, then it needs to be called using `new`
840+
return new (Function.prototype.bind.apply(fn, [null].concat(args)))();
855841
}
856842
}
857843

@@ -863,9 +849,7 @@ function createInjector(modulesToLoad, strictDi) {
863849
var args = injectionArgs(Type, locals, serviceName);
864850
// Empty object at position 0 is ignored for invocation with `new`, but required.
865851
args.unshift(null);
866-
/*jshint -W058 */ // Applying a constructor without immediate parentheses is the point here.
867-
return new (Function.prototype.bind.apply(ctor, args));
868-
/*jshint +W058 */
852+
return new (Function.prototype.bind.apply(ctor, args))();
869853
}
870854

871855

test/ng/compileSpec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
/* globals support: false */
34

45
describe('$compile', function() {
56
function isUnknownElement(el) {
@@ -4241,7 +4242,7 @@ describe('$compile', function() {
42414242

42424243

42434244
it('should eventually expose isolate scope variables on ES6 class controller with controllerAs when bindToController is true', function() {
4244-
if (!/chrome/i.test(navigator.userAgent)) return;
4245+
if (!support.classes) return;
42454246
/*jshint -W061 */
42464247
var controllerCalled = false;
42474248
module(function($compileProvider) {

0 commit comments

Comments
 (0)