String resultStr = "";
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects(null);
// Set up some objects for the script to play with
scope.put("log", scope, log); //$NON-NLS-1$
scope.put("ctx", scope, jmctx); //$NON-NLS-1$
scope.put("vars", scope, vars); //$NON-NLS-1$
scope.put("props", scope, JMeterUtils.getJMeterProperties()); //$NON-NLS-1$
// Previously mis-spelt as theadName
scope.put("threadName", scope, Thread.currentThread().getName()); //$NON-NLS-1$
scope.put("sampler", scope, currentSampler); //$NON-NLS-1$
scope.put("sampleResult", scope, previousResult); //$NON-NLS-1$
Object result = cx.evaluateString(scope, script, "<cmd>", 1, null); //$NON-NLS-1$
resultStr = Context.toString(result);
if (varName != null && vars != null) {// vars can be null if run from TestPlan