Mercurial > cgi-bin > hgwebdir.cgi > PR > PR_Integrations > javascript > SpiderMonkey
comparison V8_tests/Two_threads.cpp @ 6:c82791ba5ce1
added two-context test, from botton of pdf, plus pdf
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Sat, 01 Feb 2014 14:26:10 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:743945172523 |
|---|---|
| 1 #include <v8.h> | |
| 2 #include <pthread.h> | |
| 3 using namespace v8; | |
| 4 Isolate* isolate; | |
| 5 void* threadFunction(void*) | |
| 6 { | |
| 7 //Isolate* isolate1 = Isolate::New(); | |
| 8 //{ | |
| 9 if(isolate == NULL) | |
| 10 { | |
| 11 printf("Error1"); | |
| 12 return 0; | |
| 13 } | |
| 14 | |
| 15 Locker locker1(isolate); | |
| 16 //isolate->Enter(); | |
| 17 Isolate::Scope isolate_scope1(isolate); | |
| 18 HandleScope handle_scope1(isolate); | |
| 19 Handle<Context> context1 = Context::New(isolate); | |
| 20 Context::Scope context_scope1(context1); | |
| 21 Handle<String> source1 = String::NewFromUtf8(isolate, "'Hi' + ', Sara'"); | |
| 22 Handle<Script> script1 = Script::Compile(source1); | |
| 23 Handle<Value> result1 = script1->Run(); | |
| 24 String::Utf8Value utf81(result1); | |
| 25 printf("%s\n", *utf81); | |
| 26 //isolate->Exit(); | |
| 27 Unlocker unlocker1(isolate); | |
| 28 | |
| 29 return 0; | |
| 30 } | |
| 31 | |
| 32 int main(int argc, char* argv[]) | |
| 33 { | |
| 34 // Get the default Isolate created at startup. | |
| 35 isolate = Isolate::New(); | |
| 36 if(isolate == NULL) | |
| 37 { | |
| 38 printf("Error"); | |
| 39 return 0; | |
| 40 } | |
| 41 //Sara: the "locker" looks like it's purpose is to make sure only a single | |
| 42 // thread is modifying the isolate.. this goes against the purpose, which | |
| 43 // is for multiple scripts to be running at the same time.. | |
| 44 Locker locker(isolate); | |
| 45 Isolate::Scope isolate_scope(isolate); | |
| 46 // Create a stack-allocated handle scope. | |
| 47 HandleScope handle_scope(isolate); | |
| 48 // Create a new context. | |
| 49 Handle<Context> context = Context::New(isolate); | |
| 50 // Enter the context for compiling and running the hello world script. | |
| 51 Context::Scope context_scope(context); | |
| 52 // Create a string containing the JavaScript source code. | |
| 53 //isolate->Exit(); | |
| 54 Unlocker unlocker(isolate); | |
| 55 pthread_t thread_id; | |
| 56 pthread_create(&thread_id, NULL, &threadFunction,NULL); | |
| 57 //isolate->Enter(); | |
| 58 Handle<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); | |
| 59 // Compile the source code. | |
| 60 Handle<Script> script = Script::Compile(source); | |
| 61 // Run the script to get the result. | |
| 62 Handle<Value> result = script->Run(); | |
| 63 // Convert the result to an UTF8 string and print it. | |
| 64 String::Utf8Value utf8(result); | |
| 65 printf("%s\n", *utf8); | |
| 66 return 0; | |
| 67 //isolate->Dispose(); | |
| 68 } |
