But since then, Google Maps and Gmail came along a few years ago using the whole Ajax (Asynchronous JavaScript and XML) technologies and JavaScript has had a major comeback and there are now one or two decent tools for it. Google's V8 (written in C++) compiles and executes JavaScript source code, handles memory allocation for objects, and garbage collects objects it no longer needs. These design details explain why V8 is so much faster than the JavaScript in other browsers. In short because it compiles to native machine code not bytecode that's interpreted.
If your C++ application requires scripting, i.e. for users to be able to write code that executes at run-time then you could consider embedding V8 in your application. It's licensed under the liberal BSD license. Google have even provided an embedder's guide.
Here's a simple example that Google provides. The classic Hello World in JavaScript (in C++!)
int main(int argc, char* argv[]) {
// Create a string holding the JavaScript source code.
String source = String::New("'Hello' + ', World'") ;
// Compile it.
Script script = Script::Compile(source) ;
// Run it.
Value result = script->Run() ;
// Convert the result to an ASCII string and display it.
String::AsciiValue ascii(result) ;
printf("%s\n", *ascii) ;
return 0;
}
- Link to C++ Code Library

Nice article, keep up the good work!
Very useful. thanks for sharing this
Hi, nice example. But, how do i call that Script::Compile?? how do i initialize it? Thanks
“-D, David, it works great, -)
hey,
can we write any kind of js source code . Ho will the http calls inside js will get execute?
TIA
Libjspp C++ template based wrapper for embedding and extending Javascript engine spidermonkey 1 . 8 . 5 and more
SpiderMonkey? is Mozilla Project’s Javascript/ECMAScript engine.
Libjspp allows C++ developers to embed SpiderMonkey? simply and easily into their applications. Libjspp allows to run multiple Javascript Engines within same process which suits one engine per thread para dime which is helpful in achieving true parallisim. Also Libjspp no way stops user from running multiple threads within engine.
Motivation for writing this library was there does not exist a decent library to wrap Javascript spidermonkey engine , SpiderApe?, Flusspferd are old and are not being maintained and are not up to date with new spidermonkey 1.8.5 API