Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (22 sloc) 886 Bytes
#include <stdio.h>
#include "v8/include/v8.h"
int main(int argc, char** argv) {
// Create a stack-allocated handle scope.
v8::HandleScope handle_scope;
// Create a new context.
v8::Persistent<v8::Context> context = v8::Context::New();
// Enter the created context for compiling and running the hello world script.
v8::Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
v8::Handle<v8::String> source(v8::String::New("'Hello' + ', World!'"));
// Compile the source code.
v8::Handle<v8::Script> script(v8::Script::Compile(source));
// Run the script to get the result.
v8::Handle<v8::Value> result(script->Run());
// Dispose the persistent context.
// Convert the result to an ASCII string and print it.
v8::String::AsciiValue ascii(result);
printf("%s\n", *ascii);
return 0;