v8::Isolate::GetCurrent() - when can it return null

31 views
Skip to first unread message

Bruce MacNaughton

unread,
Apr 4, 2023, 4:21:21 PM4/4/23
to v8-users
I've written a node extension that works with private data. I see from the function signature that v8::Isolate::GetCurrent() can return NULL, but I don't understand how that's possible, given that my extension is called by JavaScript and has to be running in an isolate.

The v8::Isolate::Current() function has a DCHECK_NOT_NULL, which I infer means that it shouldn't happen. But I don't know when debug checks would be enabled, so that could be a bad inference.

Does it return NULL in specific circumstances, like startup, thread termination, etc.? Can it return 

Ben Noordhuis

unread,
Apr 5, 2023, 4:44:54 AM4/5/23
to v8-u...@googlegroups.com
Yes. :-)

A thread "enters" and "exits" (V8 nomenclature) an isolate. Node
normally enters it and doesn't exit until the thread terminates.

v8::Isolate::TryGetCurrent() exists in case you need to handle the
eventuality of no isolate having been entered.
Reply all
Reply to author
Forward
0 new messages