| rev |
line source |
|
Sara@4
|
1 #include <v8.h>
|
|
Sara@4
|
2 #include <pthread.h>
|
|
Sara@4
|
3 using namespace v8;
|
|
Sara@4
|
4 Isolate* isolate;
|
|
Sara@4
|
5 void* threadFunction(void*){
|
|
Sara@4
|
6 //Isolate* isolate1 = Isolate::New();
|
|
Sara@4
|
7 //{
|
|
Sara@4
|
8 if(isolate == NULL){
|
|
Sara@4
|
9 printf("Error1");
|
|
Sara@4
|
10 return 0;
|
|
Sara@4
|
11 }
|
|
Sara@4
|
12 Locker locker1(isolate);
|
|
Sara@4
|
13 //isolate->Enter();
|
|
Sara@4
|
14 Isolate::Scope isolate_scope1(isolate);
|
|
Sara@4
|
15 HandleScope handle_scope1(isolate);
|
|
Sara@4
|
16 Handle<Context> context1 = Context::New(isolate);
|
|
Sara@4
|
17 Context::Scope context_scope1(context1);
|
|
Sara@4
|
18 Handle<String> source1 = String::NewFromUtf8(isolate, "'Hi' + ', Sara'");
|
|
Sara@4
|
19 Handle<Script> script1 = Script::Compile(source1);
|
|
Sara@4
|
20 Handle<Value> result1 = script1->Run();
|
|
Sara@4
|
21 String::Utf8Value utf81(result1);
|
|
Sara@4
|
22 printf("%s\n", *utf81);
|
|
Sara@4
|
23 //isolate->Exit();
|
|
Sara@4
|
24 Unlocker unlocker1(isolate);
|
|
Sara@4
|
25
|
|
Sara@4
|
26 return 0;
|
|
Sara@4
|
27
|
|
Sara@4
|
28 }
|
|
Sara@4
|
29 int main(int argc, char* argv[]) {
|
|
Sara@4
|
30
|
|
Sara@4
|
31 // Get the default Isolate created at startup.
|
|
Sara@4
|
32 isolate = Isolate::New();
|
|
Sara@4
|
33 {
|
|
Sara@4
|
34 if(isolate == NULL){
|
|
Sara@4
|
35 printf("Error");
|
|
Sara@4
|
36 return 0;
|
|
Sara@4
|
37 }
|
|
Sara@4
|
38 Locker locker(isolate);
|
|
Sara@4
|
39 Isolate::Scope isolate_scope(isolate);
|
|
Sara@4
|
40 // Create a stack-allocated handle scope.
|
|
Sara@4
|
41 HandleScope handle_scope(isolate);
|
|
Sara@4
|
42 // Create a new context.
|
|
Sara@4
|
43 Handle<Context> context = Context::New(isolate);
|
|
Sara@4
|
44 // Enter the context for compiling and running the hello world script.
|
|
Sara@4
|
45 Context::Scope context_scope(context);
|
|
Sara@4
|
46 // Create a string containing the JavaScript source code.
|
|
Sara@4
|
47 //isolate->Exit();
|
|
Sara@4
|
48 Unlocker unlocker(isolate);
|
|
Sara@4
|
49 pthread_t thread_id;
|
|
Sara@4
|
50 pthread_create(&thread_id, NULL, &threadFunction,NULL);
|
|
Sara@4
|
51 //isolate->Enter();
|
|
Sara@4
|
52 Handle<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
|
|
Sara@4
|
53 // Compile the source code.
|
|
Sara@4
|
54 Handle<Script> script = Script::Compile(source);
|
|
Sara@4
|
55 // Run the script to get the result.
|
|
Sara@4
|
56 Handle<Value> result = script->Run();
|
|
Sara@4
|
57 // Convert the result to an UTF8 string and print it.
|
|
Sara@4
|
58 String::Utf8Value utf8(result);
|
|
Sara@4
|
59 printf("%s\n", *utf8);
|
|
Sara@4
|
60 return 0;
|
|
Sara@4
|
61 }
|
|
Sara@4
|
62 //isolate->Dispose();
|
|
Sara@4
|
63 }
|