Skip to content

[Fix] ES5+: Use spec‑accurate IsCallable#93

Open
ExE-Boss wants to merge 1 commit intoljharb:mainfrom
ExE-Boss:fix/es5/use-spec-accurate-iscallable-isconstructor-implementation
Open

[Fix] ES5+: Use spec‑accurate IsCallable#93
ExE-Boss wants to merge 1 commit intoljharb:mainfrom
ExE-Boss:fix/es5/use-spec-accurate-iscallable-isconstructor-implementation

Conversation

@ExE-Boss
Copy link
Copy Markdown
Contributor

@ExE-Boss ExE-Boss commented May 16, 2020

The IsConstructor implementation is based on the one in tc39/ecma262#1798 (comment)


Fixes #48

Co-authored-by: Jordan Harband <ljharb@gmail.com>
Copy link
Copy Markdown
Owner

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on which specific tests wouldn't have passed before this PR?

If the only effect is that class constructors are going to report as being callable, i don't think tightly adhering to the spec in this case is worth it.

module.exports = require('is-callable');
module.exports = function IsCallable(argument) {
// some older engines say that typeof /abc/ === 'function',
return typeof argument === 'function'
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't actually useful though, because it will report class constructors as callable.

Copy link
Copy Markdown
Contributor Author

@ExE-Boss ExE-Boss May 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that’s what the specification for IsCallable says to do.

Copy link
Copy Markdown
Owner

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this, but we'd still need to determine if getters are supported, in case Reflect.contruct is polyfilled in ES5.

@ExE-Boss ExE-Boss force-pushed the fix/es5/use-spec-accurate-iscallable-isconstructor-implementation branch from cbdd330 to 371fc87 Compare May 18, 2020 06:31
@ExE-Boss ExE-Boss force-pushed the fix/es5/use-spec-accurate-iscallable-isconstructor-implementation branch from 371fc87 to c617543 Compare May 18, 2020 09:26
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 13, 2020

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.00%. Comparing base (d959e6d) to head (a0dc7e0).
⚠️ Report is 625 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #93      +/-   ##
==========================================
+ Coverage   90.93%   91.00%   +0.07%     
==========================================
  Files         647      647              
  Lines        9041     9071      +30     
  Branches     2125     2137      +12     
==========================================
+ Hits         8221     8255      +34     
+ Misses        820      816       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ljharb ljharb force-pushed the fix/es5/use-spec-accurate-iscallable-isconstructor-implementation branch from c617543 to a0dc7e0 Compare June 13, 2020 21:20
@ljharb
Copy link
Copy Markdown
Owner

ljharb commented Jun 13, 2020

I've separated out the IsConstructor fixes and pulled those into master; this PR has been rebased with just the IsCallable changes.

@ljharb ljharb changed the title [Fix] ES5+: Use spec‑accurate IsCallable and IsConstructor impls [Fix] ES5+: Use spec‑accurate IsCallable Jun 13, 2020
@zloirock zloirock mentioned this pull request Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ES.isCallable not spec compliant

2 participants