@@ -48,15 +48,15 @@ class object_registry final : public class_info
48
48
using const_pointer_type = typename Traits::const_pointer_type;
49
49
using object_id = typename Traits::object_id;
50
50
51
- using ctor_function = pointer_type (*)( v8::FunctionCallbackInfo<v8::Value> const & args);
52
- using dtor_function = void (*)( v8::Isolate*, pointer_type const &);
51
+ using ctor_function = std::function< pointer_type (v8::FunctionCallbackInfo<v8::Value> const & args)> ;
52
+ using dtor_function = std::function< void ( v8::Isolate*, pointer_type const &)> ;
53
53
using cast_function = pointer_type (*)(pointer_type const &);
54
54
55
- object_registry (v8::Isolate* isolate, type_info const & type, dtor_function dtor)
55
+ object_registry (v8::Isolate* isolate, type_info const & type, dtor_function&& dtor)
56
56
: class_info(type, type_id<Traits>())
57
57
, isolate_(isolate)
58
- , ctor_(nullptr ) // no wrapped class constructor available by default
59
- , dtor_(dtor)
58
+ , ctor_() // no wrapped class constructor available by default
59
+ , dtor_(std::move( dtor) )
60
60
{
61
61
v8::HandleScope scope (isolate_);
62
62
@@ -121,7 +121,7 @@ class object_registry final : public class_info
121
121
return to_local (isolate_, js_func_);
122
122
}
123
123
124
- void set_ctor (ctor_function ctor) { ctor_ = ctor; }
124
+ void set_ctor (ctor_function&& ctor) { ctor_ = std::move ( ctor) ; }
125
125
126
126
void add_base (object_registry& info, cast_function cast)
127
127
{
@@ -344,7 +344,7 @@ class classes
344
344
public:
345
345
template <typename Traits>
346
346
static object_registry<Traits>& add (v8::Isolate* isolate, type_info const & type,
347
- typename object_registry<Traits>::dtor_function dtor)
347
+ typename object_registry<Traits>::dtor_function&& dtor)
348
348
{
349
349
classes* info = instance (operation::add, isolate);
350
350
auto it = info->find (type);
@@ -354,7 +354,7 @@ class classes
354
354
throw std::runtime_error ((*it)->class_name ()
355
355
+ " is already exist in isolate " + pointer_str (isolate));
356
356
}
357
- info->classes_ .emplace_back (new object_registry<Traits>(isolate, type, dtor));
357
+ info->classes_ .emplace_back (new object_registry<Traits>(isolate, type, std::move ( dtor) ));
358
358
return *static_cast <object_registry<Traits>*>(info->classes_ .back ().get ());
359
359
}
360
360
@@ -450,25 +450,27 @@ class class_
450
450
}
451
451
};
452
452
453
- static void factory_destroy (v8::Isolate* isolate, pointer_type const & obj)
454
- {
455
- factory<T, Traits>::destroy (isolate, Traits::template static_pointer_cast<T>(obj));
456
- }
457
-
458
- using ctor_function = object_pointer_type (*)(v8::FunctionCallbackInfo<v8::Value> const & args);
459
- using dtor_function = void (*)(v8::Isolate* isolate, pointer_type const & obj);
453
+ using ctor_function = std::function<object_pointer_type (v8::FunctionCallbackInfo<v8::Value> const & args)>;
454
+ using dtor_function = std::function<void (v8::Isolate* isolate, object_pointer_type const & obj)>;
460
455
461
456
public:
462
- explicit class_ (v8::Isolate* isolate, dtor_function destroy = factory_destroy)
463
- : class_info_(detail::classes::add<Traits>(isolate, detail::type_id<T>(), destroy))
457
+ explicit class_ (v8::Isolate* isolate, dtor_function destroy = &factory<T, Traits>::destroy)
458
+ : class_info_(detail::classes::add<Traits>(isolate, detail::type_id<T>(),
459
+ [destroy = std::move(destroy)](v8::Isolate* isolate, pointer_type const & obj)
460
+ {
461
+ destroy (isolate, Traits::template static_pointer_cast<T>(obj));
462
+ }))
464
463
{
465
464
}
466
465
467
466
// / Set class constructor signature
468
467
template <typename ...Args, typename Create = factory_create<Args...>>
469
- class_& ctor (ctor_function create = Create::call)
468
+ class_& ctor (ctor_function create = & Create::call)
470
469
{
471
- class_info_.set_ctor (reinterpret_cast <typename object_registry::ctor_function>(create));
470
+ class_info_.set_ctor ([create = std::move (create)](v8::FunctionCallbackInfo<v8::Value> const & args)
471
+ {
472
+ return create (args);
473
+ });
472
474
return *this ;
473
475
}
474
476
0 commit comments