Esempio n. 1
0
int main(){
  // Initialize V8.
  V8::InitializeICU();
  //V8::InitializeExternalStartupData(argv[0]);
  Platform* platform = platform::CreateDefaultPlatform();
  V8::InitializePlatform(platform);
  V8::Initialize();

  // Create a new Isolate and make it the current one.
  ArrayBufferAllocator allocator;
  Isolate::CreateParams create_params;
  create_params.array_buffer_allocator = &allocator;
  Isolate* isolate = Isolate::New(create_params);
  

  exec(isolate); 

  // Dispose the isolate and tear down V8.
  isolate->Dispose();
  V8::Dispose();
  V8::ShutdownPlatform();
  delete platform;
  return 0;

}
Esempio n. 2
0
    AutoIsolateCleanup::~AutoIsolateCleanup() {
      while (Isolate::GetCurrent()) {
        // Isolates can be entered multiple times
        Isolate* i {Isolate::GetCurrent()};

        //internal::Isolate* ii {internal::Isolate::FromAPIIsolate(i)};
        //V8MONKEY_ASSERT(!ii->IsLockedForThisThread(), "An isolate was still locked");

        while (Isolate::GetCurrent() == i) {
          i->Exit();
        }

        i->Dispose();
      }
    }
Esempio n. 3
0
int main(int argc, char **argv) 
{
    // Initialize V8.
    V8::InitializeICU();
    Platform* platform = platform::CreateDefaultPlatform();
    V8::InitializePlatform(platform);
    V8::Initialize();

    //Quite simple, these are scope based 'managers'.
    //One protects threading issues, and one manages
    //the creation of JS handles, for clean up.

    Isolate* isolate = Isolate::New();
    {
        Isolate::Scope isolate_scope(isolate);

        // Create a stack-allocated handle scope.
        HandleScope handle_scope(isolate);

        // Create a new context.
        Local<Context> context = Context::New(isolate);

        //A context is a fresh execution context. Take for example, 
        //a browser tab or frame in Google Chrome. Each of these are
        //a new context, stamped with a global template, and created
        //on demand. When executing scripts, you can execute them in 
        //and existing context by using the Context::context_scope 
        //handlers. This 'switches' context for that execution period
        Context::Scope context_scope(context);

        //If we receive an argument, execute the script file

        if(argc > 1) {
            eScriptExecResult r = executeScript(isolate, context, string(argv[1]));
        } else {
            printf("Usage: <scriptname.js> \n Execute the javascript file.");
        }

    }

    // Dispose the isolate and tear down V8.
    isolate->Dispose();
    V8::Dispose();
    V8::ShutdownPlatform();
    delete platform;
    return 0;
}
Esempio n. 4
0
INT32_MAIN_INT32_ARGC_TCHAR_ARGV()
{
	GEngineLoop.PreInit(ArgC, ArgV);
	UE_LOG(LogUnrealNode, Display, TEXT("Hello World"));

	// Initialize V8.
	V8::InitializeICU();
	//V8::InitializeExternalStartupData(ArgV[0]);
	Platform* platform = platform::CreateDefaultPlatform();
	V8::InitializePlatform(platform);
	V8::Initialize();

	// Create a new Isolate and make it the current one.
	ArrayBufferAllocator allocator;
	Isolate::CreateParams create_params;
	create_params.array_buffer_allocator = &allocator;
	Isolate* isolate = Isolate::New(create_params);
	{
		Isolate::Scope isolate_scope(isolate);

		// Create a stack-allocated handle scope.
		HandleScope handle_scope(isolate);

		// Create a new context.
		Local<Context> context = Context::New(isolate);

		// Enter the context for compiling and running the hello world script.
		Context::Scope context_scope(context);

		// Create a string containing the JavaScript source code.
		Local<String> source =
			String::NewFromUtf8(isolate, "'Hello World' + ' from JavaScript'",
				NewStringType::kNormal).ToLocalChecked();

		// Compile the source code.
		Local<Script> script = Script::Compile(context, source).ToLocalChecked();

		// Run the script to get the result.
		Local<Value> result = script->Run(context).ToLocalChecked();

		// Convert the result to an UTF8 string and print it.
		String::Utf8Value utf8(result);
		printf("%s\n", *utf8);

	}

	// Dispose the isolate and tear down V8.
	isolate->Dispose();
	V8::Dispose();
	V8::ShutdownPlatform();
	delete platform;



	//uv_idle_t idler;

	//uv_idle_init(uv_default_loop(), &idler);
	//uv_idle_start(&idler, wait_for_a_while);

	//printf("Idling...\n");
	//uv_run(uv_default_loop(), UV_RUN_DEFAULT);

	//uv_loop_close(uv_default_loop());


	return 0;


}