[Laszlo-dev] SWF9: Need for with(this)

Donald Anderson dda at ddanderson.com
Fri Dec 7 09:25:25 PST 2007


I'm trying to get lztest-node compiled in SWF9, and I see a compiler  
error
coming from the included lztestmanager.lzx:

LzTestManager.assertTrue = function(condition, assertion) {
     if (!condition)  {
         var errmsg = "FAIL: assertTrue('" + condition + "') failed"
                     + (assertion ? ': ' + assertion : '');
==>        LzTestManager.failAssertion(errmsg);
     }
}

On the indicated line, LzTestManager shows up as undefined.
I've declared LzTestManager as an instance variable of the
application class that was created, so the LzTestManager.assertTrue
reference is not a problem.  The indicated one is a problem because the
associated block for a function expression does not automatically
inherit the surrounding scope.

What is needed is a with(this), like:

LzTestManager.assertTrue = function(condition, assertion) {
   with (this) {
     if (!condition)  {
         var errmsg = "FAIL: assertTrue('" + condition + "') failed"
                     + (assertion ? ': ' + assertion : '');
         LzTestManager.failAssertion(errmsg);
     }
   }
}

I could do this when we generate code for function expression blocks.
One concern is that this may be done in a static method or block
(where there is no 'this').  I think we can detect if we're in a static
context, so I'm not too worried about that.  The other approach is
adding with(this) to existing code -- is that out of the question?
I know there are many of these constructions in our source tree,
and I'm guessing it would affect user's code, you all know that  
better than I.

- Don

--

Don Anderson
Java/C/C++, Berkeley DB, systems consultant

Voice:  617-547-7881
Email:  dda at ddanderson.com
WWW:    http://www.ddanderson.com



More information about the Laszlo-dev mailing list