Which Javascript engine would you embed in your application? [closed] Which Javascript engine would you embed in your application? [closed] javascript javascript

Which Javascript engine would you embed in your application? [closed]


I've tried both SpiderMonkey and V8. With SpiderMonkey, I couldn't get anything to work. I couldn't even get the examples on mozilla.org to compile.

V8 worked out-of-the-box and I got some basic C++ <-> Javascript interaction going pretty quickly. There are some google lists for people using V8, and I found most of my questions answered there already.


Mozilla's SpiderMonkey is fairly easy and well-documented. It's a C API, but it's straightforward to wrap it in C++. It can be compiled to be thread-safe, which is useful for games since you'd likely want to have your main logic in one thread and user interface logic in a second thread.

Google's V8 might be a good choice, since you're using C++, but I have no experience with it yet. According to the documentation (thanks to Daniel James), V8 is not thread-safe, although this may change in the future.

There's also WebKit's SquirrelFish, but I couldn't find a standalone version of that when I was looking earlier.


I believe that v8 only works on x86, x64 and arm processors at the moment. Which might be a disadvantage.

With regards to thread safety, from include/v8.h:

 * Multiple threads in V8 are allowed, but only one thread at a time * is allowed to use V8.  The definition of 'using V8' includes * accessing handles or holding onto object pointers obtained from V8 * handles.  It is up to the user of V8 to ensure (perhaps with * locking) that this constraint is not violated.

You can read more in the source file (it looks like doxygen documentation, but they don't seem to have put it up anywhere).

Update: That comment has been removed, probably some time ago. It looks like v8 now has an Isolate object which represents an instance of the engine. A single Isolate instance can only be used in a single thread at a time, but other Isolate instances can be used in other threads at the same time.