Skip to content

Node.js Feature Request: Embedded Host API & NativeWrapperGen Solution with Decorator and Tool Support & Infrastructure Change #51824

Closed as not planned

Description

@congzhangzh

What is the problem this feature will solve?

Using JavaScript as a library and plugin extension for existing C/C++ programs requires a substantial amount of work, where writing glue code is particularly complex and error-prone.

What is the feature you are proposing to solve the problem?

Key Features:

  1. Define a basic type table(reference ffi)and decorate functions (export2c in nativegen.js)
  2. Auto-generate .h, .cc, and Makefile files from a library file (library.js/plugin.js) where functions are already decorated using export2c from nativegen.js
  3. Nativegen.js implement the tools main function

Technical Challenges:

1.	Is it necessary to run the libuv event loop on a separate thread? Merely pump out the event queue is insufficient as code with persistent logic (such as a server) will not function.
2.	For sync api, communication with the event loop by async handle/async send? Implement send call with c++ promise from caller, activate c++ promise on finish call, and return values on the C/C++ side.
3.	For async api(promise handling): set callback on V8 promise to activate c++ promise for valueb back to caller.
4.	Exception propagation: from JavaScript to C++, including catch, wrapper, and rethrow mechanisms.

Infrastructure change Requirements:

Include with node-embedded.tar(like python)

•	node.h, v8.h (and all related child.h), uv.h
•	libnode.lib (win), libuv.lib (win)
•	libnode.so/libnode.dll, libuv.dll(win)

References:

  1. https://nodejs.org/api/embedding.html
  2. https://github.com/nodejs/node/blob/HEAD/test/embedding/embedtest.cc
  3. https://v8.dev/docs/embed
  4. https://github.com/v8/v8/blob/main/samples/process.cc
  5. https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial
  6. https://github.com/TooTallNate/ref/blob/6951bf7fdcef0dfa7e0b65d93f68d36aabdedef7/lib/ref.js#L831
  7. https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting#hosting-apis
  8. https://github.com/AaronRobinsonMSFT/DNNE
  9. https://cffi.readthedocs.io/en/latest/embedding.html
  10. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html
  11. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#interacting-with-code-call-javascript-from-native
  12. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#implement-c-in-javascript
  13. https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#embind-val-guide
  14. https://emscripten.org/docs/porting/asyncify.html
  15. https://github.com/danbev/learning-v8/tree/master
  16. https://docs.python.org/3.6/using/windows.html#embedded-distribution
  17. httpsq://www.python.org/ftp/python/3.11.8/python-3.11.8-embed-amd64.zip

What alternatives have you considered?

Do all the work by hand is possible, but very verbose and error prone.

Activity

  1. github-actions commented on Sep 6, 2024

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Issues and PRs exempt from automated stale handling. label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
    For more information on how the project manages feature requests, please consult the feature request management document.

  2. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Sep 6, 2024
  3. github-actions commented on Oct 6, 2024

    @github-actions
    Contributor

    There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions