Mercurial > cgi-bin > hgwebdir.cgi > PR > PR_Integrations > javascript > SpiderMonkey
changeset 5:a6cc4a802db6
the code
| author | Sara |
|---|---|
| date | Sat, 01 Feb 2014 08:51:00 -0800 |
| parents | 469c49d5aa02 |
| children | c82791ba5ce1 |
| files | V8/Hello_World.cpp |
| diffstat | 1 files changed, 31 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/V8/Hello_World.cpp Sat Feb 01 08:51:00 2014 -0800 1.3 @@ -0,0 +1,31 @@ 1.4 +#include <v8.h> 1.5 + 1.6 +using namespace v8; 1.7 + 1.8 +int main(int argc, char* argv[]) { 1.9 + // Get the default Isolate created at startup. 1.10 + Isolate* isolate = Isolate::GetCurrent(); 1.11 + 1.12 + // Create a stack-allocated handle scope. 1.13 + HandleScope handle_scope(isolate); 1.14 + 1.15 + // Create a new context. 1.16 + Handle<Context> context = Context::New(isolate); 1.17 + 1.18 + // Enter the context for compiling and running the hello world script. 1.19 + Context::Scope context_scope(context); 1.20 + 1.21 + // Create a string containing the JavaScript source code. 1.22 + Handle<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); 1.23 + 1.24 + // Compile the source code. 1.25 + Handle<Script> script = Script::Compile(source); 1.26 + 1.27 + // Run the script to get the result. 1.28 + Handle<Value> result = script->Run(); 1.29 + 1.30 + // Convert the result to an UTF8 string and print it. 1.31 + String::Utf8Value utf8(result); 1.32 + printf("%s\n", *utf8); 1.33 + return 0; 1.34 +}
