Porting Narcissus to Rhino

I just spent a couple days trying to build Spidermonkey on Windows with Narcissus, JS_THREADSAFE and JS_HAS_FILE_OBJECT support in order to parse and do some static analysis of  malicious JS.

After patching the the Makefiles (and cpp in one place) and trying way too hard to make it work, I’ve got to warn others off of going down this route. I repeat: DON’T try to make it work. First, you’ll find that there’s no easily available parsing API in spidermonkey itself and that building in extensions is incredibly tedious and error prone (despite the great autoconfig work done in 1.8.1 for the vanilla build, which works perfectly); second, the non-standard File object is no longer maintained and as of Feb 10, 2010 is completely removed.

So with that option DOA, if you had your heart set on using Narcissus for parsing, it can be trivially ported to Rhino. Despite Brendan’s comments in the Narc code and other locations on the web that it relies on several Spidermonkey-specific extensions, it runs perfectly fine (at least the parser does) with a few minor changes. Here is the code, a diff, and sample tree walker.

Leave a Reply