quickjspp icon indicating copy to clipboard operation
quickjspp copied to clipboard

quickjspp v2

Open ftk opened this issue 3 years ago • 3 comments

This changes the way pointers are stored in JS objects.

v1 (branch master) v2 (branch sharedptr)
js object holds opaque pointer to std::shared_ptr<T> T
std::shared_ptr<T> conversion yes no
qjs::shared_ptr<T> conversion no yes
T* conversion yes only if T has qjs::enable_shared_from_this<T> as base class
extra allocations when converting from C++ pointer to JS object yes(slower) no(faster)
weak_ptr and deleter support std not yet
inheritance support yes limited
creating c++ objects new,std::make_shared qjs::make_shared
<!-- class can evaluate js code no

current v2 limitations:

  • qjs::make_shared needs JSContext
  • all qjs::shared_ptr instances need to be destroyed before js context is destroyed

Also fixes bugs where JS properties are not saved

ftk avatar Dec 11 '21 12:12 ftk

looks great, will give it a try when ready :)

cykoder avatar Dec 11 '21 18:12 cykoder

small bit of feedback, i tried implementing this branch over last weekend to see how itd go with the changes. requiring classes to be inherited from enable_shared_from_this is a bit of a pain in an existing codebase, was much better in V1 where things can be auto exposed. even if i want to have a class that will only be created natively in JS i still need to inherit from that which doesnt seem nessecary

cykoder avatar Sep 16 '22 03:09 cykoder

@SamHellawell I'm agree with you !

enable_shared_from_this is a bad idea.

luodaoyi avatar Jul 10 '23 02:07 luodaoyi