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

Invoking/Driving the org.graal.polyglot API's from non-JVM languages (blocked on #631) #3605

Closed
GavinRay97 opened this issue Jul 19, 2021 · 2 comments
Assignees

Comments

@GavinRay97
Copy link
Contributor

GavinRay97 commented Jul 19, 2021

Feature request

It would be really incredible to be able to utilize non-JVM languages to drive Polyglot GraalVM programs.

I'm most experienced with Javascript/Typescript, and have a couple years of professional Ruby dev experience + use Python (like most folks I assume) occasionally for random tasks.

Unfortunately, though Graal supports all of these languages for the most part, the only place where it doesn't really is if you want to use them to be the host language and call out to other languages as guests 🙁

What this scenario would look like in Graal, illustrated by @chumer is roughly:

try(Context context = Context.newBuilder("js").allowAllAccess(true).build()) {
    context.eval("js", "" +
                    "var Context = Java.type('org.graalvm.polyglot.Context');" +
                    "var c = Context.newBuilder().build();" +
                    "c.eval('js', \"console.log('Hello inner world!')\");" +
                    "c.close();");
}

Or, as you'd be running it in the actual scenario (IE a Graal Node process):

var Context = Java.type('org.graalvm.polyglot.Context');
var c = Context.newBuilder().build();
// Could be Python, Ruby, whatnot
c.eval('js', "console.log('Hello inner world!')");
c.close();

But as of now, due to #631 the problem is that this causes:

Hello inner world!
Exception in thread "main" The value 'DynamicObject<undefined>@39d76cb5' cannot be passed from one context to another. The current context is 0x4a00d9cf and the argument value originates from context 0x6736fa8d.
	at <js> :program(Unnamed:1:93-141)
	at org.graalvm.polyglot.Context.eval(Context.java:379)
	at testgraalvm.Test.main(Test.java:18)

Christian mentioned a fix for this may be targeted for 21.3.0 but I just wanted to file the issue here in case anyone else was interested in tracking this.

I tried this tonight with 21.3.0-dev from latest nightly releases and it hasn't changed yet, just in case anyone else is curious

(Feel free to close if this isn't acceptable/wanted)

Express whether you'd like to help contributing this feature
If you'd like to contribute, please read the contribution guide.

Sure, I'm not certain I can be of much use but I'll help out where I can if wanted =)

@munishchouhan
Copy link
Contributor

@GavinRay97 Thanks for the feature, we will check it out and get back to you

@GavinRay97
Copy link
Contributor Author

Fixed/closed by commit 8d70605

🎉 🥳

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

No branches or pull requests

3 participants