Setting the JavaScript version to use

When your policy is written in JavaScript language, you can set the JavaScript version to use for your policy.

Note: This is applicable to Impact Fix Pack 30 or later.

In the Impact policy JavaScript file, add the following line to the start of your policy (namely, the first line in your policy file):

//#VERSION_1_7

This will instruct JavaScript to use the version VERSION_1_7.

Other versions of JavaScript you may set are:

//#VERSION_1_6
//#VERSION_ES6
//#VERSION_1_5

The following table explains what each comment does:

Directive Version

//#VERSION_1_5

JavaScript 1.5

//#VERSION_1_6

JavaScript 1.6

//#VERSION_1_7

JavaScript 1.7

//#VERSION_ES6

ECMAScript 2015

Note: For information about compatibility with ES6 features in JavaScript, refer to the Rhino Compatibility table https://mozilla.github.io/rhino/compat/engines.html
Note: The syntax checker may report syntax errors with keywords and features from newer JavaScript versions. These errors can be ignored.

The Mozilla Rhino version of JavaScript shipped with Impact uses an older ES3 interpretation of parseInt where the 0X strings are treated as octal integers instead of decimal.

With this version of JavaScript, the following code both return NaN (not a number) instead of an integer in a JavaScript policy:

parseInt("08"); // expect 8 but we get NaN
parseInt("09"); // expect 9 but we get NaN

To fix this problem, set the JavaScript version to VERSION_1_7 to use in policy.

If the JavaScript version to use is not set in the policy file, the default version used by the JavaScript will be specified as VERSION_DEFAULT which has a value of 0. For the JavaScript implementation, refer to Rhino documentation: https://mozilla.github.io/rhino/

You can examine the JavaScript version being used when running a policy by setting the Impact log level to debug for the com.micromuse.response.common.parser.JavaScriptPolicy class. The output of the version used will be logged in the Impact log file.

The following log message indicates that JavaScript is using the version VERSION_1_7:

[JavaScriptPolicy] !execute: Setting JS VERSION=170

The following log message indicates that JavaScript is using the version VERSION_DEFAULT:

[JavaScriptPolicy] !execute: Setting JS VERSION=0