Subj : Re: possible Rhino bug with long lined scripts? To : Igor Bukanov From : Jon Collis Date : Fri May 09 2003 08:06 am Igor Bukanov wrote: > Jon Collis wrote: > >> Sorry about the confusion. >> >> I am reading the script in from the web. It is in an HTML page which I >> store in a string. When I come across a script, I use >> String.substring() to cut it out of the HTML text and then pass it on >> to Rhino. Here is the line of code in which I add the script: >> >> Object o = contex.evaluateString(scope, js, "", 1, null); >> > > I tried the attched program which reads the suplied file into string and > call cx.evaluateString(scope, js, "", 1, null); and got no errors after > running > java Test longlines.js > > BTW, which encoding do you use to convert HTML to String? > > Regards, Igor > > > ------------------------------------------------------------------------ > > import java.io.*; > import org.mozilla.javascript.*; > > > public class Test { > > > static String readAll(Reader r) throws IOException { > char[] buffer = new char[4096]; > int offset = 0; > for (;;) { > int n = r.read(buffer, offset, buffer.length - offset); > if (n < 0) { break; } > offset += n; > if (offset == buffer.length) { > char[] tmp = new char[buffer.length * 2]; > System.arraycopy(buffer, 0, tmp, 0, offset); > buffer = tmp; > } > } > return new String(buffer, 0, offset); > } > > public static void main(String[] args) > throws Exception > { > Context cx = Context.enter(); > try { > Scriptable scope = cx.initStandardObjects(null); > byte[] array = new byte[4096]; > Reader r = new InputStreamReader(new FileInputStream(args[0])); > String js; > try { > js = readAll(r); > } finally { > r.close(); > } > cx.evaluateString(scope, js, "", 1, null); > } finally { > Context.exit(); > } > } > } Thanks for the code sample for testing. Well, I compared this to what I was doing and found that the only difference was that I was setting the language version like so: // Set version to JavaScript1.2 so that we get object-literal style // printing instead of "[object Object]" cx.setLanguageVersion(Context.VERSION_1_2); I think that I must have got this from an example that came with Rhino, but it was causing this problem as well as some other weird anomalies. I went ahead and commented it out.. Thank you for all the help, Jon Collis .