Mercurial > cgi-bin > hgwebdir.cgi > PR > PR_Integrations > javascript > SpiderMonkey
comparison V8/Hello_World.cpp @ 5:a6cc4a802db6
the code
| author | Sara |
|---|---|
| date | Sat, 01 Feb 2014 08:51:00 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:680c83a09b10 |
|---|---|
| 1 #include <v8.h> | |
| 2 | |
| 3 using namespace v8; | |
| 4 | |
| 5 int main(int argc, char* argv[]) { | |
| 6 // Get the default Isolate created at startup. | |
| 7 Isolate* isolate = Isolate::GetCurrent(); | |
| 8 | |
| 9 // Create a stack-allocated handle scope. | |
| 10 HandleScope handle_scope(isolate); | |
| 11 | |
| 12 // Create a new context. | |
| 13 Handle<Context> context = Context::New(isolate); | |
| 14 | |
| 15 // Enter the context for compiling and running the hello world script. | |
| 16 Context::Scope context_scope(context); | |
| 17 | |
| 18 // Create a string containing the JavaScript source code. | |
| 19 Handle<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); | |
| 20 | |
| 21 // Compile the source code. | |
| 22 Handle<Script> script = Script::Compile(source); | |
| 23 | |
| 24 // Run the script to get the result. | |
| 25 Handle<Value> result = script->Run(); | |
| 26 | |
| 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 } |
