Javascript fixes

I've been playing around with your Javascript emulator and I have a bunch of fixes/improvements. The framebuffer change is important, without that the emulator is unusably slow for me in Firefox. The others are pretty minor.

 Tested in Firefox and Chrome.