On Tue, Feb 11, 2014 at 10:29 PM, Geoff Morrison <[email protected]> wrote: > On Tuesday, February 11, 2014 2:47:48 AM UTC-8, Ben Noordhuis wrote: >> >> On Tue, Feb 11, 2014 at 12:11 AM, Geoff Morrison <[email protected]> wrote: >> > I'm trying to Enter a Context in one Locker, then use it in another: >> > >> > v8::Isolate *isolate = v8::Isolate::New(); >> > { >> > v8::Locker locker(isolate); >> > isolate->Enter(); >> > } >> > >> > v8::Persistent<v8::Context> pctxt; >> > { >> > v8::Locker locker(isolate); >> > v8::HandleScope handleScope(isolate); >> > v8::Local<v8::Context> ctxt = v8::Context::New(isolate); >> > ctxt->Enter(); >> > pctxt.Reset(isolate, ctxt); >> > } // Error occurs here, on locker dtor >> > >> > { >> > v8::Locker locker(isolate); >> > v8::HandleScope handleScope(isolate); >> > v8::Local<v8::Context> ctxt = >> > v8::Local<v8::Context>::New(isolate, pctxt); >> > ctxt->Exit(); >> > } >> > >> > This causes an assertion failure in a debug build: >> > # Fatal error in ../src/api.h, line 577 >> > # CHECK(entered_contexts_.length() == 0) failed >> > and a fatal error in a release build: >> > # Fatal error in v8::Context::Exit() >> > # Cannot exit non-entered context >> > >> > The assertion fails because the dtor of a top-level Locker releases >> > thread-local resources, which includes the list of entered contexts. >> > >> > I'm able to work around this by heap-allocating a Locker/Unlocker pair >> > after >> > entering the isolate (before the declaration of pctxt): >> > v8::Locker *toplock = new v8::Locker(isolate); >> > v8::Unlocker *topunlock = new v8::Unlocker(isolate); >> > and deleting them when I dispose of the isolate, but this is ugly and >> > goes >> > counter to the way I see these APIs being used. >> > >> > Is there a better way to solve this problem? >> >> Hi Geoff, is there a reason you cannot (or don't want to) exit the >> Context before unlocking the isolate again? Do you need Lockers and >> Unlockers in the first place? > > > I want to be able to run a script against a context, then access values out > of that context later. > > This is actually working fine without Locker/Unlocker, but I'm adding > Lockers so I can add debugger support: > http://code.google.com/p/v8/wiki/AddDebuggerSupport
Okay, is there anything stopping you from exiting the context, then entering it again when you want to retrieve those values? Store the context in a Persistent<Context> if you're worried that V8 will prematurely garbage-collect it. -- -- v8-users mailing list [email protected] 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
