[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit/javascript JavaScript.java,1.33,1.34
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-10-24 13:28:59
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript
In directory usw-pr-cvs1:/tmp/cvs-serv28243/src/com/meterware/httpunit/javascript
Modified Files:
JavaScript.java
Log Message:
Added support for document.write
Index: JavaScript.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/javascript/JavaScript.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- JavaScript.java 22 Oct 2002 20:15:34 -0000 1.33
+++ JavaScript.java 24 Oct 2002 13:28:54 -0000 1.34
@@ -102,16 +102,30 @@
protected ScriptableDelegate _scriptable;
- public void executeScript( String script ) {
+ public String executeScript( String script ) {
try {
script = script.trim();
if (script.startsWith( "<!--" )) script = withoutFirstLine( script );
Context.getCurrentContext().evaluateString( this, script, "httpunit", 0, null );
+ StringBuffer buffer = getDocumentWriteBuffer();
+ return buffer.toString();
} catch (Exception e) {
handleScriptException( e, "Script '" + script + "'" );
+ return "";
+ } finally {
+ Context.getCurrentContext().removeThreadLocal( "stream" );
}
}
+ protected StringBuffer getDocumentWriteBuffer() {
+ StringBuffer buffer = (StringBuffer) Context.getCurrentContext().getThreadLocal( "stream" );
+ if (buffer == null) {
+ buffer = new StringBuffer();
+ Context.getCurrentContext().putThreadLocal( "stream", buffer );
+ }
+ return buffer;
+ }
+
private String withoutFirstLine( String script ) {
for (int i=0; i < script.length(); i++) {
@@ -139,6 +153,7 @@
}
}
+
/**
* Evaluates the specified string as JavaScript. Will return null if the script has no return value.
*/
@@ -237,7 +252,6 @@
public ScriptingEngine newScriptingEngine( ScriptableDelegate child ) {
try {
-// return (JavaScriptEngine) Context.getCurrentContext().newObject( this, getScriptableClassName( child ) );
return (ScriptingEngine) toScriptable( child );
} catch (Exception e) {
e.printStackTrace();
@@ -432,6 +446,18 @@
public Scriptable jsGet_forms() throws SAXException {
if (_forms == null) initializeForms();
return _forms;
+ }
+
+
+ public void jsFunction_write( String string ) {
+ final StringBuffer documentWriteBuffer = getDocumentWriteBuffer();
+ documentWriteBuffer.append( string );
+ }
+
+
+ public void jsFunction_writeln( String string ) {
+ final StringBuffer documentWriteBuffer = getDocumentWriteBuffer();
+ documentWriteBuffer.append( string ).append( 0x0D );
}
|