Author: sebb
Date: Fri Nov 9 11:39:07 2007
New Revision: 593633
URL: http://svn.apache.org/viewvc?rev=593633&view=rev
Log:
Give JavaScript function access to same variables as Jexl
Document the variables for Jexl and Javascript
Modified:
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/JavaScript.java
jakarta/jmeter/trunk/xdocs/changes.xml
jakarta/jmeter/trunk/xdocs/usermanual/functions.xml
Modified:
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/JavaScript.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/JavaScript.java?rev=593633&r1=593632&r2=593633&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/JavaScript.java
(original)
+++
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/JavaScript.java
Fri Nov 9 11:39:07 2007
@@ -77,7 +77,15 @@
try {
Scriptable scope = cx.initStandardObjects(null);
- Object result = cx.evaluateString(scope, script,
"<cmd>", 1, null); //$NON-NLS-1$
+
+ // Set up some objects for the script to play with
+ scope.put("ctx", scope,
currentSampler.getThreadContext()); //$NON-NLS-1$
+ scope.put("vars", scope, vars); //$NON-NLS-1$
+ scope.put("theadName", scope,
currentSampler.getThreadName()); //$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
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=593633&r1=593632&r2=593633&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Fri Nov 9 11:39:07 2007
@@ -90,6 +90,7 @@
<li>Bug 43727 - Test Action does not support variables or functions</li>
<li>The Proxy server removes If-Modified-Since headers from generated Header
Managers by default.
To change the list of removed headers, define the property
proxy.headers.remove as a comma-separated list of headers to remove</li>
+<li>The javaScript function now has access to JMeter variables and context
etc. See <a href="usermanual/functions.html#__javaScript">JavaScript
function</a></li>
</ul>
<h4>Non-functional Improvements</h4>
Modified: jakarta/jmeter/trunk/xdocs/usermanual/functions.xml
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/functions.xml?rev=593633&r1=593632&r2=593633&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/functions.xml Fri Nov 9 11:39:07 2007
@@ -395,6 +395,16 @@
<p>
For details of the language, please see <a
href="http://www.mozilla.org/rhino/overview.html">Mozilla Rhino Overview</a>
</p>
+<p>
+Versions of JMeter after 2.3 make the following variables available to the
script:
+</p>
+<ul>
+<li>ctx - JMeterContext object</li>
+<li>vars - JMeterVariables object</li>
+<li>threadName - String</li>
+<li>sampler - current Sampler object (if any)</li>
+<li>sampleResult - previous SampleResult object (if any)</li>
+</ul>
<note>
JMeter is not a browser, and does not interpret the JavaScript in downloaded
pages.
</note>
@@ -756,8 +766,13 @@
<component index="§-num;.5.18" name="__jexl">
<description>
<p>The jexl function returns the result of evaluating a
- <a href="http://jakarta.apache.org/commons/jexl">Commons JEXL
expression</a>.
+ <a href="http://jakarta.apache.org/commons/jexl">Commons JEXL
expression</a>.
+ See links below for more information on JEXL expressions.
</p>
+ <ul>
+ <li><a href="http://commons.apache.org/jexl/reference/syntax.html">JEXL
syntax description</a></li>
+ <li><a
href="http://commons.apache.org/jexl/reference/examples.html#Example_Expressions">JEXL
examples</a></li>
+ </ul>
</description>
<properties>
@@ -765,6 +780,16 @@
The expression to be evaluated.
</property>
</properties>
+<p>
+JMeter 2.3 (and later versions) make the following variables available to the
script:
+</p>
+<ul>
+<li>ctx - JMeterContext object</li>
+<li>vars - JMeterVariables object</li>
+<li>threadName - String</li>
+<li>sampler - current Sampler object (if any)</li>
+<li>sampleResult - previous SampleResult object (if any)</li>
+</ul>
</component>
<component index="§-num;.5.19" name="__V">
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]