示例#1
0
        /// <summary>
        /// Calls the function with the given name.  The function must exist on this object or an
        /// exception will be thrown.
        /// </summary>
        /// <param name="functionName"> The name of the function to call. </param>
        /// <param name="parameters"> The parameters to pass to the function. </param>
        /// <returns> The result of calling the function. </returns>
        internal object CallMemberFunctionOn(object thisObj, string functionName, params object[] parameters)
        {
            PropertyVariable function = GetProperty(functionName);

            if (function == null)
            {
                throw new JavaScriptException(this.Engine, "TypeError", "Object " + ToString() + " has no method '" + functionName + "'");
            }

            MethodBase method = function.ConstantValue as MethodBase;

            if (method != null)
            {
                // Invoke it:
                return(method.Invoke(thisObj, parameters));
            }

            MethodGroup set = function.ConstantValue as MethodGroup;

            if (set != null)
            {
                // Invoke it:
                set.Invoke(thisObj, parameters);
            }

            throw new JavaScriptException(this.Engine, "TypeError", "Property '" + functionName + "' of object " + ToString() + " is not a function");
        }