I'm trying to run crypto-js in PreProcessor JSR223 but i have an error (see below.
I don't found a solution to resolve it, can you check please?
javax.script.ScriptException: SyntaxError: crypto-js.js:1424:48 Expected , but found =
stringify: function (wordArray, urlSafe=true) {
^ in <eval> at line number 1
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:470) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:454) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) ~[nashorn.jar:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) ~[nashorn.jar:?]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) ~[?:1.8.0_202]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:219) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:45) ~[ApacheJMeter_components.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:978) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:561) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:501) ~[ApacheJMeter_core.jar:5.5]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268) ~[ApacheJMeter_core.jar:5.5]
at java.lang.Thread.run(Thread.java:748) ~[?:1.8.0_202]
Caused by: jdk.nashorn.internal.runtime.ECMAException: SyntaxError: crypto-js.js:1424:48 Expected , but found =
stringify: function (wordArray, urlSafe=true) {
Load cryptoJs.js with success
Nashorn is a Java implementation which supports ECMAScript 5.1
ECMAScript 5.1 was released in 2011 and now it's 2023 that's why it cannot support ECMAScript 6 or higher, that's why you're getting the error.
You could try looking for an archive version of crypto-js which is ECMAScript 5.1 compatible but I don't think it's something you should be doing because Nashorn itself was removed in OpenJDK 15
So I would recommend re-implementing your cryptography logic in Groovy language, moreover it's the most performing scripting engine and it's recommended for using by JMeter authors.
Related
if (oldPresenter?.userId !== currentPresenterId) {
return setPresenterInPodReqMsg(setPresenterPayload);
}
I got syntax error in this snippet running with Node.js but working for other people. I need explanation if it is correct JS syntax.
You are using optional chaining. It is in Stage 4.
Optional chaining is supported in node version v14.2.0 or higher!
?. is called the optional chaining operator. On the last versions of node it's valid syntax.
This javascript syntax will be reported incorrect for any Node version < 14. To be able to use this format ( specifically the ?. optional chaining syntax ), first check your node version using node -v on your commandline, and if < 14, then update to a Node version >=14.
After upgrading to the latest closure compiler jar I am getting this error:
/home/users/****/js/lib/soyutils.js:1685:
WARNING - [JSC_BAD_JSDOC_ANNOTATION] Parse error. illegal use of unknown JSDoc tag "consistentIdGenerator"; ignoring it
* #consistentIdGenerator
How can I fix this issue?
According to my research you'll want to convert #consistentIdGenerator to
#idGenerator {consistent}.
It seems that #consistentIdGenerator has been deprecated:
NOTE: There are three deprecated variants: #idGenerator, #consistentIdGenerator, and #stableIdGenerator. These map to #idGenerator {unique}, #idGenerator {consistent}, and #idGenerator {stable}. Support for these will be removed in a future compiler release.
I have something like this:
var arr = []
arr.indexOf(element => element.includes(''))
QtCreator gives error for this. My Qt version is 5.12 and I'm using QtCreator 4.8.
Can I use this kind of lambda expressions in QML?
That was just a QtCreator bug, arrow functions are supported in Qt 5.12 and later. QtCreator properly supports them starting 4.9 version and stop displaying warnings for it (QTCREATORBUG-21301 & QTCREATORBUG-20341. See 4.9 changelog).
In your case however, as folibis said, you need findIndex if you want to provide a predicate. It does work in 5.12, the page of the supported functions is not very reliable.
Qt 5.12 should support most of the standard ECMAScript functions, look at MDN for reference and try it your Qt code.
{
let arr = ['a', 'ab', 'abc', 'abcd'];
let index = arr.findIndex(element => element.includes('c'));
let abcIsPresent = arr.includes('abc');
print(index, abcIsPresent);
}
This codes runs in Qt 5.12 and outputs 2 true.
Here's an excerpt from Chapter 2 Names:
A name cannot be one of these reserved words:
... delete ...
Then later in that section:
Names are used for ... property names...
If that's true, then why does this work in my browser console:
> a = {};
> a.delete = 1;
> a.delete + 2 === 3
true
I'm using "Version 36.0.1985.143 m" of Google Chrome for my browser and Windows 8.1 Enterprise for my OS.
Does the author mean property names should not be a reserved word or am I missing something?
When the book was written, ECMAScript 3 ruled the earth and that was a true statement.
However, modern browsers are running ECMAScript 5, which has lifted that requirement.
If you have IE, put yourself into IE6 or IE7 compatibility mode and it will fail.
BTW, even with ECMAScript 3, you can still write it as
a["delete"]
I am trying to experiment with the Script defined in Get timestamp difference using ANT SO question.
When I use the Date.parse as given in the example, I get a NullPointerException on the line for Javascript i.e. on this line
<script language="javascript" >
It seems to be somehow related to the Date.parse call, but I don't seem to be able to figure it out.
<script language="javascript" >
<![CDATA[
println("calc js");
project.setProperty("task.diff",
Math.abs(
(Date.parse(project.getProperty("task.stop")) +
+project.getProperty("task.stop.millis")) -
(Date.parse(project.getProperty("task.start")) +
+project.getProperty("task.start.millis"))))
]]>
When I used the same concept in another script, making some changes to the original script, I get a different error -
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing ) after argument list (#7) in at line number 7
Here I am sending startTime and endTime as attributes to a macrodef and defining the script inside it.
project.setProperty("task.diff",
Math.abs(
Date.parse(#{startTime}) -
Date.parse(#{endtime})
)
);
How can I go about debugging this issue?
sun.org.mozilla refers to the Rhino JavaScript engine. Date.parse() is not supported by Rhino, unless you have a recent version:
New in Rhino 1.7R3
Use the Rhino console to check the version:
java -jar $RHINOPATH/js.jar #Rhino, `$RHINOPATH` is environment specific
jrunscript -q #Rhino via Mustang
References
Command Line Shell Scripting in Mustang
Java 6 Scripting is no js.jar
e4X is not Mustang
JavaScript Debugging Tips for Mustang
More JavaScript Debugging Tips for Mustang