Zaphod/Narcissus — tools for JavaScript language research

There have been a number of questions about Zaphod and Narcissus.  Or perhaps just the one major question:

“Seems cool.  Why should I use this?”

For day to day browsing, Narcissus does not offer any real advantages over SpiderMonkey.  However, Narcissus is an ideal tool for developing new ideas for the JavaScript language itself.

What features should we add to JavaScript?  What should the syntax/semantics be?  What practical issues will come up that we have not considered so far?  With Narcissus and Zaphod, we can more easily answer these questions.

In programming language (PL) research, we like to write up fancy evaluation rules containing lots of Greek letters. Unfortunately, these rules tend to be inscrutable to anyone who isn’t a PL researcher. Even for PL researchers, there is something unsatisfying about seeing a bunch of rules on a piece of paper.

We want to be able to try our ideas out with a real implementation — kick the tires, so to speak. Also, we want to share our ideas as widely as we can.  This way, we can get feedback from programmers who experiment with our design.

Unfortunately, this usually means editing a sizable, constantly shifting C++ code base. Anyone who wants to test out our ideas has to build the browser from source, which can be a daunting task.

With Narcissus JavaScript, we have another alternative.  Narcissus is both a simpler code base, and also much less affected by the changing browser code base.  Once we have made our changes, we can easily distribute the JavaScript files and let others play around with the new feature.

But Narcissus does not by itself integrate smoothly with the browser. That is where Zaphod comes in.

Zaphod looks for scripts with a tag of “application/narcissus” (which SpiderMonkey will ignore) and parses those scripts with Narcissus.  This setup allows us to demonstrate a few examples using the new feature.  Here are a few simple pages using this technique. Using this, you can show some examples of how your new feature could be used.

But we might also want to see how the implementation would work on a pre-existing page. Click on the mozilla icon in the bottom right corner and Narcissus will be set as the default JavaScript interpreter. After experimenting, click on the icon again and SpiderMonkey will be reset as your JS implementation.

Zaphod/Narcissus cannot yet handle some of the more JavaScript-heavy pages, but it can handle enough to be a valuable research tool for JavaScript language hackers.  I hope you enjoy.  And if you use it for some cool experiments, let me know!