Пример #1
0
 public void Dispose()
 {
     if (!disposed)
     {
         RuntimeFunctionInvocation parent = this.Parent;
         bool isSuspendedDispose          = parent != null && previous != parent;
         if (current == this)
         {
             current = previous;
         }
         if (this.SuspendOnDispose)
         {
             if (parent != null)
             {
                 parent.childCount++;
             }
         }
         else if (childCount == 0)
         {
             disposed = true;
             if (isSuspendedDispose && parent.childCount == 0)
             {
                 parent.Dispose();
             }
         }
         previous = null;
     }
 }
Пример #2
0
        public static RuntimeFunction GetExecutingFunction()
        {
            RuntimeFunctionInvocation current = RuntimeFunctionInvocation.Current;

            if (current == null)
            {
                return(null);
            }
            return(current.FunctionObject);
        }
Пример #3
0
 public override EcmaValue Call(EcmaValue thisValue, params EcmaValue[] arguments)
 {
     Guard.ArgumentNotNull(arguments, "arguments");
     if (this.HomeObject == this)
     {
         throw new EcmaTypeErrorException(InternalString.Error.MustCallAsConstructor);
     }
     using (RuntimeFunctionInvocation invocation = new RuntimeFunctionInvocation(this, thisValue, arguments)) {
         return(Invoke(invocation, arguments));
     }
 }
Пример #4
0
        private EcmaValue GetCurrentArguments()
        {
            RuntimeFunctionInvocation invocation = RuntimeFunctionInvocation.Current;

            for (; invocation != null; invocation = invocation.Parent)
            {
                if (invocation.FunctionObject == this)
                {
                    return(invocation.Arguments);
                }
            }
            return(EcmaValue.Null);
        }
Пример #5
0
 public IDisposable Resume()
 {
     if (disposed)
     {
         throw new ObjectDisposedException("");
     }
     if (this.Parent != null)
     {
         this.Parent.childCount--;
     }
     previous = current;
     current  = this;
     return(this);
 }
Пример #6
0
 internal RuntimeFunctionInvocation(RuntimeFunction method, EcmaValue thisValue, EcmaValue[] arguments, RuntimeObject newTarget = null)
 {
     this.FunctionObject = method;
     this.Parent         = current;
     this.ThisValue      = thisValue;
     this.NewTarget      = newTarget;
     this.arguments      = arguments;
     this.previous       = current;
     if (method.IsHomedMethod || method.IsDerivedConstructor)
     {
         this.Super = new SuperAccessor(this, method.HomeObject);
     }
     current = this;
 }
Пример #7
0
        private EcmaValue GetCurrentCallee()
        {
            RuntimeFunctionInvocation invocation = RuntimeFunctionInvocation.Current;
            bool returnCaller = false;

            for (; invocation != null; invocation = invocation.Parent)
            {
                if (returnCaller)
                {
                    return(invocation.FunctionObject);
                }
                if (invocation.FunctionObject == this)
                {
                    returnCaller = true;
                }
            }
            return(EcmaValue.Null);
        }
Пример #8
0
        public override EcmaValue Construct(EcmaValue[] arguments, RuntimeObject newTarget)
        {
            Guard.ArgumentNotNull(arguments, "arguments");
            Guard.ArgumentNotNull(newTarget, "newTarget");
            if (!this.IsConstructor || !newTarget.IsConstructor || (this.HomeObject != null && this.HomeObject != this))
            {
                throw new EcmaTypeErrorException(InternalString.Error.NotConstructor);
            }

            RuntimeObject thisValue = IsDerivedFromInternalClass() ? default : ConstructThisValue(newTarget);

                                      using (RuntimeFunctionInvocation invocation = new RuntimeFunctionInvocation(this, thisValue, arguments, newTarget)) {
                                          EcmaValue returnValue = Invoke(invocation, arguments);
                                          if (returnValue.Type == EcmaValueType.Object)
                                          {
                                              return(returnValue);
                                          }
                                          if (invocation.Super != null && !invocation.Super.ConstructorInvoked)
                                          {
                                              throw new EcmaReferenceErrorException(InternalString.Error.SuperConstructorNotCalled);
                                          }
                                          return(invocation.ThisValue);
                                      }
        }
Пример #9
0
 protected override EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     return(EcmaValue.Undefined);
 }
Пример #10
0
 protected virtual EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     throw new EcmaTypeErrorException(InternalString.Error.IllegalInvocation);
 }
Пример #11
0
 internal SuperAccessor(RuntimeFunctionInvocation invocation, RuntimeObject homeObject)
 {
     this.invocation = invocation;
     this.homeObject = homeObject;
 }
Пример #12
0
 protected override EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     return(GetDelegate()(invocation, arguments, method.IsStatic ? null : invocation.ThisValue.GetUnderlyingObject()));
 }
Пример #13
0
 protected override EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     return(GetDelegate()(invocation, arguments, target));
 }
Пример #14
0
 protected override EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     return(new AsyncGenerator(invocation, new GeneratorDelegateEnumerator(generator)));
 }