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

Missing node.js support from context library #50

Closed
anthonyskipper opened this issue Aug 27, 2018 · 11 comments
Closed

Missing node.js support from context library #50

anthonyskipper opened this issue Aug 27, 2018 · 11 comments
Assignees
Labels
Node.js Relevant for Graal.js' Node.js recast

Comments

@anthonyskipper
Copy link

We need the ability to call a node.js function from inside the jvm context library. It would be best if this could be called repeatedly. It is completely ok if Node is orphaned from the greater event loop and has no signal access.

@wirthi wirthi self-assigned this Sep 17, 2018
@wirthi
Copy link
Member

wirthi commented Sep 17, 2018

Hi Anthony,

can you please clarify what you mean with "a Node.js function". Do you mean an npm module, or Node.js core functionality ("fs.js")?

If it is plain JavaScript code with no dependency on Node.js, you can likely load it with load(filename) already.

Best,
Christian

@thiagogcm
Copy link

Hi @wirthi
I am able to run plain javascript using the polyglot api on OpenJDK 11 by including the maven dependencies on my project, just like demonstrated here: https://github.com/graalvm/graal-js-jdk11-maven-demo
Is it possible to rely on npm packages as well?

@wirthi
Copy link
Member

wirthi commented Nov 26, 2018

Hi @thiagogcm

When you start from JVM and not from the node binary, you get a JavaScript engine, not the full Node.js ecosystem.

node and npm are binary applications that expect to be started by themselves, standalone. We can cheat in a JVM into those applications (that's what we do in GraalVM), but once you have started a full JVM you cannot inject a node application in the same process. You'd need to start node's eventloop then, ensure it gets access to all the signals it requires, etc. That might be possible, but is outside our current focus.

What you can try, however, is to load npm modules. As long as they contain only JavaScript code and do not try to access core Node.js functionality, that should work. Tools like browserify can help you with that.

Best,
Christian

@wirthi wirthi added the Node.js Relevant for Graal.js' Node.js recast label Mar 8, 2019
@eliasvasylenko
Copy link

It's worth noting that while there is no official support for it from Node.js other applications have successfully embedded node, i.e. so that it can be used as a shared-library without being the entry-point of the application. The obvious example is Electron, but much smaller projects have also managed it such as discussed here and here.

I understand that it is outside the focus of the project itself atm, but if someone were to come along who wanted to do this I assume it would be possible to link against node via JNI or whatever and achieve the same effect for Graal.js.

@eliasvasylenko
Copy link

This issue is a duplicate of #2

@ralleman
Copy link

I found this library https://github.com/apigee/trireme. I'm going to start porting pieces of it under trial (I need net and http initially). Unless someone has a better idea.

@chumer
Copy link
Member

chumer commented Apr 30, 2019

@ralleman
Copy link

Thanks @chumer. I don't think Mike's wrapper will work in my case because I'm running trusted and untrusted code together. The nodejvm wrapper appears to be creating a full-access NodeJS thread first under which everything is run.

@ralleman
Copy link

ralleman commented May 1, 2019

I spent the day working through the trireme code and can now see how to port it. Problem is that it's very old (Node version v0.10 - current version is v12) and the differences between these Node versions is quite significant. Porting it isn't a one-man show I think for this reason.

@psanders
Copy link

I had this issue before with Nashorn, and endup using Nodyn's package loader. I created a repo with an example of my approach. You can also see this working in a larger project.

I hope this helps someone!

@wirthi
Copy link
Member

wirthi commented Feb 27, 2020

Hi,

Since GraalVM 20.0.0, we have experimental support for common.js require().

Best,
Christian

@wirthi wirthi closed this as completed Feb 27, 2020
graalvmbot pushed a commit that referenced this issue Sep 1, 2021
Original commit message:

    Merged: [wasm][liftoff] Fix register usage for i64_addi

    The arm implementation made the assumption that the {lhs} and {dst}
    registers are either the same, or there is no overlap. This assumption
    does not hold.
    ia32 on the other hand has a lot of complicated logic (and unnecessary
    code generation) for different cases of overlap.

    This CL fixes the arm issue *and* simplifies the ia32 logic by making
    the arm assumption hold, and using it to eliminate special handling on
    ia32.

    R=​thibaudm@chromium.org

    (cherry picked from commit 89ca48c907e25ef94a135255092c4e150654c4fc)

    Bug: chromium:1146861
    Change-Id: I96c4985fb8ff710b98e009e457444fc8804bce58
    No-Try: true
    No-Presubmit: true
    No-Tree-Checks: true
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2584242
    Reviewed-by: Thibaud Michaud <thibaudm@chromium.org>
    Commit-Queue: Clemens Backes <clemensb@chromium.org>
    Cr-Commit-Position: refs/branch-heads/8.6@{#50}
    Cr-Branched-From: a64aed2333abf49e494d2a5ce24bbd14fff19f60-refs/heads/8.6.395@{#1}
    Cr-Branched-From: a626bc036236c9bf92ac7b87dc40c9e538b087e3-refs/heads/master@{#69472}

Refs: v8/v8@eddb823

PR-URL: nodejs/node#38275
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Shelley Vohr <codebytere@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Node.js Relevant for Graal.js' Node.js recast
Projects
None yet
Development

No branches or pull requests

7 participants