Try here: https://github.com/myxor/EspruinoAppLoaderCore/blob/master/js/index.js#L750
Looks like it is doable. I'd have to write lots of console.log() statements to figure out what is going on. This is quite complicated javascript code.
@HughB started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Try here: https://github.com/myxor/EspruinoAppLoaderCore/blob/master/js/index.js#L750