There are a couple of ways to do this:
One way is to implement a ContextFactory class which sets the
instruction threashold:

ContextFactory.initGlobal( new ContextFactory() {
  protected Context makeContext() {
    Context cx = super.makeContext();
    cx.setInstructionObserverThreshold( 1000000 /*tune this number*/ );
    return cx;
  }
);

Note, you can only call initGlobal *once* in the application.

An alternative way would be to implement a Listener which sets this
threshold.  I think the code would look something like this:

ContextFactory.getGlobal().addListener( new Listener() {
  public void contextCreated( Context cx ) {
    cx.setInstructionObserverThreshold( 1000000 /*tune this number*/ );
  }
);

I don't know what is the preferred way to do this.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Monday, April 14, 2008 2:07 AM
To: [email protected]
Subject: how to avoid infinite loop

The script below, which is defined in a web-site, causes infinite loop..
Firefox indicates that there is "too much recursion" and stops execution
of the script ( using firebug extension we could see this
message)

Question: How to defend against the infinite loop when using Rhino?

<script>
var RealWinOpen = null;

function SymOnLoad()
{
        if(RealWinOpen != null)
        {
              RealWinOpen();
        }

}

RealWinOpen = SymOnLoad;

RealWinOpen();
</script>
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to