Generalized 'modifyJSRef' to work in JSA and JSB.