1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.core.BasicClass; 18 19 /** 20 * @author Simon Wacker 21 */ 22 class org.as2lib.util.MethodUtil extends BasicClass { 23 24 /** 25 * Invokes the method with the given name {@code methodName} on the given 26 * {@code scope} using the givne {@code args}. 27 * 28 * @param methodName the name of the method to invoke on the given {@code scope} 29 * @param scope the scope to invoke the method on 30 * @param args the arguments for the method invocation 31 * @return the result of the method invocation 32 */ 33 public static function invoke(methodName:String, scope, args:Array) { 34 var m:Function = scope[methodName]; 35 if (m) { 36 if (scope.__proto__[methodName] == scope.__proto__.__proto__[methodName]) { 37 var s = scope.__proto__.__proto__; 38 while (s[methodName] == s.__proto__[methodName] 39 && s.__proto__[methodName] == s.__proto__.__proto__[methodName]) { 40 s = s.__proto__; 41 } 42 s.__as2lib__invoker = function() { 43 delete s.__as2lib__invoker; 44 return m.apply(super, args); 45 }; 46 return scope.__as2lib__invoker(); 47 } 48 return m.apply(scope, args); 49 } 50 } 51 52 /** 53 * Constructs a new {@code MethodUtil} instance. 54 */ 55 private function MethodUtil() { 56 } 57 58 }