Skip to content

Commit

Permalink
[Fix] for HTML constructors, always use tryFunctionObject even in p…
Browse files Browse the repository at this point in the history
…re-toStringTag browsers

 - in IE 6 - 8, HTML constructors are not callable
  • Loading branch information
ljharb committed Sep 12, 2022
1 parent da90b2b commit 3076ea2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -78,5 +78,5 @@ module.exports = reflectApply
if (hasToStringTag) { return tryFunctionObject(value); }
if (isES6ClassFn(value)) { return false; }
var strClass = toStr.call(value);
return strClass === fnClass || strClass === genClass;
return strClass === fnClass || strClass === genClass || tryFunctionObject(value);
};
30 changes: 26 additions & 4 deletions test/index.js
Expand Up @@ -19,6 +19,8 @@ try {
/* eslint-enable no-new-func */
} catch (e) { /**/ }

var isIE68 = !(0 in [undefined]);

var noop = function () {};
var classFake = function classFake() { }; // eslint-disable-line func-name-matching
var returnClass = function () { return ' class '; };
Expand Down Expand Up @@ -160,10 +162,30 @@ test('throwing functions', function (t) {
t.ok(isCallable(thrower), 'a function that throws is callable');
});

/* globals document: false */
test('document.all', { skip: typeof document !== 'object' }, function (t) {
t.notOk(isCallable(document), 'document is not callable');
t.ok(isCallable(document.all), 'document.all is callable');
test('DOM', function (t) {
/* eslint-env browser */

t.test('document.all', { skip: typeof document !== 'object' }, function (st) {
st.notOk(isCallable(document), 'document is not callable');
st.ok(isCallable(document.all), 'document.all is callable');

st.end();
});

forEach([
'HTMLElement',
'HTMLAnchorElement'
], function (name) {
var constructor = global[name];

t.test(name, { skip: !constructor }, function (st) {
st.match(typeof constructor, /^(?:function|object)$/, name + ' is a function');

st.equal(isCallable(constructor), !isIE68, name + ' is ' + (isIE68 ? 'not ' : '') + 'callable');

st.end();
});
});

t.end();
});

0 comments on commit 3076ea2

Please sign in to comment.