From 2b11a57d47e9a0862fa965c87107c540db92df0f Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sun, 5 Jul 2020 17:28:13 +0200 Subject: [PATCH] Refactor 'v8__internal__GetIsolateFromHeapObject' (#415) It turns out that using `v8::internal::MaybeObject` was, although harmless, not appropriate here, because this function does not deal deal with (potentially) weak handles. --- src/binding.cc | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/binding.cc b/src/binding.cc index 9cef8e1c..68d5562d 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -10,7 +10,8 @@ #include "v8/include/v8.h" #include "v8/src/execution/isolate-utils-inl.h" #include "v8/src/execution/isolate-utils.h" -#include "v8/src/objects/maybe-object.h" +#include "v8/src/objects/objects-inl.h" +#include "v8/src/objects/objects.h" using namespace support; @@ -1720,18 +1721,15 @@ void v8__HeapProfiler__TakeHeapSnapshot(v8::Isolate* isolate, 'v8_enable_shared_ro_heap' feature enabled. #endif -v8::Isolate* v8__internal__GetIsolateFromHeapObject(const v8::Data& location) { - auto address = *reinterpret_cast(&location); - auto maybe_object = v8::internal::MaybeObject(address); - if (maybe_object.IsSmi() || maybe_object.IsCleared()) { - return nullptr; - } - auto heap_object = maybe_object.GetHeapObject(); - v8::internal::Isolate* isolate; - if (!v8::internal::GetIsolateFromHeapObject(heap_object, &isolate)) { - return nullptr; - } - return reinterpret_cast(isolate); +v8::Isolate* v8__internal__GetIsolateFromHeapObject(const v8::Data& data) { + namespace i = v8::internal; + i::Object object(reinterpret_cast(data)); + i::Isolate* isolate; + return object.IsHeapObject() && + i::GetIsolateFromHeapObject(object.GetHeapObject(), &isolate) + ? reinterpret_cast(isolate) + : nullptr; +} } } // extern "C"