Can v8::Isolate::GetCurrent() return null?

584 views
Skip to first unread message

Yutaka Hirano

unread,
Feb 26, 2016, 1:16:50 PM2/26/16
to v8-u...@googlegroups.com
Hi,

I'm writing a unit tests in blink and I want to check if an isolate is disposed in a worker thread. In v8.h, v8::Isolate::GetCurrent() header comment says

  /**
   * Returns the entered isolate for the current thread or NULL in
   * case there is no current isolate.
   *
   * This method must not be invoked before V8::Initialize() was invoked.
   */

, but in the implementation in src/isolate.h, returning null is not allowed.

Which is correct? Can I remove the DCHECK?

Thanks,

Jochen Eisinger

unread,
Feb 29, 2016, 6:45:31 AM2/29/16
to v8-u...@googlegroups.com
Please don't use Isolate::GetCurrent() - it's deprecated.

If you need to know whether the Isolate was disposed or not, why not maintain a boolean flag on the worker thread that keeps track of the isolate's state?

--
--
v8-users mailing list
v8-u...@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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yutaka Hirano

unread,
Feb 29, 2016, 6:48:48 PM2/29/16
to v8-u...@googlegroups.com
I see, thank you.

Bart van Heukelom

unread,
Mar 10, 2016, 4:31:17 AM3/10/16
to v8-users
Where do you see that it's deprecated? http://v8.paulfryzel.com/docs/master/classv8_1_1_isolate.html#afd8c10d0f01e2ae43522c3ddf0bb053d does not mention it. Or has it been..undeprecated in the meantime?

Jochen Eisinger

unread,
Mar 11, 2016, 2:00:16 AM3/11/16
to v8-users

bit.ly/v8-api-changes mentions at the top that we're trying to get to a state where the embedder always specifies the isolate to use and we don't use TLS to store it internally.

At that point, Isolate::GetCurrent will no longer work.

This is, however, still in the not so near future, so I think marking the API add deprecated is premature at this point.

OTOH, Yutaka was asking about usage in chromium, and I'd rather not introduce more call sites there.


On Thu, Mar 10, 2016, 10:31 AM Bart van Heukelom <ma...@bartvh.nl> wrote:
Where do you see that it's deprecated? http://v8.paulfryzel.com/docs/master/classv8_1_1_isolate.html#afd8c10d0f01e2ae43522c3ddf0bb053d does not mention it. Or has it been..undeprecated in the meantime?

--

Bart van Heukelom

unread,
Mar 18, 2016, 8:48:56 AM3/18/16
to v8-users
Is TLS being phased out to access multiple Isolates in a single thread? Does that mean Isolate::Scope will be deprecated as well?
If I'm using just one Isolate (globally or per thread), will it remain safe to store it in my own TLS?

Jochen Eisinger

unread,
Apr 1, 2016, 5:55:55 AM4/1/16
to v8-users
sorry for the late reply.

Yes, it will be possible to track the isolate to use in TLS yourself. Isolate::Scope will probably be a no-op since you'll have to pass the isolate everywhere anyways. Lockers will probably just be a wrapper around a regular mutex.

On Fri, Mar 18, 2016 at 1:49 PM Bart van Heukelom <ma...@bartvh.nl> wrote:
Is TLS being phased out to access multiple Isolates in a single thread? Does that mean Isolate::Scope will be deprecated as well?
If I'm using just one Isolate (globally or per thread), will it remain safe to store it in my own TLS?

--

Joris Wijnant

unread,
May 10, 2016, 10:37:52 AM5/10/16
to v8-users, yhi...@chromium.org
Hi,

Do you know it which cases Isolate::GetCurrent() will return NULL?
because i'm trying to execute the following code

v8::Locker lock(m_pIsolate);
v8::HandleScope scope(m_pIsolate);

v8::Local<v8::Object> v8Global = m_pContext->Get(m_pIsolate)->Global();
v8::Local<v8::Value> v8Value = v8Global->GetRealNamedProperty(v8::String::NewFromUtf8(m_pIsolate, strName.c_str()));

which will break, because GetCurrent does not find the isolate ( call stack at the moment of crash, see below)
simple calling Isolate::GetCurrent() will give the same result.
Jochen mentioned that GetCurrent() will be phased out, to i'm limiting the usage of it, but this case is inside the V8 api, so outside of my control.

I assume that something, somewhere is corrupted. but i have no idea where, can you help me?


  00000000() Unknown
  [Frames below may be incorrect and/or missing]
> VoxJavascriptTest.exe!v8::base::OS::Abort() Line 836 C++
  VoxJavascriptTest.exe!V8_Fatal(const char * file, int line, const char * format, ...) Line 117 C++
  VoxJavascriptTest.exe!v8::internal::Isolate::Current() Line 494 C++
  VoxJavascriptTest.exe!v8::Object::GetRealNamedProperty(v8::Local<v8::Context> context, v8::Local<v8::Name> key) Line 4288 C++
  VoxJavascriptTest.exe!v8::Object::GetRealNamedProperty(v8::Local<v8::String> key) Line 4304 C++
  VoxJavascriptTest.exe!CScriptContext::GetVariable(const ustring & strName, std::shared_ptr<CJSValue> spVariable) Line 470 C++
  VoxJavascriptTest.exe!main(int argc, char * * argv) Line 208 C++
  [External Code]

Ben Noordhuis

unread,
May 10, 2016, 12:14:31 PM5/10/16
to v8-users, yhi...@chromium.org
Hoi Joris, does it work when you stick in an v8::Isolate::Scope after
the v8::Locker? You may want to consider adding a v8::Context::Scope
as well.
Reply all
Reply to author
Forward
0 new messages