On 2007-12-07, at 13:27 EST, Donald Anderson wrote:
>
> On Dec 7, 2007, at 12:36 PM, P T Withington wrote:
>
>> Maybe we just need to think a bit more about how we are going to
>> convert the user application into something compilable.
>>
>> I guess we decided that the user application needs to be a class?
>> The question is, whether the globals in the old app should be
>> instance variables, or, should they be class variables? If
>> LzTestManager were a class variable, then it would be 'in scope'
>> without needing `with(this)`.
>>
> I just tried
> static var LzTestManager
> and it is not seen. I need to qualify it ---
> DefaultApplication.LzTestManager.failAssertion(errmsg);
That's weird. My reading of AS3 scope rules is that attributes of the
class object are in scope to each other.
But, do we really have to put the user app in a class? The AS3 book
seems to imply you can have code in a package that is not in a class
(and that it should behave like our normal expectations for top-level
code, except that it will be in a package.
>> But, I think the real problem here is just that LzTestManager needs
>> to be class-ified, rather than trying to simulate the old Object
>> way of doing things. In which case the reference to LzTestManager
>> would just need to be replaced with `this`, or, removed altogether
>> if you rely on AS3's implicit with this inside methods
>
> there is an implicit this inside methods, but this is a closure, so
> explicit qualification appears to be needed.
> In java for this situation you have access to anything declared
> final, but final cannot be used on vars in AS3.
>
> Are you suggesting .lzx code changes?
Yeah. We should consider that option when the code is written in such
an old-fashioned style.
>> (which reminds me: the compiler should _not_ insert it's own
>> `with(this)` when generating for AS3, and makes me wonder if we
>> should simulate the same in our script class methods in addition to
>> LZX methods).
>>
>> On 2007-12-07, at 12:25 EST, Donald Anderson wrote:
>>
>>> 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
>>>
>>
>
>
> --
>
> Don Anderson
> Java/C/C++, Berkeley DB, systems consultant
>
> Voice: 617-547-7881
> Email: dda at ddanderson.com
> WWW: http://www.ddanderson.com
>