diff --git a/include/v8.h b/include/v8.h index 50d721378e..9674e0d6ea 100644 --- a/include/v8.h +++ b/include/v8.h @@ -8645,6 +8645,14 @@ class V8_EXPORT Isolate { */ static Isolate* GetCurrent(); + /** + * Returns the entered isolate for the current thread or NULL in + * case there is no current isolate. + * + * No checks are performed by this method. + */ + static Isolate* TryGetCurrent(); + /** * Clears the set of objects held strongly by the heap. This set of * objects are originally built when a WeakRef is created or diff --git a/src/api/api.cc b/src/api/api.cc index 02c8ca3d9d..bfb687f9e2 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -8248,6 +8248,11 @@ Isolate* Isolate::GetCurrent() { return reinterpret_cast(isolate); } +Isolate* Isolate::TryGetCurrent() { + i::Isolate* isolate = i::Isolate::TryGetCurrent(); + return reinterpret_cast(isolate); +} + // static Isolate* Isolate::Allocate() { return reinterpret_cast(i::Isolate::New());