Closed michaelficarra closed 6 days ago
Yes, we should always validate all arguments whether they're used or not.
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.
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.
Sounds like we're ok with the current behaviour.
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.