Best way to get spidermonkey js on Ubuntu?

妖精的绣舞 提交于 2019-12-30 01:52:06

问题


I need to install the Spidermonkey JS engine on my work machine. The project I'm working on has a jslint script that requires Spidermonkey or a similar js binary. I've tried compiling Spidermonkey from source and gotten stuck in dependency hell. I tried installing the rhino package from the ubuntu repositories, and that turned out to be slow and broken. This morning, I successfully compiled Google's V8 engine and built v8jslint following the instructions here:

http://blog.stevenreid.co.uk/2011/06/27/jslint-command-line-tool-powered-by-v8/

v8jslint works, but will only lint one file at a time. For instance,

$ v8jslint foo/*.js

if I have a.js, b.js and c.js under foo, v8jslint will only lint a.js. Easy fix: I could write a bash script for this. A bigger problem is that v8jslint is not compatible with the Spidermonkey jslint on our build server. Has anyone had any success building Spidermonkey on a recent version of Ubuntu, or know a good workaround?


回答1:


You can build from source, but spider monkey is still available on ubuntu, it's just been renamed to "libmozjs". Install "libmozjs-24-bin" and then either refer to it as "js24" or symlink /usr/bin/js24 to "js", like so:

sudo apt-get install libmozjs-24-bin; sudo ln -sf /usr/bin/js24 /usr/bin/js



回答2:


Fixed it. You need the 'autoconf2.13' package. Install it with apt-get. Go to the SpiderMonkey source code page on Mozilla. Find the hg repository (linked below) and download a snapshot of the Mozilla tree. Don't clone it, just get the archive as .tar.gz or .tar.bz2 from the top bar.

http://hg.mozilla.org/index.cgi/mozilla-central/file/tip

Unzip the archive and cd into the root directory.

$ cd js/src
$ autoconf2.13
$ ./configure
$ make

This should make a binary called js. For some reason, when I ran make install, it did not copy js into /bin/. I just symlinked /bin/js to point to ~/.../mozilla/js/src/js. Lint scripts work now and I don't have to start a build to fix lint errors anymore :P

Source:

https://developer.mozilla.org/en/SpiderMonkey_Build_Documentation

Note: the above link calls for the command autoconf-2.13. I think this is a typo; you want to use autoconf2.13 as I wrote in the code.




回答3:


update:

looks like spidermonkey-bin is no longer available through the launchpad ppa

plus the v8jslint repo was down when I tried to clone it.




回答4:


Also, (via #2: spidermonkey-bin not availble in Ubuntu Lucid - Issues - hallettj/jslint.vim - GitHub), can use PPA for Launchpad Engineering : “Canonical Launchpad Engineering” team:

sudo add-apt-repository ppa:launchpad/ppa
sudo apt-get update
sudo apt-get install spidermonkey-bin
apt-cache show spidermonkey-bin
sudo apt-get install spidermonkey-bin # also installs extra: libmozjs2d

# .. and then: 
$ js --help
JavaScript-C 1.8.0 pre-release 1 2007-10-03
usage: js [-zKPswWxCij] [-t timeoutSeconds] [-c stackchunksize] [-o option] [-v version] [-f scriptfile] [-e script] [-S maxstacksize] [scriptfile] [scriptarg...]
$ js
js> var f = function(){ print("the answer is " + 42); }; 
js> f();
the answer is 42
js> ^C
$



回答5:


Install the package libmozjs-24-bin. It contains the Spidermonkey JavaScript shell binary /usr/bin/js24 which you can the be installed as an alternative for the command js.

sudo apt-get install libmozjs-24-bin
sudo update-alternatives --install /usr/bin/js js /usr/bin/js24 10


来源:https://stackoverflow.com/questions/6656904/best-way-to-get-spidermonkey-js-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!