-
Notifications
You must be signed in to change notification settings - Fork 3
Description
I've noticed that TC_JS_MEMBER_FUNCTION generates a non-const member which holds CUniqueDetachableJsFunction since e9b78c5, so the comment above is outdated:
// We do not care about slicing to ref<> or moving from this class, because
// it is only stored as a by-value const field.
template<typename T>
struct CUniqueDetachableJsFunction IIRC, it was possible to tc::jst::function<T> func = std::move(some_object.some_method);, which left some_method inside the object null: although the derived class non-movable, the base class is. Which resulted in an error in the destructor. It was first discovered with lambdas.
Also, moving an object which has JS functions is not generally safe if any of these functions are registered somewhere in the JS world.
A probably better approach may be to somehow restrict move/copy constructors of base classes so they don't move (and copy..?) from nonmovable (and noncopyable../) derived classes. I'm not sure if it's possible because the "move constructor" has a very specific signature.