Skip to content

Commit 06c1db2

Browse files
committed
[Fix] recognize document.all in IE 6-10
1 parent 17391fe commit 06c1db2

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

index.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ var toStr = Object.prototype.toString;
4646
var objectClass = '[object Object]';
4747
var fnClass = '[object Function]';
4848
var genClass = '[object GeneratorFunction]';
49-
var ddaClass = '[object HTMLAllCollection]';
49+
var ddaClass = '[object HTMLAllCollection]'; // IE 11
5050
var ddaClass2 = '[object HTML document.all class]';
51-
var ddaClass3 = '[object HTMLCollection]'; // opera 12.16
51+
var ddaClass3 = '[object HTMLCollection]'; // IE 9-10
5252
var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag; // better: use `has-tostringtag`
5353

5454
var isIE68 = !(0 in [,]); // eslint-disable-line no-sparse-arrays, comma-spacing
5555

5656
var isDDA = function isDocumentDotAll() { return false; };
5757
if (typeof document === 'object') {
58-
// Firefox 3 canonicalized DDA to undefined when it's not accessed directly
58+
// Firefox 3 canonicalizes DDA to undefined when it's not accessed directly
5959
var all = document.all;
6060
if (toStr.call(all) === toStr.call(document.all)) {
6161
isDDA = function isDocumentDotAll(value) {
@@ -64,8 +64,12 @@ if (typeof document === 'object') {
6464
if ((isIE68 || !value) && (typeof value === 'undefined' || typeof value === 'object')) {
6565
try {
6666
var str = toStr.call(value);
67-
// IE 6-8 uses `objectClass`
68-
return (str === ddaClass || str === ddaClass2 || str === ddaClass3 || str === objectClass) && value('') == null; // eslint-disable-line eqeqeq
67+
return (
68+
str === ddaClass
69+
|| str === ddaClass2
70+
|| str === ddaClass3 // opera 12.16
71+
|| str === objectClass // IE 6-8
72+
) && value('') == null; // eslint-disable-line eqeqeq
6973
} catch (e) { /**/ }
7074
}
7175
return false;
@@ -78,13 +82,12 @@ module.exports = reflectApply
7882
if (isDDA(value)) { return true; }
7983
if (!value) { return false; }
8084
if (typeof value !== 'function' && typeof value !== 'object') { return false; }
81-
if (typeof value === 'function' && !value.prototype) { return true; }
8285
try {
8386
reflectApply(value, null, badArrayLike);
8487
} catch (e) {
8588
if (e !== isCallableMarker) { return false; }
8689
}
87-
return !isES6ClassFn(value);
90+
return !isES6ClassFn(value) && tryFunctionObject(value);
8891
}
8992
: function isCallable(value) {
9093
if (isDDA(value)) { return true; }

test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ test('DOM', function (t) {
202202
st.notOk(isCallable(document), 'document is not callable');
203203

204204
var all = document.all;
205-
var isFF3 = Object.prototype.toString(all) === Object.prototype.toString.call(document.all);
205+
var isFF3 = !isIE68 && Object.prototype.toString(all) === Object.prototype.toString.call(document.all); // this test is true in IE 6-8 also
206206
var expected = false;
207207
if (!isFF3) {
208208
try {

0 commit comments

Comments
 (0)