Giter Club home page Giter Club logo

Comments (6)

sampsongao avatar sampsongao commented on July 27, 2024 1

Sure, I can try to implement it.

from node-addon-api.

sampsongao avatar sampsongao commented on July 27, 2024

So the idea here is that the whatever function the original code use to initialize a new instance (in this case is the Database::New) should be the last thing get called in the ConstructoCallbackWrapper. By the time we call it, all preparation should have been done.

from node-addon-api.

sampsongao avatar sampsongao commented on July 27, 2024

To clarify this problem:
So in Database::New() it creates a new Baton, which calls ObjectWrap->Ref(). However, if we change Database::New to be Database::Database (similar to what is done in Canvas), then in the ConstructorCallbackWrapper, the napi_ref haven't be created by the time Ref() is called.

So I think we should create napi_ref before calling the object-wrapped class constructor.
@mhdawson @jasongin Please tell me if this issue is still not clear.

from node-addon-api.

jasongin avatar jasongin commented on July 27, 2024

This is tricky. The napi_ref is created by the napi_wrap() call, and that can't be called until the class instance is constructed (or at least allocated).

I think the fix should be to move the call to napi_wrap() and reference assignment from ObjectWrap::ConstructorCallbackWrapper() to the ObjectWrap::ObjectWrap() constructor, where it would execute after the instance is allocated but before the subclass constructor. If napi_wrap() returns an error status there, it should be thrown as an exception, which will be caught by the details::WrapCallback() wrapper in ConstructorCallbackWrapper().

@sampsongao Do you want to implement this change or should I?

from node-addon-api.

mhdawson avatar mhdawson commented on July 27, 2024

Unrelated to fixing the current issue, Sampson mentioned that because it does not support the 2 step flow used with Nan, the conversion script cannot make the substitutions automatically and it takes some work to do it manually. Would it make sense to support that flow in addition or instead to make conversion easier ?

from node-addon-api.

sampsongao avatar sampsongao commented on July 27, 2024

Commited d45ba72

from node-addon-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.