-
Notifications
You must be signed in to change notification settings - Fork 190
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
Java Map to JS Object via experimental-foreign-object-prototype Has No Members #143
Comments
AFAIK, there is no special support for |
@iamstolis Thanks for the quick response. Yes, we're using ProxyObject, but hoping that:
|
@hashtag-smashtag Thanks a lot for the suggestions. Yes allowMapAccess is planned to be added. There are some changes to the interop protocol required for this, that will take a bit longer. Expect this to land in the next 2-3 releases/months. |
I'm using
What are the pros/cons compared to eg ProxyObject.fromMap() ? |
@hanzr This issue is so one doesn't need to create a proxy nor assemble an object manually like your snippet. Btw some cons of that approach instead of a Proxy: additional boilerplate, additional object(s)/memory, JS object isn't linked to Java map such that additions/deletions to the JS object are not mirrored to the Java map |
@chumer I hate to be the one that asks, but how's the estimate of 2-3 months looking? It's a blocker because we have a bunch of user scripts out there that we can't break, using x.y and x['y'] syntax on java maps that are nested in deep object graphs, so we can't proxy them. Unless there is some other workaround for applying proxies, or modifying the Object prototype somehow? |
Basically you need to proxy all the way down, wrap getter() return values in a Proxy if they return Map, or the equivalent for your setup.. can be pretty tough if you don't own the objects in question, or can't easily change them though. Would be much nicer if it was OTB. |
I don't think its going to be practical to recursively proxy the whole graph, unfortunately. So just have to suck it up and wait... |
I have a question on this issue. If you use the method If this issue is resolved would you have member access as well as access to map methods? Also would those map methods follow the JS Map methods or Java Map methods, would it use |
@everestbt With the requested |
Hey @chumer is this still in the works, or on an updated roadmap? Many thanks. |
That's a blocker for us as well, any update on this one? |
Guys, FYI it's the 15th of December, 2-3 releases/months already gone. |
Hi, sorry for the delay. The feature is currently scheduled for our GraalVM 20 release early next year. I will check with @chumer to make sure someone is actually working on it. |
Hello, Thanks |
Also, looking... very interested as to when it can work. I think that without this Graal cannot be considered a Nashorn replacement. |
This is a real show stopper for the migration of https://magnews.com to JDK15 and switch from Nashorn to GrallVM JS |
It is still unavailable. |
Is there a repair plan for this problem? Nearly two years! We've dealt with it temporarily in the following ways, but it has brought about other problems
|
As a workaround we had to build our own And note if the members can be nested maps/lists, |
It does solve the problem, thanks |
Is there any new timeline for allowMapAccess? In theory we could replace all maps with MapProxy as @hashtag-smashtag suggests, but I would prefer if there was another easier way. |
Hello team! |
I cannot understand; how they removed the Nashorn engine from JDK 15 before fixing this? |
Noone understand why they removed working code at all |
I have created a PR for this. There might be some missing points 'cause I am not fully familiar with the complete architecture. If you guide me for the missing points. I can try to add but basic functionality seems working. |
Thank you!There’s List as well, that will be great to have “natively” in the js |
Lists work already. From the initial comment on this issue:
|
With PR I have tested those: with bindings.putMember("list", List.of("1", "2", "3"));
assert "1".equals(context.eval(JavaScriptLanguage.ID, "list[0]").asString()); dot notation and indexed access using ProxyObject for bindings.putMember("map", ProxyObject.fromMap(Map.of("one", 1)));
assert Integer.valueOf(1).equals(context.eval(JavaScriptLanguage.ID, "map['one']").asInt());
assert Integer.valueOf(1).equals(context.eval(JavaScriptLanguage.ID, "map.one").asInt()); with bindings.putMember("map", Map.of("one", 1));
assert Integer.valueOf(1).equals(context.eval(JavaScriptLanguage.ID, "map['one']").asInt());
assert Integer.valueOf(1).equals(context.eval(JavaScriptLanguage.ID, "map.one").asInt()); TBH: I have no idea why there are those configuration options like |
I'm on 21.0.0.2 (not SemVer compliant - you should consider using SemVer for your versions going forward) and I don't see The issue here is nested objects. If I have a POJO like this:
I can't pass this to Graal JS at all. Instead, I have to convert this to a Map, proxy it, and then convert it back to a POJO. Not ideal and I'm not sure why Graal doesn't handle this with core Java types and collections. EDIT: In addition to this POJO issue, it appears that even the
And send that in via Java code like this:
At the end of this call, the Map does not contain the value I'm doing a lot of converting back and forth to JSON and Collections using Jackson with a lot of recursion to fix this all up because Graal JS is not properly handling Maps and Lists. EDIT # 2: Doing a recursive proxy does work. The code is nasty, but I'm happy to post it somewhere for others to use if anyone needs it. My comment here is getting pretty long, but I could post it here as well. |
@voidmain Not really. It's even worse, if you'd assign an object value in the js, it will be PolyglotMap or PolyglotList, which is
For your example, suppose that you set user.otherStuff.testing={ f: 'v' }, then 'testing' will be stored as PolyglotMap inside your ProxyObject, so, you need to convert it as well. Graal is inconsistent even in itself, but uses AbstractMap and AbstractList inside. It's sad that devs are focused on runing nodejs but not on real needs. Recursion is good, but in case java objects are large and there are many of them, it will be a real hassle to convert and overall performance will be just terrible. The good news is, that nashorn is still alive and available as a standalone module here: https://github.com/openjdk/nashorn |
Hi @voidmain thanks for your post.
Can you please clarify what you mean with "at all"? You can't pass it, you can't access it in Java semantics, you can't access it in JavaScript semantics?
That's exactly what we are doing and what others above are complaining about. We treat What is not working to the full extend currently is accessing the Best, |
Good news everyone: Support for this will finally land in 21.1.0. Using |
PS: |
I'm using RC15. Here's a failing test (in Groovy) that shows the issue:
I noticed for Java List -> JS Array to work required using not only
experimental-foreign-object-prototype
but alsohostAccessBuilder.allowListAccess(true)
. Are we missing some equivalent.allowMapAccess(boolean)
API?The text was updated successfully, but these errors were encountered: