pax_global_header00006660000000000000000000000064141032422370014510gustar00rootroot0000000000000052 comment=cfef1bbebedf84e132cca8a8aedd1053e19f3f57 is-callable-1.2.4/000077500000000000000000000000001410324223700136645ustar00rootroot00000000000000is-callable-1.2.4/.editorconfig000066400000000000000000000006011410324223700163360ustar00rootroot00000000000000root = true [*] indent_style = tab indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true max_line_length = 150 [CHANGELOG.md] indent_style = space indent_size = 2 max_line_length = off [*.json] max_line_length = off [Makefile] max_line_length = off [coverage*/**/*] indent_style = off indent_size = off max_line_length = off is-callable-1.2.4/.eslintignore000066400000000000000000000000121410324223700163600ustar00rootroot00000000000000coverage/ is-callable-1.2.4/.eslintrc000066400000000000000000000004461410324223700155140ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "id-length": 0, "max-statements": [2, 14], "max-statements-per-line": [2, { "max": 2 }], "operator-linebreak": [2, "before"], }, "overrides": [ { "files": "test/**", "rules": { "no-throw-literal": 0, }, }, ], } is-callable-1.2.4/.github/000077500000000000000000000000001410324223700152245ustar00rootroot00000000000000is-callable-1.2.4/.github/FUNDING.yml000066400000000000000000000011061410324223700170370ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/is-callable community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] is-callable-1.2.4/.github/workflows/000077500000000000000000000000001410324223700172615ustar00rootroot00000000000000is-callable-1.2.4/.github/workflows/node-4+.yml000066400000000000000000000030111410324223700211400ustar00rootroot00000000000000name: 'Tests: node.js' on: [pull_request, push] jobs: matrix: runs-on: ubuntu-latest outputs: latest: ${{ steps.set-matrix.outputs.requireds }} minors: ${{ steps.set-matrix.outputs.optionals }} steps: - uses: ljharb/actions/node/matrix@main id: set-matrix with: preset: '>=4' latest: needs: [matrix] name: 'latest minors' runs-on: ubuntu-latest strategy: fail-fast: false matrix: ${{ fromJson(needs.matrix.outputs.latest) }} steps: - uses: actions/checkout@v2 - uses: ljharb/actions/node/install@main name: 'nvm install ${{ matrix.node-version }} && npm install' with: node-version: ${{ matrix.node-version }} - run: npm run tests-only - uses: codecov/codecov-action@v1 minors: needs: [matrix, latest] name: 'non-latest minors' continue-on-error: true if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: ${{ fromJson(needs.matrix.outputs.minors) }} steps: - uses: actions/checkout@v2 - uses: ljharb/actions/node/install@main name: 'nvm install ${{ matrix.node-version }} && npm install' with: node-version: ${{ matrix.node-version }} - run: npm run tests-only - uses: codecov/codecov-action@v1 node: name: 'node 4+' needs: [latest, minors] runs-on: ubuntu-latest steps: - run: 'echo tests completed' is-callable-1.2.4/.github/workflows/node-iojs.yml000066400000000000000000000031141410324223700216720ustar00rootroot00000000000000name: 'Tests: node.js (io.js)' on: [pull_request, push] jobs: matrix: runs-on: ubuntu-latest outputs: latest: ${{ steps.set-matrix.outputs.requireds }} minors: ${{ steps.set-matrix.outputs.optionals }} steps: - uses: ljharb/actions/node/matrix@main id: set-matrix with: preset: 'iojs' latest: needs: [matrix] name: 'latest minors' runs-on: ubuntu-latest strategy: fail-fast: false matrix: ${{ fromJson(needs.matrix.outputs.latest) }} steps: - uses: actions/checkout@v2 - uses: ljharb/actions/node/install@main name: 'nvm install ${{ matrix.node-version }} && npm install' with: node-version: ${{ matrix.node-version }} skip-ls-check: true - run: npm run tests-only - uses: codecov/codecov-action@v1 minors: needs: [matrix, latest] name: 'non-latest minors' continue-on-error: true if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: ${{ fromJson(needs.matrix.outputs.minors) }} steps: - uses: actions/checkout@v2 - uses: ljharb/actions/node/install@main name: 'nvm install ${{ matrix.node-version }} && npm install' with: node-version: ${{ matrix.node-version }} skip-ls-check: true - run: npm run tests-only - uses: codecov/codecov-action@v1 node: name: 'io.js' needs: [latest, minors] runs-on: ubuntu-latest steps: - run: 'echo tests completed' is-callable-1.2.4/.github/workflows/node-pretest.yml000066400000000000000000000011021410324223700224070ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: pretest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ljharb/actions/node/install@main name: 'nvm install lts/* && npm install' with: node-version: 'lts/*' - run: npm run pretest posttest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ljharb/actions/node/install@main name: 'nvm install lts/* && npm install' with: node-version: 'lts/*' - run: npm run posttest is-callable-1.2.4/.github/workflows/node-zero.yml000066400000000000000000000034621410324223700217130ustar00rootroot00000000000000name: 'Tests: node.js (0.x)' on: [pull_request, push] jobs: matrix: runs-on: ubuntu-latest outputs: stable: ${{ steps.set-matrix.outputs.requireds }} unstable: ${{ steps.set-matrix.outputs.optionals }} steps: - uses: ljharb/actions/node/matrix@main id: set-matrix with: preset: '0.x' stable: needs: [matrix] name: 'stable minors' runs-on: ubuntu-latest strategy: fail-fast: false matrix: ${{ fromJson(needs.matrix.outputs.stable) }} steps: - uses: actions/checkout@v2 - uses: ljharb/actions/node/install@main name: 'nvm install ${{ matrix.node-version }} && npm install' with: node-version: ${{ matrix.node-version }} cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }} skip-ls-check: true - run: npm run tests-only - uses: codecov/codecov-action@v1 unstable: needs: [matrix, stable] name: 'unstable minors' continue-on-error: true if: ${{ !github.head_ref || !startsWith(github.head_ref, 'renovate') }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: ${{ fromJson(needs.matrix.outputs.unstable) }} steps: - uses: actions/checkout@v2 - uses: ljharb/actions/node/install@main name: 'nvm install ${{ matrix.node-version }} && npm install' with: node-version: ${{ matrix.node-version }} cache-node-modules-key: node_modules-${{ github.workflow }}-${{ github.action }}-${{ github.run_id }} skip-ls-check: true - run: npm run tests-only - uses: codecov/codecov-action@v1 node: name: 'node 0.x' needs: [stable, unstable] runs-on: ubuntu-latest steps: - run: 'echo tests completed' is-callable-1.2.4/.github/workflows/rebase.yml000066400000000000000000000004011410324223700212400ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] jobs: _: name: "Automatic Rebase" runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: ljharb/rebase@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} is-callable-1.2.4/.github/workflows/require-allow-edits.yml000066400000000000000000000003011410324223700236740ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main is-callable-1.2.4/.gitignore000066400000000000000000000012541410324223700156560ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage/ .nyc_output/ # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Only apps should have lockfiles yarn.lock package-lock.json npm-shrinkwrap.json is-callable-1.2.4/.istanbul.yml000066400000000000000000000017411410324223700163110ustar00rootroot00000000000000verbose: false instrumentation: root: . extensions: - .js - .jsx default-excludes: true excludes: [] variable: __coverage__ compact: true preserve-comments: false complete-copy: false save-baseline: false baseline-file: ./coverage/coverage-baseline.raw.json include-all-sources: false include-pid: false es-modules: false auto-wrap: false reporting: print: summary reports: - html dir: ./coverage summarizer: pkg report-config: {} watermarks: statements: [50, 80] functions: [50, 80] branches: [50, 80] lines: [50, 80] hooks: hook-run-in-context: false post-require-hook: null handle-sigint: false check: global: statements: 100 lines: 100 branches: 100 functions: 100 excludes: [] each: statements: 100 lines: 100 branches: 100 functions: 100 excludes: [] is-callable-1.2.4/.npmignore000066400000000000000000000013171410324223700156650ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage coverage-harmony coverage-std # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Only apps should have lockfiles yarn.lock package-lock.json npm-shrinkwrap.json .github/workflows is-callable-1.2.4/.npmrc000066400000000000000000000000231410324223700147770ustar00rootroot00000000000000package-lock=false is-callable-1.2.4/.nycrc000066400000000000000000000002131410324223700147770ustar00rootroot00000000000000{ "all": true, "check-coverage": false, "reporter": ["text-summary", "text", "html", "json"], "exclude": [ "coverage", "test" ] } is-callable-1.2.4/CHANGELOG.md000066400000000000000000000102531410324223700154760ustar00rootroot000000000000001.2.4 / 2021-08-05 ================= * [Fix] use `has-tostringtag` approach to behave correctly in the presence of symbol shams * [readme] fix repo URLs * [readme] add actions and codecov badges * [readme] remove defunct badges * [meta] ignore eclint checking coverage output * [meta] use `prepublishOnly` script for npm 7+ * [actions] use `node/install` instead of `node/run`; use `codecov` action * [actions] remove unused workflow file * [Tests] run `nyc` on all tests; use `tape` runner * [Tests] use `available-typed-arrays`, `for-each`, `has-symbols`, `object-inspect` * [Dev Deps] update `available-typed-arrays`, `eslint`, `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape` 1.2.3 / 2021-01-31 ================= * [Fix] `document.all` is callable (do not use `document.all`!) * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape` * [Tests] migrate tests to Github Actions * [actions] add "Allow Edits" workflow * [actions] switch Automatic Rebase workflow to `pull_request_target` event 1.2.2 / 2020-09-21 ================= * [Fix] include actual fix from 579179e * [Dev Deps] update `eslint` 1.2.1 / 2020-09-09 ================= * [Fix] phantomjs‘ Reflect.apply does not throw properly on a bad array-like * [Dev Deps] update `eslint`, `@ljharb/eslint-config` * [meta] fix eclint error 1.2.0 / 2020-06-02 ================= * [New] use `Reflect.apply`‑based callability detection * [readme] add install instructions (#55) * [meta] only run `aud` on prod deps * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`, `make-arrow-function`, `make-generator-function`; add `aud`, `safe-publish-latest`, `make-async-function` * [Tests] add tests for function proxies (#53, #25) 1.1.5 / 2019-12-18 ================= * [meta] remove unused Makefile and associated utilities * [meta] add `funding` field; add FUNDING.yml * [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `semver`, `tape`, `covert`, `rimraf` * [Tests] use shared travis configs * [Tests] use `eccheck` over `editorconfig-tools` * [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops * [Tests] remove `jscs` * [actions] add automatic rebasing / merge commit blocking 1.1.4 / 2018-07-02 ================= * [Fix] improve `class` and arrow function detection (#30, #31) * [Tests] on all latest node minors; improve matrix * [Dev Deps] update all dev deps 1.1.3 / 2016-02-27 ================= * [Fix] ensure “class “ doesn’t screw up “class” detection * [Tests] up to `node` `v5.7`, `v4.3` * [Dev Deps] update to `eslint` v2, `@ljharb/eslint-config`, `jscs` 1.1.2 / 2016-01-15 ================= * [Fix] Make sure comments don’t screw up “class” detection (#4) * [Tests] up to `node` `v5.3` * [Tests] Add `parallelshell`, run both `--es-staging` and stock tests at once * [Dev Deps] update `tape`, `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config` * [Refactor] convert `isNonES6ClassFn` into `isES6ClassFn` 1.1.1 / 2015-11-30 ================= * [Fix] do not throw when a non-function has a function in its [[Prototype]] (#2) * [Dev Deps] update `tape`, `eslint`, `@ljharb/eslint-config`, `jscs`, `nsp`, `semver` * [Tests] up to `node` `v5.1` * [Tests] no longer allow node 0.8 to fail. * [Tests] fix npm upgrades in older nodes 1.1.0 / 2015-10-02 ================= * [Fix] Some browsers report TypedArray constructors as `typeof object` * [New] return false for "class" constructors, when possible. * [Tests] up to `io.js` `v3.3`, `node` `v4.1` * [Dev Deps] update `eslint`, `editorconfig-tools`, `nsp`, `tape`, `semver`, `jscs`, `covert`, `make-arrow-function` * [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG 1.0.4 / 2015-01-30 ================= * If @@toStringTag is not present, use the old-school Object#toString test. 1.0.3 / 2015-01-29 ================= * Add tests to ensure arrow functions are callable. * Refactor to aid optimization of non-try/catch code. 1.0.2 / 2015-01-29 ================= * Fix broken package.json 1.0.1 / 2015-01-29 ================= * Add early exit for typeof not "function" 1.0.0 / 2015-01-29 ================= * Initial release. is-callable-1.2.4/LICENSE000066400000000000000000000020721410324223700146720ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Jordan Harband Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. is-callable-1.2.4/README.md000066400000000000000000000043131410324223700151440ustar00rootroot00000000000000# is-callable [![Version Badge][2]][1] [![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![dependency status][5]][6] [![dev dependency status][7]][8] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][11]][1] Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag. ## Example ```js var isCallable = require('is-callable'); var assert = require('assert'); assert.notOk(isCallable(undefined)); assert.notOk(isCallable(null)); assert.notOk(isCallable(false)); assert.notOk(isCallable(true)); assert.notOk(isCallable([])); assert.notOk(isCallable({})); assert.notOk(isCallable(/a/g)); assert.notOk(isCallable(new RegExp('a', 'g'))); assert.notOk(isCallable(new Date())); assert.notOk(isCallable(42)); assert.notOk(isCallable(NaN)); assert.notOk(isCallable(Infinity)); assert.notOk(isCallable(new Number(42))); assert.notOk(isCallable('foo')); assert.notOk(isCallable(Object('foo'))); assert.ok(isCallable(function () {})); assert.ok(isCallable(function* () {})); assert.ok(isCallable(x => x * x)); ``` ## Install Install with ``` npm install is-callable ``` ## Tests Simply clone the repo, `npm install`, and run `npm test` [1]: https://npmjs.org/package/is-callable [2]: https://versionbadg.es/inspect-js/is-callable.svg [5]: https://david-dm.org/inspect-js/is-callable.svg [6]: https://david-dm.org/inspect-js/is-callable [7]: https://david-dm.org/inspect-js/is-callable/dev-status.svg [8]: https://david-dm.org/inspect-js/is-callable#info=devDependencies [11]: https://nodei.co/npm/is-callable.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/is-callable.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/is-callable.svg [downloads-url]: https://npm-stat.com/charts.html?package=is-callable [codecov-image]: https://codecov.io/gh/inspect-js/is-callable/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/inspect-js/is-callable/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-callable [actions-url]: https://github.com/inspect-js/is-callable/actions is-callable-1.2.4/index.js000066400000000000000000000045101410324223700153310ustar00rootroot00000000000000'use strict'; var fnToStr = Function.prototype.toString; var reflectApply = typeof Reflect === 'object' && Reflect !== null && Reflect.apply; var badArrayLike; var isCallableMarker; if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') { try { badArrayLike = Object.defineProperty({}, 'length', { get: function () { throw isCallableMarker; } }); isCallableMarker = {}; // eslint-disable-next-line no-throw-literal reflectApply(function () { throw 42; }, null, badArrayLike); } catch (_) { if (_ !== isCallableMarker) { reflectApply = null; } } } else { reflectApply = null; } var constructorRegex = /^\s*class\b/; var isES6ClassFn = function isES6ClassFunction(value) { try { var fnStr = fnToStr.call(value); return constructorRegex.test(fnStr); } catch (e) { return false; // not a function } }; var tryFunctionObject = function tryFunctionToStr(value) { try { if (isES6ClassFn(value)) { return false; } fnToStr.call(value); return true; } catch (e) { return false; } }; var toStr = Object.prototype.toString; var fnClass = '[object Function]'; var genClass = '[object GeneratorFunction]'; var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag; // better: use `has-tostringtag` /* globals document: false */ var documentDotAll = typeof document === 'object' && typeof document.all === 'undefined' && document.all !== undefined ? document.all : {}; module.exports = reflectApply ? function isCallable(value) { if (value === documentDotAll) { return true; } if (!value) { return false; } if (typeof value !== 'function' && typeof value !== 'object') { return false; } if (typeof value === 'function' && !value.prototype) { return true; } try { reflectApply(value, null, badArrayLike); } catch (e) { if (e !== isCallableMarker) { return false; } } return !isES6ClassFn(value); } : function isCallable(value) { if (value === documentDotAll) { return true; } if (!value) { return false; } if (typeof value !== 'function' && typeof value !== 'object') { return false; } if (typeof value === 'function' && !value.prototype) { return true; } if (hasToStringTag) { return tryFunctionObject(value); } if (isES6ClassFn(value)) { return false; } var strClass = toStr.call(value); return strClass === fnClass || strClass === genClass; }; is-callable-1.2.4/package.json000066400000000000000000000037761410324223700161670ustar00rootroot00000000000000{ "name": "is-callable", "version": "1.2.4", "author": { "name": "Jordan Harband", "email": "ljharb@gmail.com", "url": "http://ljharb.codes" }, "funding": { "url": "https://github.com/sponsors/ljharb" }, "contributors": [ { "name": "Jordan Harband", "email": "ljharb@gmail.com", "url": "http://ljharb.codes" } ], "description": "Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.", "license": "MIT", "main": "index.js", "scripts": { "prepublishOnly": "safe-publish-latest", "prepublish": "not-in-publish || npm run prepublishOnly", "pretest": "npm run --silent lint", "test": "npm run tests-only --", "posttest": "aud --production", "tests-only": "nyc tape 'test/**/*.js'", "prelint": "eclint check *", "lint": "eslint ." }, "repository": { "type": "git", "url": "git://github.com/inspect-js/is-callable.git" }, "keywords": [ "Function", "function", "callable", "generator", "generator function", "arrow", "arrow function", "ES6", "toStringTag", "@@toStringTag" ], "devDependencies": { "@ljharb/eslint-config": "^17.6.0", "aud": "^1.1.5", "available-typed-arrays": "^1.0.4", "eclint": "^2.8.1", "es-value-fixtures": "^1.2.1", "eslint": "^7.32.0", "for-each": "^0.3.3", "has-tostringtag": "^1.0.0", "make-arrow-function": "^1.2.0", "make-async-function": "^1.0.0", "make-generator-function": "^2.0.0", "nyc": "^10.3.2", "object-inspect": "^1.11.0", "rimraf": "^2.7.1", "safe-publish-latest": "^1.1.4", "tape": "^5.3.0" }, "testling": { "files": "test/index.js", "browsers": [ "iexplore/6.0..latest", "firefox/3.0..6.0", "firefox/15.0..latest", "firefox/nightly", "chrome/4.0..10.0", "chrome/20.0..latest", "chrome/canary", "opera/10.0..latest", "opera/next", "safari/4.0..latest", "ipad/6.0..latest", "iphone/6.0..latest", "android-browser/4.2" ] }, "engines": { "node": ">= 0.4" }, "greenkeeper": { "ignore": [ "rimraf" ] } } is-callable-1.2.4/test/000077500000000000000000000000001410324223700146435ustar00rootroot00000000000000is-callable-1.2.4/test/index.js000066400000000000000000000130141410324223700163070ustar00rootroot00000000000000'use strict'; /* globals Proxy */ /* eslint no-magic-numbers: 1 */ var test = require('tape'); var isCallable = require('../'); var hasToStringTag = require('has-tostringtag/shams')(); var v = require('es-value-fixtures'); var forEach = require('for-each'); var inspect = require('object-inspect'); var typedArrayNames = require('available-typed-arrays')(); var generators = require('make-generator-function')(); var arrows = require('make-arrow-function').list(); var asyncs = require('make-async-function').list(); var weirdlyCommentedArrowFn; try { /* eslint-disable no-new-func */ weirdlyCommentedArrowFn = Function('return cl/*/**/=>/**/ass - 1;')(); /* eslint-enable no-new-func */ } catch (e) { /**/ } var noop = function () {}; var classFake = function classFake() { }; // eslint-disable-line func-name-matching var returnClass = function () { return ' class '; }; var return3 = function () { return 3; }; /* for coverage */ noop(); classFake(); returnClass(); return3(); /* end for coverage */ var proxy; if (typeof Proxy === 'function') { try { proxy = new Proxy(function () {}, {}); // for coverage proxy(); String(proxy); } catch (_) { // If `Reflect` is supported, then `Function.prototype.toString` isn't used for callability detection. if (typeof Reflect !== 'object') { // Older engines throw a `TypeError` when `Function.prototype.toString` is called on a Proxy object. proxy = null; } } } var invokeFunction = function invokeFunctionString(str) { var result; try { /* eslint-disable no-new-func */ var fn = Function(str); /* eslint-enable no-new-func */ result = fn(); } catch (e) {} return result; }; var classConstructor = invokeFunction('"use strict"; return class Foo {}'); var commentedClass = invokeFunction('"use strict"; return class/*kkk*/\n//blah\n Bar\n//blah\n {}'); var commentedClassOneLine = invokeFunction('"use strict"; return class/**/A{}'); var classAnonymous = invokeFunction('"use strict"; return class{}'); var classAnonymousCommentedOneLine = invokeFunction('"use strict"; return class/*/*/{}'); test('not callables', function (t) { t.notOk(isCallable(), 'implicit undefined is not callable'); forEach(v.nonFunctions.concat([ Object(42), Object('foo'), NaN, [], /a/g, new RegExp('a', 'g'), new Date() ]), function (nonFunction) { t.equal(isCallable(nonFunction), false, inspect(nonFunction) + ' is not callable'); }); t.test('non-function with function in its [[Prototype]] chain', function (st) { var Foo = function Bar() {}; Foo.prototype = noop; st.equal(isCallable(Foo), true, 'sanity check: Foo is callable'); st.equal(isCallable(new Foo()), false, 'instance of Foo is not callable'); st.end(); }); t.end(); }); test('@@toStringTag', { skip: !hasToStringTag }, function (t) { var fakeFunction = { toString: function () { return String(return3); }, valueOf: return3 }; fakeFunction[Symbol.toStringTag] = 'Function'; t.equal(String(fakeFunction), String(return3)); t.equal(Number(fakeFunction), return3()); t.notOk(isCallable(fakeFunction), 'fake Function with @@toStringTag "Function" is not callable'); t.end(); }); test('Functions', function (t) { t.ok(isCallable(noop), 'function is callable'); t.ok(isCallable(classFake), 'function with name containing "class" is callable'); t.ok(isCallable(returnClass), 'function with string " class " is callable'); t.ok(isCallable(isCallable), 'isCallable is callable'); t.end(); }); test('Typed Arrays', { skip: typedArrayNames.length === 0 }, function (st) { forEach(typedArrayNames, function (typedArray) { st.ok(isCallable(global[typedArray]), typedArray + ' is callable'); }); st.end(); }); test('Generators', { skip: generators.length === 0 }, function (t) { forEach(generators, function (genFn) { t.ok(isCallable(genFn), 'generator function ' + genFn + ' is callable'); }); t.end(); }); test('Arrow functions', { skip: arrows.length === 0 }, function (t) { forEach(arrows, function (arrowFn) { t.ok(isCallable(arrowFn), 'arrow function ' + arrowFn + ' is callable'); }); t.ok(isCallable(weirdlyCommentedArrowFn), 'weirdly commented arrow functions are callable'); t.end(); }); test('"Class" constructors', { skip: !classConstructor || !commentedClass || !commentedClassOneLine || !classAnonymous }, function (t) { t.notOk(isCallable(classConstructor), 'class constructors are not callable'); t.notOk(isCallable(commentedClass), 'class constructors with comments in the signature are not callable'); t.notOk(isCallable(commentedClassOneLine), 'one-line class constructors with comments in the signature are not callable'); t.notOk(isCallable(classAnonymous), 'anonymous class constructors are not callable'); t.notOk(isCallable(classAnonymousCommentedOneLine), 'anonymous one-line class constructors with comments in the signature are not callable'); t.end(); }); test('`async function`s', { skip: asyncs.length === 0 }, function (t) { forEach(asyncs, function (asyncFn) { t.ok(isCallable(asyncFn), '`async function` ' + asyncFn + ' is callable'); }); t.end(); }); test('proxies of functions', { skip: !proxy }, function (t) { t.ok(isCallable(proxy), 'proxies of functions are callable'); t.end(); }); test('throwing functions', function (t) { t.plan(1); var thrower = function (a) { return a.b; }; 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'); t.end(); });