[BUGFIX beta] Fix isEmpty for map

Fixes #9412 (`isEmpty` raises a deprecation in beta), with the cost of far more complexity in `isEmpty`. Tried to avoid `typeof` calls as much as possible.

@stefanpenner for you.