void testing()
{ // Initialize V8.
V8::InitializeICU();
Platform* platform = platform::CreateDefaultPlatform();
V8::InitializePlatform(platform);
V8::Initialize();
// Create a new Isolate and make it the current one.
Isolate* isolate = Isolate::New();
{
Isolate::Scope isolate_scope(isolate);
// Create a stack-allocated handle scope.
HandleScope handle_scope(isolate);
scripthelper* sh = new scripthelper();
// Create a new context with a global template
Handle<ObjectTemplate> global = ObjectTemplate::New(isolate);
Local<ObjectTemplate> design_templ = ObjectTemplate::New(isolate);
design_templ->SetInternalFieldCount(1);
Rsyn::Design* d = new Rsyn::Design();
//this line causes a segmentation fault:
Local<Object> obj = design_templ->NewInstance();
obj->SetInternalField(0, External::New(isolate, d));
global->Set(String::NewFromUtf8(isolate, "Design"), FunctionTemplate::New(isolate, designConstructor));
global->Set(String::NewFromUtf8(isolate, "print"), FunctionTemplate::New(isolate, jsprint));
Local<Context> context = Context::New(isolate, NULL, global);
// 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, sh->getSourceFromFile("/home/andreoliv/uplace2/project/src/script/test.js").c_str());
// Compile the source code.
Local<Script> script = Script::Compile(source);
//run script
script->Run();
// Run the desired function
Handle<Value> args[2];
sh->addStringToArguments("HAHA ", args, 0);
sh->addNumberToArguments(5.0, args, 1);
Handle<Value> result = sh->callJSFunction(context->Global(), "JSrepeat", args, 2);
// Convert the result to an UTF8 string and print it.
String::Utf8Value utf8(result);
printf("result: %s\n", *utf8);
sh->callJSFunction(context->Global(), "useCppFunc", args, 2);
}