Most recent blog posts

How do we cope with Google Chrome

By Erik Mollink

Out of the blue, Google Chrome saw the light on September 2, and managed to receive a market share of 1% within the day. This is for a new browser a very remarkable achievement. Chrome was on that particular day the 3rd most used browser (on the Windows platform).
Current market share
Now, almost two months later, [...]

Iterating properties creates unwanted side-effects

By Hans Wichman

Also known as:
iterating properties causes getter setter to execute
I was working on our AS2 logger today. In particular I was creating a setup where you could simply drop in a couple components in your fla and ‘tada’, you would have a reflecting logger at your disposal.
I’ll go into the reflecting logger and component creation in [...]

Consuming webservices in Flash 8

By Hans Wichman

During a partial refactoring process of the Behrloo client system, one of the items on my list was the backend webservice result processing. Without going into a lot of detail how these services are wrapped, it suffices to say that somewhere in the application a couple of webservices are being initialized and utilized through the [...]

TriMM: conductor of the NXP-site

By Jan Willem Alfenaar

Since 1997 NXP, formerly Philips Semiconductors, has been a customer of TriMM’s. For NXP we supply our total service-package: developing, designing, hosting, maintenance and support.
See also our portfolio.

Persona’s

By Christian van den Berge

Everybody would like their website to be a success. Still it seems that a lot of websites don’t measure up to the expectations made. In a series of articles I will look at where mistakes are made and give suggestions how a persona can help to make a better and more successful website.
Today in part [...]

TriMM nominated as best employer!

By Marc Woesthuis

In the 2007 edition of the (regional) Best Employers Awards TriMM was nominated in the category ‘profit’. The nominations came forth from a satisfaction survey among the employees of the participating companies. TriMM was one of the five companies bestowed with the honour.
The jury, all originating from the business community, the labor sector, and [...]

Iterating properties creates unwanted side-effects

By Hans Wichman.

Also known as:

  • iterating properties causes getter setter to execute
  • I was working on our AS2 logger today. In particular I was creating a setup where you could simply drop in a couple components in your fla and ‘tada’, you would have a reflecting logger at your disposal.

    I’ll go into the reflecting logger and component creation in another post, because what happened was that during a test run I ran into the dreaded 256 levels recursion problem.

    Some research indicated that the problem lay with getters and setters.

    Imagine you have a class:

    class TestClass {
        public function get id1 () {
            trace ("hello world");
        }
    
        public function id2() {
            trace ("goodbye world");
        }
    }
    

    Now do:

    _global.ASSetPropFlags(TestClass.prototype, null, 0, 7);
    for (var i:String in TestClass.prototype) {
        trace ("Property:"+i+" is function ? "+(TestClass.prototype[i] instanceof Function));
    }
    

    Ok, truth be told, you will not do this every day. In fact building a reflection package is probably the only time this issue shows up. However I like to document stuff for posterity’s sake, so here we are.

    Executing the code above will show something like:
    hello world
    Property:id1 is function ? false
    Property:id2 is function ? true
    Property:__get__id1 is function ? true
    Property:__proto__ is function ? false
    Property:constructor is function ? true

    The _global.ASSetPropFlags is used to unprotect all the prototypes properties, in order to force them to show up. In a real situation, you should always make sure you keep track of the original settings of an object’s properties and revert the object back to those settings after you are done with it.

    Anyway what is really interesting is that testing the id1 property to see whether it is a function or not, causes the underlying method (the ‘get’ method) to execute.

    Luckily I never use getters and setters. But other people do. This is not to say that getters and setters are bad, just that I ran into a situation which I hadn’t anticipated :) .

    In most situation this will not cause a problem either, but you never know. The getter might go into a recursive loop if no parameters are passed. A class might update it’s properties unintentionally, who knows? I don’t. I do know that if those side effects do happen, you will lose hours of precious time bughunting.

    So how to circumvent these special properties of woe?
    If you look closely at the output again, you’ll see something like __get__id1 in there as well.
    These kind of methods will only be created by flash if you use getters and setters.

    So how can you detect if obj[i] refers to a getter/setter and should not be executed?

    Test for the existence of __set__i and __get__i.

    As the saying goes, you’ll find the solution in the last place you look.

    More information on ASSetPropFlags:
    http://objectpainters.com/blog/2007/06/21/assetpropflags-explained/

    Tags: , , , ,


    Comment: