Neil's News

ECMAScript 5

7 October 2016

The JS-Interpreter is a sandbox that allows one to run JavaScript in JavaScript. When I released it three years ago, it ran basic code well, but there were a lot of gaps. Over the summer I've brought it up to nearly 100% compliance with the ECMAScript 5 specification. It now supports try/catch/finally, Array.sort/map/reduce, property getter/setter functions, switch statements, regular expressions, strict mode, error classes, and more. I've also more than doubled the execution speed.

Try out the JS-Interpreter demo.

The best part of working on this project was acquiring a much deeper understanding of the JavaScript language. A couple of the more interesting discoveries:


This returns 3. Obviously.

What about this one:

try {
  throw 'a';
} catch (e) {
  throw 'b';
} finally {
  throw 'c';

It's pretty obvious that 'a' will be thrown and get caught. But then what happens? Does throwing 'b' terminate the program? Or does throwing 'c' terminate the program? Or does it throw both 'b' then 'c'?

Actually, both do get thrown, but 'b' gets thrown first and then gets immediately clobbered by 'c'. Thus 'b' disappears without a trace. The same thing happens if return is used instead of throw. Wat.

An unexpected side effect of working on the JS-Interpreter is that my Google searches started to get quite obscure. This resulted in three separate instances where the search results page split open and Google invited me to apply for a job. I think they nailed the target audience.

< Previous | Next >

Legal yada yada: My views do not necessarily represent those of my employer or my goldfish.