CC-Archived / promise-as3

Promises/A+ compliant implementation in ActionScript 3.0
167 stars 52 forks source link

onFulfilled may call more then one time #52

Closed valera911 closed 7 years ago

valera911 commented 8 years ago

Hello the "optionally" method located at file com/codecatalyst/util/optionally.as contains a exception handler on ArgumentError type. the problems is that called code can throw ArgumentError in different cases and those cases may be not related whith method's argument error. I mean cases that throw following exception : ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. the starling library uses that exception type to notify about various problems. you can see it in following search result. https://github.com/Gamua/Starling-Framework/search?utf8=✓&q=ArgumentError

I suggest to add errorId check like this:

public function optionally(targetFunction:Function, parameters:Array, requiredParameters:int = 0):* {  
 try {
        return targetFunction.apply(null, parameters);
    } catch (e:ArgumentError) {

        if (e.errorID != 1063) //errorid check
            throw e;

        var parameterCount:int = Math.max(targetFunction.length, requiredParameters);
        if (parameterCount < parameters.length) {
            // only retry if we actually get less parameters:
            return targetFunction.apply(null, parameters.slice(0, parameterCount));
        }
        throw e;
    }
}
}