Category Archives: Announcements

I’ve moved!

My blog has a new home:

Hope to see you there!

Mozilla Research intern Tim Disney has has just released, a dialect of CoffeeScript with a sweet syntax for wrapping JavaScript objects with contracts that are automatically checked at runtime (“assert on steroids”). Tim’s got a great tutorial with lots of examples, so I won’t try to reproduce it here. Just check it out! is a great demonstrator of the power of JavaScript proxies, which are coming in the ES6 standard, have been shipping in SpiderMonkey since Firefox 4, and are in the works for V8. uses proxies to create wrapper objects that do all the proper checking to enforce your contracts.

It’s also a nice experiment in language design (using ideas from Eiffel and Scheme), which we’ll be paying attention to along the road to ES7 and beyond.

The JS parser API has landed

Today I pushed a patch to our development repository to expose the JavaScript Parser API to code with chrome privileges. I’ve fixed all known major bugs, and it’s been holding up under sustained attack from Jesse Ruderman‘s fuzz tester without crashing for the better part of a year. So hopefully this means the landing will stick. If so, then this should land in Nightly within the week and Aurora by next week. If all goes well, the library will ship with Firefox 7.

Once it ships, addons will be able to write:

> Components.utils.import("resource://gre/modules/reflect.jsm");
> var expr = Reflect.parse(" + 42").body[0].expression
> expr.right.value

I hope people find this useful for introspecting on code, building development tools, or writing static analyses. I also hope people come up with cool new applications I haven’t even thought of.

Zaphod: A Browser Language Lab for JS

When I started full-time at Mozilla this January, one of the first projects I dreamed of starting was an experimental version of JavaScript that would be easy to hack and experiment with. Ideally, it would be embeddable in Firefox so that we could really try it out in the wild. My hope was that this would be useful for experimenting with JS features and ECMAScript committee proposals, and for seeing how they interact on the web. But, the best laid plans of mice and men being what they are, I never seemed to find the time for the project.

Enter our summer intern Tom Austin! Tom spent the first part of his summer helping us revive the Narcissus project, which is a JavaScript interpreter written in JavaScript. Brendan Eich wrote Narcissus several years ago as an experiment, but at that point it required a special build of SpiderMonkey to enable some low-level hooks. This meant that you couldn’t use Narcissus without building it from scratch. Tom worked on replacing the dependency on these hooks with the new meta-programming API’s coming in Firefox 4 so that Narcissus can be used with the standard build of SpiderMonkey.

Once Narcissus started getting back into shape, Tom spent the rest of his summer building Zaphod, which is now available as an experimental Mozilla Labs addon for Firefox. Zaphod lets you choose Narcissus as the scripting engine for a <script> element by specifying the attribute type="application/narcissus". It also lets you switch the default engine from SpiderMonkey to Narcissus so that you can run existing web pages through Narcissus.

Zaphod promises to be a great tool for getting hands-on experience with experimental JS language features. Initially, it will useful to us internally for rapidly piloting language features in the browser. Down the road, it may also become a vehicle for giving the community early access to these ideas, so they can try them out and give us feedback. And of course, it’s all open source, so anyone who wants to join in on the effort is most welcome.

An API for parsing JavaScript

In new builds of the SpiderMonkey shell we’re introducing an experimental API for parsing JavaScript source code, which landed this week. For now, you have to download and build SpiderMonkey from source to use it, but hopefully we’ll include it in future versions of Firefox.

The parser API provides a single function:

Reflect.parse(src[, filename=null[, lineno=1]])

Reflect.parse takes a source string (and optionally, a filename and starting line number for source location metadata), and produces a JavaScript object representing the abstract syntax tree of the parsed source code, using the built-in parser of SpiderMonkey itself. Straightforward enough, but behind this simple entry point is a thorough API that covers the entirety of SpiderMonkey’s abstract syntax. In short, anything that SpiderMonkey can parse, you can parse, too. Developer tools generally need a parse tree, and JavaScript isn’t an easy language to parse. With this API, it becomes much easier to write tools like syntax highlighters, static analyses, style checkers, etc. And because Reflect.parse uses the same parser that SpiderMonkey uses, it’s guaranteed to be compatible.

Here’s a simple example:

js> var ast = Reflect.parse(" + 42");
js> var expr = ast.body[0].expression;
({loc:null, type:"Identifier", name:"foo"})
js> expr.right
    loc: {
        source: null,
        start: {
            line: 1,
            column: 10
        end: {
            line: 1,
            column: 12
    type: "Literal",
    value: 42

Try it out, and feel free to give me feedback!

Language engineering on the web

I joined Mozilla Labs this January as a research engineer. I will continue in my role as a contributor to the Ecma TC39 committee, working on the design of ECMAScript. I’m also starting to contribute to Mozilla projects such as SpiderMonkey. This is an incredible place to work, and I’m excited about all the projects we’ve got coming up.

I intend to continue blogging more research-oriented topics at The Little Calculist. But this is my new home for topics like Mozilla, ECMAScript, and the web.