tags:

views:

1323

answers:

9

Bit of a strange question here i know.

but i wanted to know if some kind of standalone engine for javascript exists..

basically i want to test running of my javascript without having to load a web page...

Maybe it doesn't exist? Like some kind of ide where i can run commands directly without launching IE etc...

I have a great editor but it doesn't support that.. i still need to launch ie / firefxo

What i was thinking of some kind of standalone javascript engine existed that i could write my code here and make debugging a bit easier... and then copy to my webpage.

I know firebug exists but you can't specifically do what i am asking cna you?

Any ideas?

+3  A: 

Rhino is an open-source implementation of JavaScript written entirely in Java.

RichieHindle
+1  A: 

I had a similar question, that wasn't too promising: http://stackoverflow.com/questions/993968/is-there-a-javascript-ide-that-has-nothing-to-do-with-a-browser

I think the best answer there was Mozilla Rhino - although for your purposes, a server-side javascript-related bundle may fit the bill. The engines they use tend to be either Rhino or Spidermonkey, with a few other random ones.

Tom Ritter
+7  A: 

Check out Rhino or Spidermonkey. You might want to grab an implementation of the ServerJS standard, like Narwhal while you're at it.

Noah Medling
Thanks, sorry for the delay in answering.
mark smith
A: 

Using Rhino or SpiderMonkey you can have a standalone JS engine, or include it in other applications you write; but you won't be able to test anything to do with the Document Object Model (DOM), such as manipulating elements and attributes or responding to events.

Everything to do with the DOM is supplied by the browser as a host environment in which the JavaScript engine runs. No browser means no DOM.

If the code you are planning to work on has absolutely no dependency on anything provided by the browser environment then you could start by looking at the Rhino Shell.

EDIT: Microsoft's JScript is also a standalone COM component which you can run under Windows Script Host. The object model available in that environment offers a basic level of access to the Windows shell.

NickFitz
+3  A: 

As for the engine - it's actually built in Windows itself and IE just uses it for webpages. Try it - you can make a simple .js file and run it. It's a great replacement for .bat files actually. :) You can also cscript.exe (for console) and wscript.exe (for windows app) to run your scripts. It's actually what Windows internally runs when you double-click a .js file.

As for debugging - I don't know. I know that:

  • Visual Studio supports script debugging, at least for browsers (but probably in other apps to that integrate with the Windows Scripting Host);
  • There is a separate "Script Debugger" downloadable for free from Microsoft, though last I checked it was pretty crappy;
  • The above mentioned cscript.exe and wscipt.exe have command-line parameters that have something to do with script debugging, although I don't know what they do.
Vilx-
+4  A: 

You can also try out Google Chrome's JavaScript engine, V8:
http://code.google.com/p/v8/

Coding With Style
A: 

Sounds like you might be looking for a server side type implementation of javascript. Aptana's Jaxer is one that hasn't been mentioned above. I havn't actually tried it, but apparently it allows you to manipulate the DOM as you would on the client side, but before being sent to the browser. I'd imagine it would also go together with their excellent Aptana IDE.

Steve Mc
+2  A: 

Many people here have recommended Rhino or other server-side implementations. But from what I read, you want something that should emulate the browser environment. In that regard, what I'd try (that means I haven't used this combination before) is Mozilla Rhino and env.js. While I've been using Mozilla Rhino for quite some time now, I can't say too much for env.js.

env.js is an emulation of the browser environment. It was originally developed by John Resig, but Chris Thatcher made it look as it is right now. Which in my opinion looks very promising. Haven't tried it before but I'd give it a chance.

Ionuț G. Stan
A: 

I have found out recently that if you have Visual Studio installed you can debug JScripts with it by invoking a script like cscript test.js //X which pops up the Just In Time debugger window.

Then you can step line by line through the script with all the benefits of a real debugger.

Cristian Adam