From f9a91bb18aa60b2d581f429dbac41a2adaa0f2b4 Mon Sep 17 00:00:00 2001 From: Jacob Sologub Date: Tue, 8 Oct 2019 12:35:05 -0700 Subject: [PATCH 1/2] Now using v8::MaybeLocal::ToLocal when getting object and function values inside detail::object_registry::wrap_object() --- v8pp/class.ipp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/v8pp/class.ipp b/v8pp/class.ipp index 3bdbf797..02f084b1 100644 --- a/v8pp/class.ipp +++ b/v8pp/class.ipp @@ -198,20 +198,21 @@ V8PP_IMPL v8::Local object_registry::wrap_object(pointer_typ v8::EscapableHandleScope scope(isolate_); v8::Local context = isolate_->GetCurrentContext(); - v8::Local obj = class_function_template() - ->GetFunction(context).ToLocalChecked()->NewInstance(context).ToLocalChecked(); - - obj->SetAlignedPointerInInternalField(0, Traits::pointer_id(object)); - obj->SetAlignedPointerInInternalField(1, this); - - v8::Global pobj(isolate_, obj); - pobj.SetWeak(this, [](v8::WeakCallbackInfo const& data) - { - object_id object = data.GetInternalField(0); - object_registry* this_ = static_cast(data.GetInternalField(1)); - this_->remove_object(object); - }, v8::WeakCallbackType::kInternalFields); - objects_.emplace(object, wrapped_object{ std::move(pobj), call_dtor }); + v8::Local obj{}; + v8::Local func{}; + if (class_function_template()->GetFunction(context).ToLocal (&func) && func->NewInstance(context).ToLocal(&obj)) { + obj->SetAlignedPointerInInternalField(0, Traits::pointer_id(object)); + obj->SetAlignedPointerInInternalField(1, this); + + v8::Global pobj(isolate_, obj); + pobj.SetWeak(this, [](v8::WeakCallbackInfo const& data) + { + object_id object = data.GetInternalField(0); + object_registry* this_ = static_cast(data.GetInternalField(1)); + this_->remove_object(object); + }, v8::WeakCallbackType::kInternalFields); + objects_.emplace(object, wrapped_object{ std::move(pobj), call_dtor }); + } return scope.Escape(obj); } From c52efcbd05c8e2b1a83eae37bc147e0a6511511e Mon Sep 17 00:00:00 2001 From: Jacob Sologub Date: Thu, 7 Nov 2019 19:51:55 -0800 Subject: [PATCH 2/2] A more future proof major/minor v8 version check inside v8pp::convert::from_v8 v8 8.x is around the corner and the current check fails. https://github.com/pmed/v8pp/pull/123/commits/4ce49efb36379f31219d6bf09cf01f48b373e43a --- v8pp/convert.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v8pp/convert.hpp b/v8pp/convert.hpp index eca21e94..03e993c0 100644 --- a/v8pp/convert.hpp +++ b/v8pp/convert.hpp @@ -142,7 +142,7 @@ struct convert { throw invalid_argument(isolate, value, "Boolean"); } -#if defined (V8_MAJOR_VERSION) && V8_MAJOR_VERSION >= 7 && defined (V8_MINOR_VERSION) && V8_MINOR_VERSION >= 1 +#if ((V8_MAJOR_VERSION << 16) + (V8_MINOR_VERSION << 8)) >= ((7 << 16) + (1 << 8)) return value->BooleanValue(isolate); #else return value->BooleanValue(isolate->GetCurrentContext()).FromJust();