2

As I understand it Salesforce CommerceCloud uses Rhino JavaScript, but sadly I cannot find what version it is, which is important for understanding compatibility. Is there any documentation that describes this, and/or is there a way to output the JavaScript engine version?

Luke
  • 18,811
  • 16
  • 99
  • 115

2 Answers2

6

Rhino 1.7R5

I was pointed to an answer on GitHub SFCC community docs FAQ (requires login), which cited an official post on a forum from 2016:

... the supported language dialect Demandware Javascript is Rhino Javascript (currently Rhino release 1.7R5) ...

Luke
  • 18,811
  • 16
  • 99
  • 115
  • 1
    And if you're curious what is supported in Rhino, this is very useful: https://mozilla.github.io/rhino/compat/engines.html – Luke Mar 05 '19 at 21:14
0

If the product allows you to execute JavaScript code directly, there are (probably, unless they've configured it in particular ways, e.g., with ClassShutter to disable script access to certain Java classes) ways to get at the Rhino version. The following will return the version as a java.lang.String:

Packages.org.mozilla.javascript.Context.getCurrentContext().getImplementationVersion()

You can convert this to a JavaScript string using the String global function:

var jlsVersion = Packages.org.mozilla.javascript.Context.getCurrentContext().getImplementationVersion();
var jsStringVersion = String(jlsVersion);

EDIT: Poster points out this is a cloud service, not a local installation, so js.jar is not available, and the below method won't help. I'm leaving this this answer up because it may be relevant to others who find this questtion through search.

Assuming they distribute the Rhino JAR file (ordinarily called js.jar), and you can locate it, you can also just execute it (and it will output the version and take you to an interactive JavaScript prompt). Here's a copy on my machine (outside Salesforce):

$ java -jar js.jar
Rhino 1.7 release 3 2011 05 09
js> 
David P. Caldwell
  • 3,394
  • 1
  • 19
  • 32
  • 1
    Since SFCC is a cloud-based service I don't know of a way to locate or execute this JAR file. – Luke Feb 21 '19 at 14:11
  • If it allows you to execute JavaScript code, there are also ways to get at the version directly. Does it? – David P. Caldwell Feb 21 '19 at 14:24
  • I updated the answer above to account for that possibility. – David P. Caldwell Feb 21 '19 at 14:32
  • I know it's been almost a year but: in the SFCC environment `Packages.org.mozilla.javascript.Context.getCurrentContext` appears as an object, not a function (with string value `"[JavaPackage org.mozilla.javascript.Context.getCurrentContext]"`). `Object.keys()` on it reveals the following non-sense structure: `{ "__iterator__": { "__iterator__": {} } }` – Miroslav Genev Oct 29 '19 at 15:01
  • That means the class is not present; it is assuming the string given is a package name (this is an unfortunate consequence of how the `Packages` construct works). – David P. Caldwell Nov 25 '19 at 21:51
  • I would guess that either it is not using Rhino, is using a private build that renames the classes, or is using the stock Rhino that came with the JDK 6 and JDK 7 distributions (replaced by Nashorn in JDK 8). – David P. Caldwell Nov 25 '19 at 21:52