Created
January 7, 2012 14:47
-
-
Save jcla1/1574928 to your computer and use it in GitHub Desktop.
Exploring the V8 JS engine (Part 1 of 2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <v8.h> | |
using namespace v8; | |
int main(int argc, char* argv[]) { | |
// Create a new context. | |
Persistent<Context> context = Context::New(); | |
// Enter the created context for compiling and | |
// running the hello world program. | |
context->Enter(); | |
// Create a stack-allocated handle scope. | |
HandleScope handle_scope; | |
// Create a string containing the JavaScript code | |
// to execute (notice the quotation). | |
Handle<String> source = String::New(" 'Hello World!'; "); | |
// Compile the Javascript code. | |
Handle<Script> script = Script::Compile(source); | |
// Run the script to get the result. | |
Handle<Value> result = script->Run(); | |
// Get rid of 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment