view V8/Hello_World.cpp @ 5:a6cc4a802db6

the code
author Sara
date Sat, 01 Feb 2014 08:51:00 -0800
parents
children
line source
1 #include <v8.h>
3 using namespace v8;
5 int main(int argc, char* argv[]) {
6 // Get the default Isolate created at startup.
7 Isolate* isolate = Isolate::GetCurrent();
9 // Create a stack-allocated handle scope.
10 HandleScope handle_scope(isolate);
12 // Create a new context.
13 Handle<Context> context = Context::New(isolate);
15 // Enter the context for compiling and running the hello world script.
16 Context::Scope context_scope(context);
18 // Create a string containing the JavaScript source code.
19 Handle<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
21 // Compile the source code.
22 Handle<Script> script = Script::Compile(source);
24 // Run the script to get the result.
25 Handle<Value> result = script->Run();
27 // Convert the result to an UTF8 string and print it.
28 String::Utf8Value utf8(result);
29 printf("%s\n", *utf8);
30 return 0;
31 }