Right, Handle<> (and Local<>) can only be stack allocated and have to live within a HandleScope. If you want to store a reference to a V8 object, you need a Persistent<>, see esp. https://developers.google.com/v8/embed#handles
best -jochen On Sat, Jan 25, 2014 at 8:52 PM, Kevin Ingwersen <ingwie2...@googlemail.com>wrote: > To really store something: > > Persistent<Value> MyVal = Persistent<Value>::New( Value::New() ); > > Replace Value with something like Array, for example. That will give you > an ever-existing value, not devoured by the GC. That, at least, works in my > case o.o; > Am Sa. Jan. 25 2014 19:07:14 schrieb mh: > > Hi. > > A cursory look at the code tells me you aren't quite aware of the > existence of the "monster" called GC in v8. You can't just > store the return value of a call for later use, there ain't any guarantee > the monster won't devour it before you get to it :-). > Search for the term Persistent in this group, and maybe you will find the > answer. Hope it helps. > > > > On Friday, January 24, 2014 2:23:06 PM UTC-6, Pierre Saunier wrote: >> >> Hi, >> >> I want to use V8 as the scripting engine of my 3D modeler... but for the >> moment, I have some troubles... >> >> basicaly, I have a structre like this: >> typedef struct >> { >> v8::Isolate* isolate; >> v8::Handle<v8::ObjectTemplate> global; >> v8::Handle<v8::Context> context; >> v8::Handle<v8::Script> script; >> }v8ScriptEngineDef; >> >> >> a function to compile a script: >> int scriptCompile(char *fileName, char *code, v8ScriptEngineDef >> *v8Engine, >> scriptExternalFuncDef *externalFunc) >> { >> >> v8::HandleScope handle_scope(v8Engine->isolate); >> v8Engine->global = v8::ObjectTemplate::New(); >> v8_create_file_obj(v8Engine->isolate, v8Engine->global); >> v8_create_color_obj(v8Engine->isolate, v8Engine->global); >> v8_create_image_obj(v8Engine->isolate, v8Engine->global); >> v8_create_gui_obj(v8Engine->isolate, v8Engine->global); >> >> v8Engine->global->Set(v8::String::NewFromUtf8(v8Engine->isolate, >> "console"), >> v8::FunctionTemplate::New(v8Engine->isolate, >> v8_console)); >> >> v8Engine->context = v8::Context::New(v8Engine->isolate, NULL, >> v8Engine->global); >> if(v8Engine->context.IsEmpty()) { >> scriptEngineAddToConsole(v8Engine, "Error creating context\n"); >> return FALSE; >> } >> v8Engine->context->Enter(); >> >> v8::TryCatch try_catch; >> v8::Handle<v8::String> v8fileName = >> v8::String::NewFromUtf8(v8Engine->isolate, >> fileName); >> v8::Handle<v8::String> v8code = v8::String::NewFromUtf8(v8Engine->isolate, >> code); >> v8Engine->script = v8::Script::Compile(v8code, v8fileName); >> if(v8Engine->script.IsEmpty()) >> { >> // Print errors that happened during compilation. >> ReportException(v8Engine, v8Engine->isolate, &try_catch); >> return false; >> } >> v8Engine->context->Exit(); >> // scriptRun(engine); >> >> >> return TRUE; >> } >> >> and a running function: >> int scriptRun(v8ScriptEngineDef *v8Engine) >> { >> v8::HandleScope handle_scope(v8Engine->isolate); >> v8::TryCatch try_catch; >> v8Engine->context->Enter(); >> v8::Handle<v8::Value> result = v8Engine->script->Run(); >> if (result.IsEmpty()) >> { >> assert(try_catch.HasCaught()); >> // Print errors that happened during execution. >> ReportException(v8Engine, v8Engine->isolate, &try_catch); >> return false; >> } >> assert(!try_catch.HasCaught()); >> if (!result->IsUndefined()) >> { >> // If all went well and the result wasn't undefined then print >> // the returned value. >> v8::String::Utf8Value str(result); >> const char* cstr = *str; >> scriptEngineAddToConsole(v8Engine, (char *)cstr); >> } >> v8Engine->context->Exit(); >> return true; >> } >> >> The problem is if I call the running function from the Compile function >> (in comment), everythink is working fine. >> But, If I call the compile fonction, then the run function... crash!!! >> >> >> Can somebody explain me what I am doing wrong? >> >> >> thanks, >> >> Pierre >> > > -- > > > > > -- > -- > v8-users mailing list > v8-users@googlegroups.com > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to v8-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.