[js] fix memory leak introduced in 7a9447e933bda832443394b539f6ac8a4f82d1c1