Jurassic.Compiler.DynamicILGenerator.EmitCall C# (CSharp) Method

EmitCall() private method

Pops the method arguments off the stack, calls the given method, then pushes the result to the stack (if there was one).
private EmitCall ( byte opCode, System method ) : void
opCode byte The opcode to emit.
method System The method to call.
return void
        private void EmitCall(byte opCode, System.Reflection.MethodBase method)
        {
            // Get the argument and return type details.
            var parameters = method.GetParameters();
            Type returnType;
            if (method is System.Reflection.ConstructorInfo)
                returnType = method.DeclaringType;
            else if (method is System.Reflection.MethodInfo)
                returnType = ((System.Reflection.MethodInfo)method).ReturnType;
            else
                throw new InvalidOperationException("Unsupported subtype of MethodBase.");

            // Get a token for the method.
            int token = this.GetToken(method);

            // Call the method.
            Emit1ByteOpCodeInt32(opCode, parameters.Length + (method.IsStatic ? 0 : 1), returnType == typeof(void) ? 0 : 1, token);

#if DEBUG
            // Check the stack.
            var operandTypes = new List<VESType>(parameters.Length);
            if (method.IsStatic == false)
            {
                var declaringType = method.DeclaringType;
                if (declaringType.IsValueType == true)
                    operandTypes.Add(VESType.ManagedPointer);
                else
                    operandTypes.Add(VESType.Object);
            }
            foreach (var parameterInfo in parameters)
            {
                if (parameterInfo.ParameterType.IsByRef == true)
                    operandTypes.Add(VESType.ManagedPointer);
                else
                    operandTypes.Add(ToVESType(parameterInfo.ParameterType));
            }
            PopStackOperands(operandTypes.ToArray());
            if (returnType != typeof(void))
                PushStackOperand(ToVESType(returnType));
#endif
        }
DynamicILGenerator