Handle null when evaluating JS value. Fixes #4235.

Rebased from #4241.