[graalvm-users] Loading JS libraries in JVM and calling their functions later

Nathaniel Mills wnmills3 at gmail.com
Mon Jan 14 13:49:17 PST 2019


In a completely JS application, I would have code like:
var somelib = require('somelib');
and later
var test = somelib(inputStr);
test.evaluate(someMsg);

The somelib returns a function that has parsed the inputStr, and the method
evaluate applies the rule created from the parsed inputStr against the
someMsg json object input.and returns the updated json object.

Is it possible to allow a context for JavaScript to handle the require and
then later reference the variable (somelib) to call its functions?

Is there a recommended way to enable what is required to be "warmed up"
ahead of time?

My goal is to execute this JavaScript library within Java code so ideally I
could create a static or class variable for the library and perform the
warmup in a static function or during construction and reference the
library in other methods as required. Something conceptually like:

Context context = Context.create();
Value somelib = context.eval("js",(var somelib = require("somelib"); var
evalfct = somelib.evaluate; {evaluate : evalfct });
Value newMsg = somelib.evaluate(someMsg);

There was a comment about using ProxyObject but I wasn't sure how to get it
set with the function (evaluate) that I want to call later.

Thanks in advance for your help.

-- 
Best Regards, Nat

Nathaniel Mills
16 Deer Hill Ln
Coventry, CT, 06238

https://urldefense.proofpoint.com/v2/url?u=http-3A__researcher.watson.ibm.com_researcher_view.php-3Fperson-3Dus-2Dwnm3&d=DwIBaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=eZITAP8Wsco5IpfAp3zGFyO9fzoLroCJo2FlSI5rpoM&s=14S2ZNqGXZVRQlspMehnm9acYncNV93l-hhcsv9cwXs&e=
https://urldefense.proofpoint.com/v2/url?u=https-3A__plus.google.com_u_0_110971604421564116308_about&d=DwIBaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=eZITAP8Wsco5IpfAp3zGFyO9fzoLroCJo2FlSI5rpoM&s=CtZuGOJUUMS4DjSzfxmt6DmveJrDqqckYv4TXJeZAiU&e=
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.linkedin.com_profile_view-3Fid-3D5260256&d=DwIBaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=eZITAP8Wsco5IpfAp3zGFyO9fzoLroCJo2FlSI5rpoM&s=aLdyTttp_V5IErEcZxOe0sjXUsjiHZuSI7ih1duyhG4&e=
https://urldefense.proofpoint.com/v2/url?u=https-3A__www.facebook.com_wnmills3&d=DwIBaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=CUkXBxBNT_D5N6HMJ5T9Z6rmvNKYsqupcbk72K0lcoQ&m=eZITAP8Wsco5IpfAp3zGFyO9fzoLroCJo2FlSI5rpoM&s=IfJzoiMFai8oHAhSC-Y77Q2NJFBgWkqmF1gH0-ZTXoc&e=

Please note new email *wnmills3 at gmail.com <wnmills3 at gmail.com>* replaces
nat at classobjects.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://oss.oracle.com/pipermail/graalvm-users/attachments/20190114/094d6d2a/attachment.html 


More information about the GraalVM-Users mailing list