Completely rewrite the code to convert JSVals to unions.

This code works correctly for the two unions currently in use, and raises
exceptions in codegen for most other cases. I will implement those cases when
the need arises.