V8 is Google's open source JavaScript engine. V8 is written in C++ and is used in Google Chrome, the open source browser from Google. V8 implements ECMAScript as specified in ECMA-262, 5th edition, and runs on Windows (XP or newer), Mac OS X (10.5 or newer), and Linux systems that use IA-32, x64, or ARM processors. V8 can run standalone, or can be embedded into any C++ application.
翻译过来重点就是:V8引擎是一个google开发的开源javascript引擎,它是由C++编写而成,被用在google的开源游览器chrome上。 二、Hello World
学习任何一门语言,“hello world”往往是我们的第一步,这里也不例外,代码如下:
#include <v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Create a new context.
Persistent<Context> context = Context::New();
// Enter the created context for compiling and
// running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Handle<String> source = String::New("'Hello' + ', World!'");
// Compile the source code.
Handle<Script> script = Script::Compile(source);
// Run the script to get the result.
Handle<Value> result = script->Run();
// Dispose the persistent context.
context.Dispose();
// Convert the result to an ASCII string and print it.
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
return 0;
}
具体的编译运行方法可以参见,如下文章:http://code.google.com/intl/zh-CN/apis/v8/get_started.html
作为一名nodejs 的开发者,我要补充一个已经安装好node之后如何正常编译运行该代码,众所周知,nodejs是以来v8引擎的,也就是说当你成功安装好nodejs之后就已经成功安装好v8了,具体方法: