Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    xiolec
    @xiolec
    var enumeratedArray = new Array();
            for (var n in object)
                enumeratedArray.push(n);
    So I want to be able to override "in" so that i can send the values that I want back
    Pavel Medvedev
    @pmed
    I suppose you need to have a custom keys function exposed from your wrapped C++ class. But I never tried this though.
    xiolec
    @xiolec
    nope no luck with that. I'm trying to implement the interceptors right now. Hopefully the enum interceptor is what I want
    xiolec
    @xiolec
    okay I got interceptors to work and it looks like that solves the problem
    xiolec
    @xiolec
    so interceptors seem to only work fully when on the js_function_template, but that doesn't hold the class object. What is the purpose of having both of the function templates? Would it be possible if I wanted to combine them into one? are there any problems that I would encounter?
    xiolec
    @xiolec
    okay I added a objecttemplate to the class_ and applied the interceptors to that. Everything is almost working. Though I also disabled the js_function... just to see what it would do... so far nothing. Was there a purpose for the js_function?
    Pavel Medvedev
    @pmed
    I used it as a well known way to wrap C++objects: http://create.tpsitulsa.com/blog/2009/01/29/v8-objects/
    xiolec
    @xiolec
    oh okay so it's just used for a constructor
    xiolec
    @xiolec
    so if I'm understanding it correctly. The function constructor gets called everytime a new instance of that function is created. So you need to let the function know if it's wrapping or creating a new object then wrapping.
    Do you know what happens with inherited constructors? are they just ignored?
    xiolec
    @xiolec

    so i changed the class function to this

    v8::Local<v8::FunctionTemplate> func = v8::FunctionTemplate::New(isolate_,//);
            //v8::Local<v8::FunctionTemplate> js_func = v8::FunctionTemplate::New(isolate_,
                [](v8::FunctionCallbackInfo<v8::Value> const& args)
                {
                    v8::Isolate* isolate = args.GetIsolate();
                    try
                    {
                        return args.GetReturnValue().Set(instance(isolate).wrap_object(args));
                    }
                    catch (std::exception const& ex)
                    {
                        args.GetReturnValue().Set(throw_ex(isolate, ex.what()));
                    }
                });

    setting the constructor on the class_function_template. then I'm also creating an object template after that

    func->InstanceTemplate()->SetInternalFieldCount(2);
            v8::Local<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate_, class_function_template());
            obj_temp_.Reset(isolate_, obj);

    and in the wrap function I changed it to

    v8::EscapableHandleScope scope(isolate_);
            v8::Local<v8::Object> obj = object_template()->NewInstance();
                //class_function_template()->GetFunction()->NewInstance();
            obj->SetAlignedPointerInInternalField(0, object);
            obj->SetAlignedPointerInInternalField(1, this);

    creating the new instance of the object template appears to not call the constr. I tested it out and so far I don't see any problems with this. Is there anything that you can think of that will go wrong?

    xiolec
    @xiolec
    and i just commented out the js_function to disable it
    xiolec
    @xiolec
    Found a couple memory leaks. The singleton class wasn't being deleted when the isolate is destroyed. Which i managed to fix. and the property data container has like 1700 instances after one run lol.
    Pavel Medvedev
    @pmed
    I think to review class wrapping in some time, the code there seems too complicated.
    Pavel Medvedev
    @pmed
    Yes, class singletons cause memory leaks since they use dynamic memory allocation. But I don't know when and where destroy them because v8::Isolate is created and destroyed outside of the library. I can just add a function to manually cleanup singletons in v8pp for specified isolate.
    What property data container do you mean?
    xiolec
    @xiolec
    struct property_ the call to set_external_data is not calling the delete function when its done.
    xiolec
    @xiolec
    ah yeah I just added the cleanup for the singletons into the context destructor and checked if it had its own isolate. Though If you created the isolate else where it still wouldn't clean up lol. I should get around to uploading all my code lol
    xiolec
    @xiolec
    so I'm not sure what's happening with the property. The set weak on the external data is not being called. Though I did read in the v8 docs that set weak shouldn't be relied on. So, I think I'm going to scrap that and just add all the external data to the class singletons which would then get deleted when the singletons are deleted. or at least that's what I'm going to try
    xiolec
    @xiolec
    wait the properties are actually getting deleted when v8 does full garbagecollection
    except its crashing lol
    Pavel Medvedev
    @pmed
    Well, all I can do on the library side is to add a function to manually unregister v8pp::class in a specified v8::Isolate. There is a similar function v8pp::class::delete_objects which deletes all wrapped C++ objects. Of course access from JavaScript to such wrapped C++ objects would crash V8
    Pavel Medvedev
    @pmed
    properties require to store 2 pointers to member functions. This at least twice more than the v8::External can store. So I use dynamic memory allocation in set_external_data and make such an External a weak reference. You are right and weak references are garbage collected sometimes on full GC.
    Pavel Medvedev
    @pmed
    actually, when a v8::Isolate has a long live time and there are no many v8pp bindings, I don't think this is a significant issue with the non-freed dynamic memory
    xiolec
    @xiolec

    So, anyways I put the dynamic external data into a static class per isolate and just deleted them when the isolate was done. Which works fine for me now. Though I'm curious as to why it was crashing to begin with.

    So, when the weak callback was called to delete the external data it went into that function and deleted the external data fine. then when exiting it went back into global-handlers.cc -PostGarbageCollectionProcessing function. and crashes at CHECK(state() != NEAR_DEATH); Do you know what would cause it to crash here?

    Pavel Medvedev
    @pmed
    I don't know the cause, probably it's an internal GC check in V8 debug version
    btw, I added a v8pp::class_::destroy() function to delete all wrapped C++objects and the class_ instance
    xiolec
    @xiolec

    I uploaded my changes to github. my version of v8pp::context is not finished though. A lot of that was testing around to see what works. Though I eventually will add a callback function for context creation that would allow you to create the global object as a v8pp::class_.

    I added interceptors to v8pp::class_. which is similar to the property. any_object.h was just stuff I was testing out. hopefully allowing a cpp function to accept either a cpp object or a v8 object. I just added v8pp::Function to that file which allows for accepting a function that is either from v8 or from cpp and if the object is passed to v8 with a cpp function that function would be converted so that It could be used within v8. also with that I enabled using std::function as a function withing v8pp.

    reference_tracker.h is just for debugging memory leaks. I should probably change it to a macro.

    v8object_base allows for a persistent object to be stored for a class. I.e. if you put it as a base class on an object that object will remain in memory until it the object is destroyed in cpp. destroying the isolate that the object is attached to also destroys the persistent object. class can also detect if the a class has the base class then just get the v8 object from there instead of searching for the v8 object.
    v8ppdebug.h was just some interceptors that I was using for debugging. they get added to every class object that doesn't already have interceptors when the debugging is enabled.
    xiolec
    @xiolec

    I also added some destroy functions in class_ though those were kinda just put together quickly. also added set_js_const which allows to add a const value on to the js function.

    the interceptors don't include all the static asserts needed. Haven't really tried merging it to your version yet. I need to redo all my changes to v8pp::context first lol.

    also I added the external_data to its own file. and tracked the data that was created and deleted all the data when the isolate is destroyed. I might also add a comparison function to the external_data holder. so that the same data wont be created multiple times but instead is just searched for.
    Yeah, i think I need to completely redo all my changes to the v8pp::context lol
    xiolec
    @xiolec

    Context.hpp is now updated to use callback functions to create a global object with class_

    Added convert functions to automatically convert an object into v8 without importing/referencing first

    Added insertobject functions in class to insert pointers into a v8 object that was already created

    - Requires 2 aligned pointer slots. 
    xiolec
    @xiolec
    Do you know if its possible to create two v8::contexts with the same objecttemplate? Can't get it to stop crashing when the new context is made and the old one still exists.
    xiolec
    @xiolec
    never mind think I found the problem. I was adding instances of objects to the template after it was created on the first context.
    Tim Janik
    @tim-janik
    @pmed can I close #52 and #49 or do you have any reason to keep them open?
    Alexey Zasenko
    @0xDAD
    Hi all! I believe here is the proper place to ask questions like mine. @pmed, have you considered adding CMake support to the project?
    Pavel Medvedev
    @pmed
    Hi @0xDAD,
    Yes, it would be great to have the CMake support. Pull requests are welcomed! :)
    while the library can be mostly used as a header-only, it would be good to have CMake support for quick starting with examples or tests
    Alexey Zasenko
    @0xDAD
    Also, cmake config file could help easily embed and customize the library into user projects. Thanks. Will make request if have something interesting
    Pavel Medvedev
    @pmed
    Super, thanks!
    Alexey Zasenko
    @0xDAD
    Got linking error in case of using v8pp::context and V8PP_HEADER_ONLY defined. Was it intended not to use contexts in header-only implementation? Or maybe I did smth wrong? Thanks
    Alexey Zasenko
    @0xDAD
    error LNK2019: unresolved external symbol "public: __thiscall v8pp::context::context(class v8::Isolate *,class v8::ArrayBuffer::Allocator *,bool)" (??0context@v8pp@@QAE@PAVIsolate@v8@@PAVAllocator@ArrayBuffer@3@_N@Z) 
    error LNK2019: unresolved external symbol "public: __thiscall v8pp::context::~context(void)" (??1context@v8pp@@QAE@XZ)
    Adding context.cpp to the project solves the problem.
    Pavel Medvedev
    @pmed
    This v8pp::context is used mostly for test and in a couple of projects those had V8 embedded. Intent for V8PP_HEADER_ONLY was to use the library without installation in projects for Node.js native add-ons. There you could just add the library as an NPM dependency in package.json. See also these comments: https://github.com/pmed/v8pp/issues/75#issuecomment-397034400 https://github.com/pmed/v8pp/issues/75#issuecomment-397249100
    Alexey Zasenko
    @0xDAD
    Got it. I'm trying to use the library for wrapping business objects for V8 engine embedded into my app. I found it quite straightforward and cppish) Thanks for your time and for sharing!
    Pavel Medvedev
    @pmed
    You are welcome! I've created this library for one similar, so v8pp was designed from requirements to that project.