Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mix NAPI and v8/Nan within the same addon #2493

Closed
Flarna opened this issue Feb 27, 2020 · 6 comments
Closed

mix NAPI and v8/Nan within the same addon #2493

Flarna opened this issue Feb 27, 2020 · 6 comments
Labels

Comments

@Flarna
Copy link
Member

Flarna commented Feb 27, 2020

  • Node.js Version: 12.x
  • OS: All
  • Scope (install, code, runtime, meta, other?): Native Addons
  • Module (and version) (if relevant):

Are there any limitations in mixing NAPI and v8/NAN within the same native Addon?

There are some v8 APIs not available via NAPI like installing GC callbacks or reading inferred function name from a function object therefore I stick on v8/NAN for some corner cases but would prefer NAPI for the rest.

I would expect that at napi_handle_scope is also a v8 HandleScope. Is that true?
Is it possible to convert between napi_value and v8::Value?

@mhdawson
Copy link
Member

We don't do anything to specifically prevent the combination however:

@mhdawson
Copy link
Member

If the list of things you can't do is small could you paste the list here.

@Flarna
Copy link
Member Author

Flarna commented Feb 28, 2020

That's clear that I have to compiler per major node version as soon as I use NAN/v8. My intention is to get rid of as much as possible from using NAN/v8 simply because of easier maintenance.

Most likely the safer approach would be to register the addon via the legacy API as context aware addon (via NODE_MODULE_INITIALIZE) to ensure loading works only for matching version but then use NAPI for as much as possible.

If the list of things you can't do is small could you paste the list here.

I created following issues a while ago which should cover most cases: nodejs/abi-stable-node#295 and nodejs/abi-stable-node#296

I think CpuProfiler and HeapProfiler are meanwhile available from JS land via inspector.
For the others the result was more or less that they don't fit to NAPI.

@github-actions
Copy link

There has been no activity on this issue for 3 years and it may no longer be relevant. It will be closed 1 month after the last non-automated comment.

@github-actions github-actions bot added the stale label Feb 28, 2023
@mhdawson
Copy link
Member

mhdawson commented Mar 2, 2023

I'm going to close out this issue.

@mhdawson mhdawson closed this as completed Mar 2, 2023
@Flarna
Copy link
Member Author

Flarna commented Mar 3, 2023

completely forgot about this one. Using Napi and v8/NAN seems to work fine, at least I haven't run into issues.

One has to copy over the casting/conversion between Napi <==> v8 handles from node code but as long as this doesn't change there it works.

Main drawback here is that this setup accumulates the disadvantages of both worlds:

  • Napi has higher overhead (might be don't care for a lot users)
  • v8/Nan requires a binary per major node.js version

It's unlikely that all potential relevant v8 APIs will be available via Napi at any time so if one decide to go this path this mixed setup will likely not go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants