How to detect from driver policy ECMAScript Engine (Rhino/Nashorn/etc) available on specific box, where driver run?

Yesterday I got an interesting case when the policy successfully ran in a Designer simulation after deploying to the server delivered different results.

The deep investigation pointed me in the direction of ECMAScript engine "available" on this specific box.

For compatibility reasons with third-party product, this specific box still has eDirectory 8.8.8.11 and IDM 4.02.7.

Designer 4.8 detected eDir/IDM versions correctly but looks like for simulation use "new" ECMA.

I would like to detect ECMAScript Engine from my driver's policy and depend on this info to execute the "old" version of the ECMA function or the "new" version of the ECMA function.

Currently I "temporarily" started use my own GCV for this selection, but I would like to switch to "fully automated" ECMA Engine detection.

I hope that somebody is aware about the way to detect it (or in ideal situations, can share "ready to use" ECMA function). :)

  • 0  

    Kind regards,

    Sebastijan

    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • Suggested Answer

    0  

    If you don't explicitly set the ECV to use Nashorn (only possible with Java 8) then you are using Rhino. I use this function to determine its version.

    /**
     * Get version of Rhino JavaScript interpreter
     * @since 1.2.8
     * @returns {string} version
     */
    function getRhinoVersion() { // eslint-disable-line no-unused-vars
        var currentContext = Packages.com.novell.soa.script.mozilla.javascript.Context.getCurrentContext();
        return (currentContext.getImplementationVersion());
    }
    

    See this table Rhino ES2015/ES6, ES2016 and ES2017 support (mozilla.github.io) for a list of language features supported by the different vesions.

  • 0   in reply to   

    Thank you very much, Norbert!

    Your function works great!

    I tested it in IDM4.0.2.7 and IDM4.8.7 environments and it provided expected results! Slight smile

    IDM4.0.2.7:

    ST: Action: do-set-local-variable("lvRhinoVersion",scope="policy",token-xpath("es:getRhinoVersion()")).
    ST: arg-string(token-xpath("es:getRhinoVersion()"))
    ST: token-xpath("es:getRhinoVersion()")
    ST: Token Value: "Rhino 1.6 release 1 2004 08 11".

    IDM4.8.7

    >getRhinoVersion()
    Rhino 1.7.7.1 2016 11 17

  • 0 in reply to   

    Hi Norbert,

    I am struggling g with Designer 4.9 to simulate policies containing ECMAScript - the functions are simply not found during simulation - but this is another story!

    When running your function in the ECMAScript Editor it is returning Rhino xyz always, no matter if the compatibility script is included. 

    As you wrote the Switch between Rhino and Nashorn is only possible in JAVA 8, does this mean the ECV is useless after migrating to IDM 4.8.7 or 4.9 since both relay on JAVA 11 and JAVA 11 does only provide the Nashorn Engine?

    No matter whether Rhino or Nashorn is used I came across both are only providing quite old ECMAScript versions (ES 5.1 or ES 6) - Do you know of any plans to provide newer versions for ECMAScript to be used by the IDM Engine and possibly Designer? I doubt the latter will be possible since Designer is still relaying on JAVA 8, is it not?``

    Kind regards 

    Thorsten

  • 0   in reply to 

    As Geoffrey mentioned when IDM 4.9 came out...

    Java 11 for everything but Designer/Analyzer. (Still Java 8 due to older Eclipse build still).


    So... am a bit puzzled that you would be seeing issues with simulating ECMAScript with Designer 4.9. (but then again, after all these years nothing should surprise me when it comes to Designer).


    I was under the impression that the ECMAScript engine in Java story went like this:

    Since Nashorn was totally removed from Java in late 2020. I don't see any point in writing scripts for that engine ever again. The community has far more scripts written for Rhino that we need to keep around until something better comes along.

    From an IDM perspective, I sort of assumed that we were in the "Back to Rhino" stage.
    I assumed this since the IDM developers have long maintained two separate private branches of Rhino (one for the IDM Engine and the other for IDM Apps). The job of merging these two codebases with more recent Rhino development is likely just as hard as updating Designer to use a newer Eclipse.

    I thought it didn't really matter whether the base JRE/JDK bakes in any ECMAScript support or not, as long as the hooks remain to include the vendor's tweaked Rhino version and other Java changes don't break this ancient code.

  • 0 in reply to   

    Hi Alex,

    Actually I have filed in two issues regarding ECMAScript usage in Desinger, both are can be reproduced on Desinger running on MacOS & Windows.

    The first issue is, that as long as an ECMAScript is open in a Desinger Editior/Tab, simulation of a policy fails with the error, the function cannot be found. AS soon as the editor/tab is closed, the simulation io working as expected!

    The other issue is a real strange one:Under certain condition Designer reports that it has detect changes in the file system  and asks to update the code of the ECMAScript - If this option is selected the whole ECMAScript code is replaced by some bogus code, which for sure can not be interpreted as ECMAScript!

    Steps to reproduce are:

    - Open any ECMAScript Object

    - Open any Policy and apply some changes

    - Get back to the ECMAScript

    in most cases I saw the Dialog coming up as described before!

    For both cases I have not received any real solution, and I am starting to believe those two cases are related to each other!

    Regarding the usage of Nashorn or Rhino I have to confess I do not really care, which Engine is used, or possibly will be used in the future - if JAVA 11 is replaced by JAVA 15 or something!

    For me, it would be more interesting to know which ECMAScript version can be used! This is a completely other question, is it not?

    So far I found, the Rhino Engine used only provides compatibility to ES6 (ECMAScript 2017) and according to some JAVA Documentation I found the Nashorn Engine is only compatible with ES 5.1!

    There a quite a few new classes/methods available in current ECMAScript versions, and I am wondering, when we will get support for ES14,15 or possibly 16.

    Kind regards

    Thorsten

     

  • 0   in reply to 

    The first issue is, that as long as an ECMAScript is open in a Desinger Editior/Tab, simulation of a policy fails with the error, the function cannot be found. AS soon as the editor/tab is closed, the simulation io working as expected!

    The other issue is a real strange one:Under certain condition Designer reports that it has detect changes in the file system  and asks to update the code of the ECMAScript - If this option is selected the whole ECMAScript code is replaced by some bogus code, which for sure can not be interpreted as ECMAScript!

    I commonly get the second issue, can confirm your steps to replicate.

    Suspect I have also seen the first issue also but never dug into it as deeply either.

    There is also GraalVM which I believe supports ES15 - but have never seen any talk about bringing that into the IDM space.
    As I said, the IDM team forked Rhino such a long time ago and I guess are stuck with maintaining that for the foreseeable future, especially on the engine side. It is not the best, fastest or most up to date ES implementation. However, it is all we really have (except resorting to custom JARs)

  • 0 in reply to   

    Alex,

    I did some more testing, and finally it seems, Designer is running into the issue not "finding" the function, if the Nashorn script is loaded at the beginning of the ECMAscript.

    I was able to reproduce the issue by 100% in Designer 4.8.7 and 4.9: If the following is added to the ECMAScript

    // load the compatibility functions

    load("nashorn:mozilla_compat.js");

    Desinger will not find any ECMAScript function, while the Engine during processing of a driver does not have any problems at all!

    Digging deeper into this, I found that the Nashorn engine used by the IDM engine (4.9) is only implementing ECMAScript 5.1:

    Initializing Nashorn extensions.
    [08/16/24 10:10:03.988]:Notfall-Prozesse ST:Script Engine : 'Oracle Nashorn', Version : '11.0.22', Script Language : 'ECMAScript', Language Version : 'ECMA - 262 Edition 5.1'.

    But the Rhino Engine used by Designer 4.9 and IDM engine 4.9 is compatible with a more current version of ECMAScript:

    token-xpath("es:getECMAVersion()")
    [08/16/24 10:22:15.822]:Notfall-Prozesse ST: Token Value: "Rhino 1.7.7.1 2016 11 17".

    This should be compatible with ECMAScript version 7!

    If this is true, I do not see any sense in using Nashorn anymore!

    Kind regards

    Thorsten

  • 0   in reply to 

    Rhino's language level is still ES 2009 (5). Only some ES 2015 (6) features are supported: https://mozilla.github.io/rhino/compat/engines.html

    GraalVM does support ES >= 2020: https://www.graalvm.org/latest/reference-manual/js/JavaScriptCompatibility/

    IDM Validator 2 does use GraalVM. That has its own quirks if you have 1.5 testsuites that include JavaScript code written for Rhino: https://www.graalvm.org/latest/reference-manual/js/RhinoMigrationGuide/

  • 0 in reply to   

    Hi Norbert,

    thanks for your comment, but this is quite confusing! According to the function you posted both Designer and IDM Engine are providing Rhino 1.7.7.1 2016 11 17, which should be compatible with ES7, is it not?

    If you are correct, the remaining question is, will opentext in the future support a more current version of ECMAScript or not?

    Kind regards

    Throsten