changeset 11:2fcaa90d17fc

y
author Sara
date Sat, 15 Feb 2014 11:36:37 -0800
parents ccedccf5a3e2
children 83548221c10d
files V8_tests/Passing_Context_and_compiledScript_to_threads/OneContextAfterOther.cpp V8_tests/Passing_Context_and_compiledScript_to_threads/OneContextAfterOtherTest.cpp
diffstat 2 files changed, 48 insertions(+), 48 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/V8_tests/Passing_Context_and_compiledScript_to_threads/OneContextAfterOther.cpp	Sat Feb 15 11:36:37 2014 -0800
     1.3 @@ -0,0 +1,48 @@
     1.4 +#include <v8.h>
     1.5 +#include <pthread.h>
     1.6 +using namespace v8;
     1.7 +Isolate* isolate;
     1.8 +int main(int argc, char* argv[]) {
     1.9 +   isolate =  Isolate::New();
    1.10 +   {
    1.11 +      if(isolate == NULL){
    1.12 +        printf("Error");
    1.13 +        return 0;
    1.14 +    }
    1.15 +  Locker locker(isolate);
    1.16 +  Isolate::Scope isolate_scope(isolate);
    1.17 +  // Create a stack-allocated handle scope.
    1.18 +  HandleScope handle_scope(isolate);
    1.19 +  // Create a new context.
    1.20 +  Handle<Context> context1 = Context::New(isolate);
    1.21 +  // Enter the context for compiling and running the hello world script.
    1.22 +  Context::Scope context_scope1(context1);
    1.23 +  {
    1.24 +  // Create a string containing the JavaScript source code
    1.25 +  Handle<String> source1 = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
    1.26 +  // Compile the source code.
    1.27 +  Handle<Script> script1 = Script::Compile(source1);
    1.28 +  // Run the script to get the result.
    1.29 +  Handle<Value> result1 = script1->Run();
    1.30 +  // Convert the result to an UTF8 string and print it.
    1.31 +  String::Utf8Value utf81(result1);
    1.32 +  printf("%s\n", *utf81);
    1.33 +}
    1.34 +//create the 2nd context
    1.35 + Handle<Context> context2 = Context::New(isolate);
    1.36 +  // Enter the context for compiling and running the hello world script.
    1.37 +  Context::Scope context_scope2(context2);
    1.38 +  {
    1.39 +  // Create a string containing the JavaScript source code.
    1.40 +  Handle<String> source2 = String::NewFromUtf8(isolate, "'Hi' + ', Dr Sean'");
    1.41 +  // Compile the source code.
    1.42 +  Handle<Script> script2 = Script::Compile(source2);
    1.43 +  // Run the script to get the result.
    1.44 +  Handle<Value> result2 = script2->Run();
    1.45 +  // Convert the result to an UTF8 string and print it.
    1.46 +  String::Utf8Value utf82(result2);
    1.47 +  printf("%s\n", *utf82);
    1.48 +}
    1.49 +  return 0;
    1.50 +  }
    1.51 + }
     2.1 --- a/V8_tests/Passing_Context_and_compiledScript_to_threads/OneContextAfterOtherTest.cpp	Sat Feb 15 11:34:34 2014 -0800
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,48 +0,0 @@
     2.4 -#include <v8.h>
     2.5 -#include <pthread.h>
     2.6 -using namespace v8;
     2.7 -Isolate* isolate;
     2.8 -int main(int argc, char* argv[]) {
     2.9 -   isolate =  Isolate::New();
    2.10 -   {
    2.11 -      if(isolate == NULL){
    2.12 -        printf("Error");
    2.13 -        return 0;
    2.14 -    }
    2.15 -  Locker locker(isolate);
    2.16 -  Isolate::Scope isolate_scope(isolate);
    2.17 -  // Create a stack-allocated handle scope.
    2.18 -  HandleScope handle_scope(isolate);
    2.19 -  // Create a new context.
    2.20 -  Handle<Context> context1 = Context::New(isolate);
    2.21 -  // Enter the context for compiling and running the hello world script.
    2.22 -  Context::Scope context_scope1(context1);
    2.23 -  {
    2.24 -  // Create a string containing the JavaScript source code
    2.25 -  Handle<String> source1 = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
    2.26 -  // Compile the source code.
    2.27 -  Handle<Script> script1 = Script::Compile(source1);
    2.28 -  // Run the script to get the result.
    2.29 -  Handle<Value> result1 = script1->Run();
    2.30 -  // Convert the result to an UTF8 string and print it.
    2.31 -  String::Utf8Value utf81(result1);
    2.32 -  printf("%s\n", *utf81);
    2.33 -}
    2.34 -//create the 2nd context
    2.35 - Handle<Context> context2 = Context::New(isolate);
    2.36 -  // Enter the context for compiling and running the hello world script.
    2.37 -  Context::Scope context_scope2(context2);
    2.38 -  {
    2.39 -  // Create a string containing the JavaScript source code.
    2.40 -  Handle<String> source2 = String::NewFromUtf8(isolate, "'Hi' + ', Dr Sean'");
    2.41 -  // Compile the source code.
    2.42 -  Handle<Script> script2 = Script::Compile(source2);
    2.43 -  // Run the script to get the result.
    2.44 -  Handle<Value> result2 = script2->Run();
    2.45 -  // Convert the result to an UTF8 string and print it.
    2.46 -  String::Utf8Value utf82(result2);
    2.47 -  printf("%s\n", *utf82);
    2.48 -}
    2.49 -  return 0;
    2.50 -  }
    2.51 - }