tc39 / proposal-upsert

ECMAScript Proposal, specs, and reference implementation for Map.prototype.upsert
https://tc39.es/proposal-upsert/
MIT License
202 stars 14 forks source link

should the computed methods check callability of the callback early? #66

Closed michaelficarra closed 6 days ago

michaelficarra commented 2 weeks ago

Right now, the spec text has the computed methods checking that the second argument is callable even when the callback may not be called. Do we want to do this check? I don't have an opinion either way at the moment.

ljharb commented 2 weeks ago

Yes, we should always validate all arguments whether they're used or not.

bakkot commented 2 weeks ago

Compare Array.prototype.forEach, which is similar in some ways (e.g. it doesn't necessarily run) and where we check callability of the callback eagerly.

johauke commented 2 weeks ago

Adding to previous answers, if we don't validate the callback function at the beginning, the function can be very unpredictable to use. Since if it is given an invalid callback function, it might throw an error sometimes and sometimes not all depending on whether the key is in the map already or not.

dminor commented 6 days ago

Sounds like we're ok with the current behaviour.