changeset 9:2650da94fa6f

y
author Sara
date Sat, 15 Feb 2014 11:30:59 -0800
parents 1e2d1d978e4a
children ccedccf5a3e2
files V8_tests/Passing_Context_and_compiledScript_to_threads/OneContextAfterOtherTest.cpp
diffstat 1 files changed, 48 insertions(+), 0 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/OneContextAfterOtherTest.cpp	Sat Feb 15 11:30:59 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 + }