annotate V8/Hello_World.cpp @ 5:a6cc4a802db6

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