Reputation: 20907
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?
Upvotes: 19
Views: 12686
Reputation: 4669
Check out Rhino or Spidermonkey. You might want to grab an implementation of the ServerJS standard, like Narwhal while you're at it.
Upvotes: 12
Reputation: 15703
I'm using Scratchpad that is in Firefox under Web Developer tools and JSDB. There is also a list of Javascript shells at MDN. This is when I just want to quickly run javascript code snippets.
Upvotes: 0
Reputation: 21
JSC.exe and a command prompt interface will allow you to compile JScript/JavaScript into a .Net executable right on your desktop.
JSC [JScript Compiler] has a -? or -help function that displays all of the compiler options and flags and is a standalone executable itself. Copy it to a folder of your choice then copy cmd.exe to the same folder and get to coding.Save your source with a .js file extension in the folder with your cmd and jsc executables. Yes, jsc.exe works with regular .js files, but JScript.net tutorials can show you how to build a GUI with buttons and everything for your .js file!
Compile your .js file by starting up the command-line shell (cmd.exe), in the same folder as jsc.exe and your .js file,type jsc then a space and then your .js file's name - hit enter - done. Additionally, jsc outputs debugger errors and warnings to the same cmd.exe that started it with the line and character positions in your .js file where the issue was encountered. You can also get debugging object output saved to a .pdb, for your .js file by typing jsc, a space then typing /debug a space and your .js file name.
/ and - before a flag are managed/read identically, use what's best for you just make sure you don't put debug or any flags in quotations of any sort.
Easy peasy; jsc.exe will run from a usb thumb drive and flash memory cards alike with the only requirement being that the .Net Framework is installed in the host operating system. If you are running newer versions of Windows the .Net framework comes pre-installed anyway; go to the Windows directory/folder of your Windows OS and do a search for jsc.exe and you'll probably get a .Net version of jsc.exe for 2.0 and 4.0 minimally. Copy the version(s) you want to your chosen folder repeating the process to find the cmd.exe.
DONOT cut and paste jsc.exe and cmd.exe - only copy these executables to the directory you wish to run them from. Right click the file(s) and from the context menu click the copy menu selection option. Right click in the directory you created for jsc.exe and cmd.exe and click the context menu selection option paste. You can also single click the file to highlight it then press and the Ctrl key then press the C key to copy the file to the clipboard; single click to highlight or double click to open the directory you created then pressing and holding the Ctrl key press the V key to paste your files in your chosen directory.
Little known facts:
The Mono .Net Framework for Linux might be able to support JScript.Net applications as well, but I have not looked into this topic for some time. The Mono Framework is a Linux compatible .Net Framework following the ECMA specifications for the .NET Framework following the CLS (Common Language Specification [generic com]). The Mono Framework supports a huge part of the ECMA specification and is largely compatible with the Microsoft .Net Framework.
Have a good one.
Upvotes: 2
Reputation: 28448
jslibs is a good standalone JavaScript runtime based on Firefox's JavaScript engine.
Upvotes: 1
Reputation: 4834
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.
Upvotes: 2
Reputation: 179119
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.
Upvotes: 4
Reputation: 1692
You can also try out Google Chrome's JavaScript engine, V8:
http://code.google.com/p/v8/
Upvotes: 6
Reputation: 106920
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:
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.Upvotes: 7
Reputation: 35041
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.
Upvotes: 0
Reputation: 101330
I had a similar question, that wasn't too promising: 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.
Upvotes: 1
Reputation: 281485
Rhino is an open-source implementation of JavaScript written entirely in Java.
Upvotes: 4