Run Linux on... JavaScript?!

Javascript has finally arrived. Ruby watch out!
Run Linux on… JavaScript?!
via ReadWriteWeb by Klint Finley on 5/17/11

JavaScript logo 150x150 Fabrice Bellard built an x86 PC emulator using JavaScript. He’s even gone so far as to install Linux kernel 2.6.20 on top of it. “The code is written in pure Javascript using Typed Arrays which are available in recent browsers,” Bellard wrote. It works in Firefox and Chrome 11, but not not Chrome 12.

As for the Linux instance, Bellard wrote: “The disk image is just a ram disk image loaded at boot time. It contains a filesystem generated with Buildroot containing BusyBox. I added my toy C compiler TinyCC and my unfinished but usable emacs clone QEmacs.” You can see Linux running JavaScript here.


JS/Linux screenshot

Bellard did it just for fun, but he speculates that it could be useful for the following purposes:

  • Benchmarking of Javascript engines (how much time takes your Javascript engine to boot Linux ?). For this particular application, efficient handling of 32 bit signed and unsigned integers and of typed arrays is important.
  • Client side processing using an x86 library, for example for cryptographic purposes. For such application, the x86 emulator can be modified to provide an API to load x86 dynamic libraries and to provide a js-ctypes like API to call the C/C++ functions from javascript.
  • A more advanced version would allow to use old DOS PC software such as games.

Oddly enough, he found that Linux ran twice as fast on Jaeger Monkey as it did on V8. He’s not sure why.