3

I read reports of others successfully using env.rhino.js on Android. I also got rhino working fine in an Android app and executing simple scripts, passing arguments both ways between Java and JavaScript. However, when I try to use env.rhino.js, no matter which version of envJs I find and use, and no matter which rhino (tried rhino1_7R2, rhino1_7R5 and rhino1_7R5pre), I get a StackOverflowError. The code in an activity based class is:

public void envjsTest() {
    String envJs = convertAssetToString("env.rhino.js");
    Context cx = ContextFactory.getGlobal().enterContext();
    cx.setOptimizationLevel(-1);
    cx.setLanguageVersion(Context.VERSION_1_8);
    try {
        Scriptable scope = cx.initStandardObjects();
        cx.evaluateString(scope, envJs, "env.rhino.js", 1, null);
    } finally {
        Context.exit();
    }
}

Tried also different VERSION settings, nothing helps. The stack trace I get is:

01-18 14:27:18.389: ERROR/AndroidRuntime(2447): FATAL EXCEPTION: main
    java.lang.StackOverflowError
    at org.mozilla.javascript.Decompiler.appendString(Decompiler.java:208)
    at org.mozilla.javascript.Decompiler.addName(Decompiler.java:121)
    at org.mozilla.javascript.IRFactory.transformName(IRFactory.java:811)
    at org.mozilla.javascript.IRFactory.transform(IRFactory.java:120)
    at org.mozilla.javascript.IRFactory.transformInfix(IRFactory.java:738)
    at org.mozilla.javascript.IRFactory.transform(IRFactory.java:161)
    at org.mozilla.javascript.IRFactory.transformInfix(IRFactory.java:738)
    at org.mozilla.javascript.IRFactory.transform(IRFactory.java:161)
    at org.mozilla.javascript.IRFactory.transformInfix(IRFactory.java:738)
    at org.mozilla.javascript.IRFactory.transform(IRFactory.java:161)
    at org.mozilla.javascript.IRFactory.transformInfix(IRFactory.java:740)
    at org.mozilla.javascript.IRFactory.transform(IRFactory.java:161)
    at org.mozilla.javascript.IRFactory.transformInfix(IRFactory.java:740)
    at org.mozilla.javascript.IRFactory.transform(IRFactory.java:161)
    at org.mozilla.javascript.IRFactory.transformInfix(IRFactory.java:740)
    at org.mozilla.javascript.IRFactory.transform(IRFactory.java:161)
    at org.mozilla.javascript.IRFactory.transfor ...

How could this be possibly fixed? Again, a similar function executes fine simple JavaScript code. And, please, don't tell me to use WebView instead to execute JavaScript code. I need a "headless browser" with JavaScript capability, that could be invoked from Android service, to do some web scraping in the background, while the user is occupied with something else on the screen.

Greg

gregko
  • 5,642
  • 9
  • 49
  • 76

0 Answers0