ljharb / es-abstract

ECMAScript spec abstract operations.
MIT License
114 stars 30 forks source link

[Fix]: `helpers/callBound`: Avoid useless `$indexOf` call #108

Closed ExE-Boss closed 9 months ago

ExE-Boss commented 4 years ago

%String.prototype.indexOf% returns ‑1 when the substring wasn’t found, and ToBoolean(‑1) returns true, so the correct check should’ve been $indexOf(name, '.prototype.') > 0, but doing that now would break many things, including PromiseResolve.

The only case where callBound could return the same function object as GetIntrinsic would’ve been callBound('.prototype.something') (callBound('%.prototype.something%') would return the result of callBind, as the index of '.prototype.' is 1), but that would cause GetIntrinsic to throw a SyntaxError.

codecov[bot] commented 4 years ago

Codecov Report

Merging #108 into master will decrease coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #108      +/-   ##
==========================================
- Coverage   90.85%   90.85%   -0.01%     
==========================================
  Files         682      682              
  Lines        9422     9421       -1     
  Branches     2169     2169              
==========================================
- Hits         8560     8559       -1     
  Misses        862      862              
Impacted Files Coverage Δ
helpers/callBound.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3f88447...9743994. Read the comment docs.

ljharb commented 9 months ago

callBound has been extracted to https://github.com/ljharb/call-bind; any further improvements should go there. Thanks!