Comments (6)
Sure, I can try to implement it.
from node-addon-api.
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.
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.
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.
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.
Commited d45ba72
from node-addon-api.
Related Issues (20)
- Just a simple question. HOT 2
- Enabling C++ exceptions on Windows is hell HOT 2
- New SemVer Major release? HOT 4
- Getting sigsegv when passing functions as parameters and building on M1 HOT 4
- Are native addons affected by Node's max memory size constraint? HOT 2
- Running single AsyncWorker at a time HOT 3
- <doc/setup.md> seems outdated HOT 1
- Query on reading/writing js typed arrays from C module. HOT 2
- Request a c++ call js demo. HOT 3
- How to properly handle `Object/Buffer/Uint8Array` in `AsyncWorker`? HOT 9
- How about add C++20 coroutine support to `Napi::Value`? HOT 9
- Node throws exception in main thread (?) when trying to execute event via ThreadSafeFunction HOT 2
- Throwing an object as an exception? HOT 3
- Napi::Value is not properly initialized the first time a program is run HOT 22
- Strange behavior HOT 2
- How do I initialize a variable of type napi_value to NULL to avoid compiler warnings HOT 4
- Failures with VS2022 HOT 4
- Added 22 to test matrixes/deprecate EOL Node.js versions. HOT 2
- Add wrappers for `node_api_nogc_env` and `node_api_nogc_finalize` HOT 8
- `function_reference` test failure when using Debug build of node v20.13.1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-addon-api.