Fix issue invoking functions with JS scripting extension

Fix for #514 based on master.