Fixed javascript impl so that it's easier to implement native->js conversion.