Friday, August 13, 2010

Narcissus addon available

Today I uploaded a plugin for Narcissus JavaScript.  Details can be found here.

It requires Firefox 4, so to test this out, you will need to build from source for the time being.  Longer term, the plan is to swap out the JS engine at will.  But, it is at least usable for experimenting currently.  Enjoy!

Tuesday, July 20, 2010

More Awesomeness:

In working with Narcissus, I've uncovered a jewel of a resource in Mozilla's JavaScript unit tests.  The value of unit tests is well understood.  The most critical quality, however, is that they are maintained.  Mozilla has done an exemplary job of this.  The unit tests are constantly growing.  As I write this, there are just shy of 3000 unit tests.  All of them pass with the Tracemonkey engine.

The organization of the tests is well thought out.  Each version of JavaScript has its own test directory.  So if you don't care about certain batches of tests, it is easy to ignore them.

Unfortunately, as with many other things at Mozilla, there is an abundance of out of date documentaion.  The JS Test Library page refers to a Perl script, which appears to be more or less abandoned.  Instead, there is a python script '', written by Dave Mandelin in his copious amounts of free time.  Unfortunately, the old version of unit testing documentation comes up first when searching for it on Google.  Alas.

One thing that is sadly not emphasized is just how easy it is to plug in a different engine to use these tests.  In fact, I have a "shell" for Narcissus JS, written in 30-some lines of Python code.

To hook into the testing framework, you need a "shell" that supports two command line options:
1) -e, which interprets a string of JavaScript code.
2) -f, which handles a JavaScript file.
It must be possible to support multiple files and strings of code, though this is not a particularly difficult challenge.

Some tricks:
  • The -m option will let you specify your own module of JS tests.  This is also a convenient way to insert a little JavaScript into the testing process to handle tests relying on non-standard JS features.
  • The -x option allows you to ignore a list of tests.  Since Mozilla includes tests for special Firefox-only features, you will want to use this.
  • The --failure-file option will write the failing unit tests to the specified file, useful as input for the -x option.

On another note, Narcissus now runs without special extensions in Firefox 4.  Huzzah!  Now to make it interact smoothly with the DOM...

Thursday, June 24, 2010

This summer I am working at Mozilla. It is an awesome, awesome place to be. The people here are friendly and amazingly bright. Plus there is a dinosaur in the lobby. How can you beat that?

My work has been looking at Narcissus JavaScript. Narcissus is a JavaScript implementation written in JavaScript, and as such, it is an ideal vehicle for playing around with the language.

Narcissus relies on a few special extensions, which require a special build. It is not hard to build, but it is not all that well documented either. Here is the process that I use (in OSX):

  $hg clone
  $cd tracemonkey/js/src/


  $./configure --enable-narcissus


With that, you are good to go. From the command line, ./js will give you a tracemonkey shell. Here, you can use evaluate(prog) to test out narcissus.

With some adjustments, Narcissus should run within a standard Firefox build. I am down to a handful of failing unit tests. After that, running Narcissus within a browser should be as simple as loading the Narcissus js code.