Using JavaScript in Your C++ Applications
At the point when Google discharged its Chrome program, the organization incorporated a quick usage of JavaScript called V8, the customer side scripting language incorporated into all programs. Early adopters of JavaScript back in the period of Netscape 4.1 didn’t care for the language in light of the fact that there were no apparatuses for investigating and every program had various usage, and various renditions of Netscape programs contrasted also. It wasn’t a charming composition cross-program code and testing it on loads of various programs.
From that point forward, Google Maps and Gmail tagged along utilizing the entire Ajax (Asynchronous JavaScript and XML) advances, and JavaScript had appreciated a noteworthy rebound. There are presently not too bad instruments for it. Google’s V8, which is written in C++, gathers and executes JavaScript source code, handles memory designation for items, and trash gathers objects it does not require anymore. V8 is such a great amount of quicker than the JavaScript in different programs since it accumulates to local machine code, not bytecode that has been translated.
JavaScript V8V8 isn’t just for use with Chrome. On the off chance that your C++ application requires scripting for clients to have the option to compose code that executes at run-time, at that point you can install V8 in your application. V8 is an open-source superior JavaScript motor authorized under the liberal BSD permit. Google has even given an embedder’s guide.
Here’s a basic model that Google gives—the great Hello World in JavaScript. It is planned for C++ developers who need to implant V8 in a C++ application
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;
}
V8 runs as a standalone program, or it can be embedded in any application written in C++.