Standalone Javascript interpreter for Linux?

E

Erik Hahn

I'm looking for a standalone Javascript interpreter like the ones of
Perl and Python. Does such a thing exist for Linux?

Thanks in advance.

-Erik
 
S

slebetman

<snip>
SpiderMonkey (C implementation of the same, but not really usable as a
scripting environment)>
<snip>
Mozilla SpiderMonkeyhttp://www.mozilla.org/js/spidermonkey/

The demo js interpreter that comes with SpiderMonkey is actually
really easy to extend. I managed to add file IO capabilities
(fopen,fread,fgets,fputs,fseek,fclose) in around 250 lines of code. I
believe this was the origin of JSDB. JSDB looks really nice especially
the unified Streams API that lets you open files on disk as well as
URI.

I myself have been thinking of implementing a simple binary module/
package system for SipderMonkeys js interpreter (instead of directly
modifying the interpreter) so that you can simply "require" a module
and have it loaded. Lots of languages have gone this path,
implementing a very simple interpreter which is turing complete but
can't do much then load features from modules/packages.
 
P

Peter Michaux

Sometimes I really regret that I haven't done more C programming. I
couldn't even build the stupid thing with support for the old File
object :-/
When I was experimenting with the SpiderMonkey jsshell, all I had was
the readline() function. Unfortunately this function isn't nearly as
useful as I had hoped - it doesn't recognize the EOF, and it seems to
automagically convert all input to Unicode. I had to resort to writing a
Perl wrapper that passed the number of lines to be read to the js file.


I think the interpreter is meant to be embedded anyway, not modified
directly. I think this is what JSDB is doing. If you go ahead with this
and build a usable all-purpose interpreter, count me in as a beta tester.


There's a load() function in jsshell. It works, but it's very basic and
doesn't do any fancy stuff like path management.


A full scripting environment for JS on the command line would be very
exciting. In time, we could even have module repositories like CPAN =)

I'm working on this same idea for Rhino. (Actually my project could
incorporate C implementations as well. I started working on a
Spidermonkey version but moved to Rhino.)

The foundation of what I'm building is a package management client
called xpkg. The intention is this will work like CPAN or apt-get. The
xpkg client I'm building is written in Perl. The language here doesn't
really matter as it is just a command line tool. Clients in other
languages could be written too.

Then the entire JavaScript world of xjs packages can be installed and
managed. The core package does little more than just add "require" and
"load" as host objects. I have packages for a web server, database
access etc. Everything is alpha software and far from feature
complete.

You might be interested in the following.

http://peter.michaux.ca/article/8579

http://groups.google.com/group/xjs-talk/browse_frm/thread/a875887cd0970b68

Peter
 
S

Stephane CHAZELAS

2008-10-31, 01:59(+01), Erik Hahn:
I'm looking for a standalone Javascript interpreter like the ones of
Perl and Python. Does such a thing exist for Linux?
[...]

$ apt-cache search standalone javascript interpreter
kjscmd - A script interpreter using the KDE JavaScript library
spidermonkey-bin - standalone JavaScript/ECMAScript (ECMA-262) interpreter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,137
Messages
2,570,794
Members
47,342
Latest member
eixataze

Latest Threads

Top