Open yuvalp-k2view opened 4 years ago
I wonder if you could wrap your JS execution with a 'with' statement, then use it's lookup to resolve your value:
with(bindingsResolver) {
...CUSTOMER_NAME...
}
where bindingsResolver
would need to be something that allows dynamic property lookup (such as a JS proxy, or possibly you can do it in Java too).
Also, if you don't want to modify your original JS, you could load it and wrap it with a 'with' statement.
(I am not part of the GraalJS project, just saw this and had an idea.)
Good idea, this did actually work. Cannot turn strict mode on but that’s fine. Another issue is if my code has inner functions, it’s losing the scope. I could live with that as well I guess.
What killed the transition from nashorn for us is that maps and lists are not transitioning seamlessly to js objects and vice verse. This means that we have to recursively build complex data bridges to send data to graal and transition the result back to java. Also other languages (python) are experimental without any clear roadmap. So if we need to build a data bridge, not gaining other languages, might as well invest in an integration with v8.
On 27 Mar 2020, at 4:47, Jonathan Gilbert notifications@github.com wrote:
I wonder if you could wrap your JS execution with a 'with' statement, then use it's lookup to resolve your value:
with(bindingsResolver) { ...CUSTOMER_NAME... }
where bindingsResolver would need to be something that allows dynamic property lookup (such as a JS proxy, or possibly you can do it in Java too).
Also, if you don't want to modify your original JS, you could load it and wrap it with a 'with' statement.
(I am not part of the GraalJS project, just saw this and had an idea.)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgraalvm%2Fgraaljs%2Fissues%2F258%23issuecomment-604772765&data=02%7C01%7Cyuval.perlov%40k2view.com%7C80e9510323f54aec2e7508d7d1f0c3e0%7C994f176e677549549f9e0c719b5e9ca0%7C1%7C0%7C637208704324996969&sdata=C2gG0%2FTCDR7OLE89oThxdcYweq7aassOapV1wj1C4Js%3D&reserved=0, or unsubscribehttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAGPA6DWGTESUCKWSHELITWDRJQAR3ANCNFSM4LEIFB4Q&data=02%7C01%7Cyuval.perlov%40k2view.com%7C80e9510323f54aec2e7508d7d1f0c3e0%7C994f176e677549549f9e0c719b5e9ca0%7C1%7C0%7C637208704325006927&sdata=4myDhOQKc%2BqnoqhCWhH5DWhyxuKn%2FoFMOjuQ9FGRiOA%3D&reserved=0.
In our JS environment we want to evaluate first level variable names and supply the values from the execution context (for instance if the JS is run within the context of a result set the variable CUSTOMER_NAME would be picked up automatically and our JS user does not need to write row.CUSTOMER_NAME).
What we do in Nashorn is supply our own javax.script.Bindings implementation. Every time the engine finds a variable, it calls Bindings.get(String) and we are able to return the correct value from the containing code.
This behavior does not carry over when running against the "graal.js" engine. Also, I could not find an equivalent API in the org.graalvm.polyglot.Context API.
Is there a way to achieve this?