Refactor JSEnv to support async running