Exemplo n.º 1
0
        public iObject Call(iObject instance, params iObject[] arguments)
        {
            if (arguments.Length != ArgumentKinds.Count)
            {
                throw new ArgumentException(
                          $"{MethodName}: Number of arguments ({arguments.Length}) doesn't match expected number ({ArgumentKinds.Count})."
                          );
            }

            var bundle = new ArgumentBundle(ArgumentKinds.Zip(arguments, (kind, arg) => (kind, arg)));

            CallFrame.Push(this, instance, bundle);

            try
            {
                try
                {
                    return(CallCache.Call());
                }
                catch (RecompilationRequiredException)
                {
                    // caught while a method was being undefined.
                    // give a second chance to recover (which will possibly call method_missing).
                    return(CallCache.Call());
                }
            }
            catch (Exception e)
            {
                if (!e.Data.Contains(RB_STACK_KEY))
                {
                    e.Data[RB_STACK_KEY] = CallFrame.Current;
                }

                throw;
            }
            catch (System.Exception e)
            {
                if (!e.Data.Contains(RB_STACK_KEY))
                {
                    e.Data[RB_STACK_KEY] = CallFrame.Current.CallSite.MethodName.Name;
                }

                throw;
            }
            finally
            {
                CallFrame.Pop();
            }
        }