Your 'testrunner' function takes no arguments:

> >>> Test.prototype = {
> >>>    testrunner: function() {
> >>>        print(this.value);
> >>>    },
> >>>    start: function() {
> >>>        print("Starting ....");
> >>>        this.gzthread.start();
> >>>    }
> >>> }

This 'testrunner' function is then "bound" to the 'onrun' property.

> >>> Test = function() {
> >>>    this.value = "A test value";
> >>>    this.gzthread = new gzThread();
> >>>    this.gzthread.onrun = this.testrunner.gzbind(this);
> >>> }

Later on, you try to call this 'onrun' function with an argument
(this), when the function actually has arity 0.

> >>>        try {
> >>>            this.onrun(this);
> >>>        } catch (ioe ) {

calling:
this.onrun()
instead makes it work.

HTH
Raphael

On Mar 11, 5:25 am, Terry Braun <[email protected]> wrote:
> My mistake the problem remains - I had an extra line of code. Anyone
> have any ideas?
> Thanks
> Terry
>
> Terry Braun wrote:
> > The answer is "don't call it onrun".
>
> > The java adapter has its own method called onrun() so it finds that.
> > If you change the name to onxrun and then add the line
>
> > >for (n in this) print(n);
>
> > before the call to
>
> > >this.onrun(this)
>
> > you will see there are BOTH "onrun" and "onxrun" properties. And it
> > works in both cases.
> > Name collision.
>
> > Terry Braun wrote:
> >> Should I file this as a bug?
> >> Terry Braun wrote:
> >>> Ok, here is the whole thing
>
> >>> ---- cut ------------
>
> >>> importPackage(java.io);
> >>> importPackage(java.util);
> >>> importPackage(java.net);
> >>> importPackage(java.util.concurrent);
> >>> importPackage(java.lang);
>
> >>> Function.prototype.gzbind = function(object){
> >>>  var fn = this;
> >>>  return function(){
> >>>    return fn.apply(object, arguments);
> >>>  };
> >>> };
>
> >>> gzThread = function() {
> >>>        this.isrunning = false;
> >>>        // here the program works uncomment the next two lines
> >>>        // this.thread = new java.lang.Thread(new
> >>> java.lang.Runnable(this));
> >>>        // this.thread.setDaemon( false );
> >>> }
>
> >>> gzThread.prototype = {
> >>>    start: function() {
> >>>        // creating a thread here does not work
> >>>        this.thread = new java.lang.Thread(new
> >>> java.lang.Runnable(this));
> >>>        this.thread.setDaemon( false );
> >>>        this.isrunning = true;
> >>>        this.thread.start();
> >>>        return this;
> >>>    },
> >>>    stop: function() {
> >>>        if (this.isRunning == true ) {
> >>>            this.isRunning = false;
> >>>            this.thread.interrupt();
> >>>            this.thread.join(1000);
> >>>            if (this.onstop ) {
> >>>                this.onstop();
> >>>            }
> >>>        }
> >>>    },
> >>>    current: function() {
> >>>        return java.lang.Thread.currentThread();
> >>>    },
> >>>    run: function() {
> >>>        if ( this.onrun == null || this.isRunning == true) {
> >>>            return this;
> >>>        }
> >>>        this.isRunning = true
> >>>        try {
> >>>            this.onrun(this);
> >>>        } catch (ioe ) {
> >>>            var w, m;
> >>>            if ( ioe.rhinoException
> >>>                    && ioe.rhinoException instanceof
> >>> org.mozilla.javascript.WrappedException
> >>>                    && (w = ioe.rhinoException.getWrappedException())
> >>>                    && (s = w.getMessage() )
> >>>                    && s == "sleep interrupted") {
> >>>            } else {
> >>>                if ( ioe.rhinoException ) {
> >>>                    ioe.rhinoException.printStackTrace();
> >>>                } else if ( ioe.javaException ) {
> >>>                    ioe.printStackTrace();
> >>>                }
> >>>            }
> >>>        }
> >>>        return this;
> >>>    }
> >>> }
>
> >>> Test = function() {
> >>>    this.value = "A test value";
> >>>    this.gzthread = new gzThread();
> >>>    this.gzthread.onrun = this.testrunner.gzbind(this);
> >>> }
> >>> Test.prototype = {
> >>>    testrunner: function() {
> >>>        print(this.value);
> >>>    },
> >>>    start: function() {
> >>>        print("Starting ....");
> >>>        this.gzthread.start();
> >>>    }
> >>> }
> >>> var t = new Test();
> >>> t.start();
>
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to