Optional catch in JavaScript

26 July 2007 in blog
tagged with [exceptions] [javascript] [programming] [rhino] [spidermonkey]

One of the things that’s been annoying me about JavaScript recently is the inability to only catch certain classes of exception, as in Java or Python, for instance. The try {..} catch(e) {..} block has always seemed too inclusive. But recently Ash found a crazy syntax in SpiderMonkey that lets us only catch certain exceptions.

try {
  // something that can throw
} catch(e if e.bar == 'foo') {
  // an error is only caught here if it has a 'bar' property of 'foo'
} catch(e if e.bar == 'baz') {
  // there can be different catches for different conditions
} catch (e) {
  // otherwise it's caught here. Without this block, the error would fall
  // through the 'try' and be re-thrown.
}

I haven’t bothered testing this in Internet Explorer (or any other web browser for that matter), because I’m only interested in server-side JavaScript execution at the moment. It works in at least recent SpiderMonkey CVS and Rhino 1.6r6, not sure about earlier versions.

disqus comments  

mod_js - a JavaScript Apache module

09 July 2007 in code
tagged with [apache] [javascript] [programming] [spidermonkey]

mod_js is an Apache module written by Ash Berlin and I that embeds the SpiderMonkey JavaScript engine and lets you run JavaScript code on the server as CGI scripts. As you’d expect, it’s very early, but is good enough to compile scripts, run the JavaScript, and print the output to the client. mod_js is licensed under the GPL3.

read more (231 words).. disqus comments  

Server-side JavaScript under Apache

09 July 2007 in blog
tagged with [apache] [javascript] [programming] [spidermonkey]

Ash Berlin and I recently hacked together an Apache module that embeds the SpiderMonkey JavaScript engine and lets you run JavaScript code on the server as CGI scripts. We called it mod_js.

read more (264 words).. disqus comments  

Google Groups: mozilla.dev.tech.js-engine

07 August 2006 in links
tagged with [javascript] [rhino] [spidermonkey]

This is, apparently, where the real mozilla spidermonkey/rhino mailing list lives, as opposed to merely the one linked from the ‘help’ page as being the official one. Nice.

http://groups.google.com/group/mozilla.dev.tech.js-engine...

disqus comments  

Google Groups: mozilla.dev.tech.js-engine