Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion 2015/IsCallable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion 2016/IsCallable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion 2017/IsCallable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion 2018/IsCallable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion 2019/IsCallable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion 5/IsCallable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use strict';

var hasSymbols = require('has-symbols')();
var callBound = require('../helpers/callBound.js');

var $toStr = callBound('%Object.prototype.toString%');

// http://www.ecma-international.org/ecma-262/5.1/#sec-9.11

module.exports = require('is-callable');
module.exports = function IsCallable(argument) {
// some older engines say that typeof /abc/ === 'function',
return typeof argument === 'function'
&& (hasSymbols || $toStr(argument) !== '[object RegExp]');
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"function-bind": "^1.1.1",
"has": "^1.0.3",
"has-symbols": "^1.0.1",
"is-callable": "^1.2.0",
"is-regex": "^1.1.0",
"object-inspect": "^1.7.0",
"object-keys": "^1.1.1",
Expand Down
18 changes: 17 additions & 1 deletion test/es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,26 @@ test('CheckObjectCoercible', function (t) {

test('IsCallable', function (t) {
t.equal(true, ES.IsCallable(function () {}), 'function is callable');
var nonCallables = [/a/g, {}, Object.prototype, NaN].concat(v.primitives);
var nonCallables = [/a/g, {}, Object.prototype, NaN].concat(v.nonFunctions);
forEach(nonCallables, function (nonCallable) {
t.equal(false, ES.IsCallable(nonCallable), debug(nonCallable) + ' is not callable');
});

var foo;
try {
foo = Function('return () => {}')(); // eslint-disable-line no-new-func
t.equal(ES.IsCallable(foo), true, 'arrow function is callable');
} catch (e) {
t.comment('SKIP: arrow function syntax not supported.');
}

try {
foo = Function('return class Foo {}')(); // eslint-disable-line no-new-func
t.equal(ES.IsCallable(foo), true, 'class is callable');
} catch (e) {
t.comment('SKIP: class syntax not supported.');
}

t.end();
});

Expand Down
16 changes: 16 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,22 @@ var es2015 = function ES2015(ES, ops, expectedMissing, skips) {
forEach(nonCallables, function (nonCallable) {
t.equal(false, ES.IsCallable(nonCallable), debug(nonCallable) + ' is not callable');
});

var foo;
try {
foo = Function('return () => {}')(); // eslint-disable-line no-new-func
t.equal(ES.IsCallable(foo), true, 'arrow function is callable');
} catch (e) {
t.comment('SKIP: arrow function syntax not supported.');
}

try {
foo = Function('return class Foo {}')(); // eslint-disable-line no-new-func
t.equal(ES.IsCallable(foo), true, 'class is callable');
} catch (e) {
t.comment('SKIP: class syntax not supported.');
}

t.end();
});

Expand Down