Example #1
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, ArrayImpl arguments = null)
        {
            var methodIdx = target.FindMethod(methodName);
            var methInfo  = target.GetMethodInfo(methodIdx);

            var argsToPass = GetArgsToPass(arguments, methInfo);

            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, argsToPass, out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, argsToPass);
            }

            if (arguments != null)
            {
                for (int i = 0; i < argsToPass.Length; i++)
                {
                    if (i < arguments.Count())
                    {
                        arguments.Set(i, argsToPass[i]?.GetRawValue());
                    }
                }
            }

            return(retValue);
        }
Example #2
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, ArrayImpl arguments = null)
        {
            if (arguments == null)
            {
                arguments = new ArrayImpl();
            }

            var methodIdx = target.FindMethod(methodName);

            var methInfo = target.GetMethodInfo(methodIdx);

            if (methInfo.ArgCount < arguments.Count())
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            if (methInfo.ArgCount > arguments.Count())
            {
                throw RuntimeException.TooLittleArgumentsPassed();
            }

            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, arguments.ToArray(), out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, arguments.ToArray());
            }

            return(retValue);
        }
Example #3
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, IRuntimeContextInstance arguments = null)
        {
            ArrayImpl argArray;

            if (arguments != null)
            {
                argArray = arguments as ArrayImpl;
                if (argArray == null)
                {
                    throw RuntimeException.InvalidArgumentType();
                }
            }
            else
            {
                argArray = new ArrayImpl();
            }

            var methodIdx = target.FindMethod(methodName);

            var    methInfo = target.GetMethodInfo(methodIdx);
            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, argArray.ToArray(), out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, argArray.ToArray());
            }

            return(retValue);
        }
Example #4
0
        private static void ProduceResponse(HttpContext context, IRuntimeContextInstance runner)
        {
            int    methodIndex = runner.FindMethod("ОбработкаВызоваHTTPСервиса");
            IValue result;

            IValue[] args = new IValue[1];
            args[0] = new OneScript.HTTPService.HTTPServiceRequestImpl(context);
            runner.CallAsFunction(methodIndex, args, out result);

            // Обрабатываем результаты
            var response = (OneScript.HTTPService.HTTPServiceResponseImpl)result;

            context.Response.StatusCode = response.StatusCode;

            if (response.Headers != null)
            {
                foreach (var ch in response.Headers)
                {
                    context.Response.AddHeader(ch.Key.AsString(), ch.Value.AsString());
                }
            }

            if (response.Reason != "")
            {
                context.Response.Status = response.Reason;
            }

            if (response.BodyStream != null)
            {
                response.BodyStream.Seek(0, SeekOrigin.Begin);
                response.BodyStream.CopyTo(context.Response.OutputStream);
            }

            context.Response.Charset = response.ContentCharset;
        }
        public IValue CallCommonModuleFunction(string moduleName, string methodName, IValue[] parameters)
        {
            IRuntimeContextInstance commonModule = (IRuntimeContextInstance)_hostedScript.EngineInstance.Environment.GetGlobalProperty(moduleName);
            int    methodId = commonModule.FindMethod(methodName);
            IValue result   = ValueFactory.Create();

            commonModule.CallAsFunction(methodId, parameters, out result);
            return(result);
        }
        public static DelegateAction Create(IRuntimeContextInstance target, string methodName)
        {
            var method = target.FindMethod(methodName);

            Func <IValue[], IValue> action = (parameters) =>
            {
                IValue retVal;
                target.CallAsFunction(method, parameters, out retVal);
                return(retVal);
            };

            return(new DelegateAction(action));
        }
Example #7
0
        public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, System.Globalization.CultureInfo culture)
        {
            IRuntimeContextInstance inst = obj as IRuntimeContextInstance;

            if (inst == null)
            {
                throw new ArgumentException("Wrong argument type");
            }

            IValue[] engineParameters = parameters.Select(x => COMWrapperContext.CreateIValue(x)).ToArray();
            IValue   retVal           = null;

            inst.CallAsFunction(_dispId, engineParameters, out retVal);

            return(COMWrapperContext.MarshalIValue(retVal));
        }
Example #8
0
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            int methIdx;

            try
            {
                methIdx = _context.FindMethod(binder.Name);
            }
            catch (MethodAccessException)
            {
                result = null;
                return(false);
            }

            var    valueArgs = args.Select(x => CustomMarshaller.ConvertReturnValue(x, x.GetType())).ToArray();
            IValue methResult;

            _context.CallAsFunction(methIdx, valueArgs, out methResult);
            result = CustomMarshaller.ConvertToDynamicCLRObject(methResult);

            return(true);
        }
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            int methIdx;

            try
            {
                methIdx = _context.FindMethod(binder.Name);
            }
            catch (MethodAccessException)
            {
                result = null;
                return(false);
            }

            var methInfo   = _context.GetMethodInfo(methIdx);
            var valueArgs  = new IValue[methInfo.Params.Length];
            var passedArgs = args.Select(x => CustomMarshaller.ConvertReturnValue(x, x.GetType())).ToArray();

            for (int i = 0; i < valueArgs.Length; i++)
            {
                if (i < passedArgs.Length)
                {
                    valueArgs[i] = passedArgs[i];
                }
                else
                {
                    valueArgs[i] = ValueFactory.CreateInvalidValueMarker();
                }
            }

            IValue methResult;

            _context.CallAsFunction(methIdx, valueArgs, out methResult);
            result = methResult == null? null : CustomMarshaller.ConvertToDynamicCLRObject(methResult);

            return(true);
        }
Example #10
0
 public void CallAsFunction(int methodNumber, IValue[] arguments, out IValue retValue)
 {
     _inst.CallAsFunction(_methRedirects[methodNumber], arguments, out retValue);
 }
 /// <summary>
 /// Прямой вызов скриптового кода, минуя медленные интерфейсы Reflection
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public IValue InvokeDirect(IRuntimeContextInstance instance, IValue[] parameters)
 {
     instance.CallAsFunction(GetDispatchIndex(instance), parameters, out var retVal);
     return(retVal);
 }