Exemplo n.º 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;
     }
 }
Exemplo n.º 2
0
        public static RuntimeFunction GetExecutingFunction()
        {
            RuntimeFunctionInvocation current = RuntimeFunctionInvocation.Current;

            if (current == null)
            {
                return(null);
            }
            return(current.FunctionObject);
        }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
 public IDisposable Resume()
 {
     if (disposed)
     {
         throw new ObjectDisposedException("");
     }
     if (this.Parent != null)
     {
         this.Parent.childCount--;
     }
     previous = current;
     current  = this;
     return(this);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
                                      }
        }
Exemplo n.º 9
0
 protected override EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     return(EcmaValue.Undefined);
 }
Exemplo n.º 10
0
 protected virtual EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     throw new EcmaTypeErrorException(InternalString.Error.IllegalInvocation);
 }
Exemplo n.º 11
0
 internal SuperAccessor(RuntimeFunctionInvocation invocation, RuntimeObject homeObject)
 {
     this.invocation = invocation;
     this.homeObject = homeObject;
 }
Exemplo n.º 12
0
 protected override EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     return(GetDelegate()(invocation, arguments, method.IsStatic ? null : invocation.ThisValue.GetUnderlyingObject()));
 }
Exemplo n.º 13
0
 protected override EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     return(GetDelegate()(invocation, arguments, target));
 }
Exemplo n.º 14
0
 protected override EcmaValue Invoke(RuntimeFunctionInvocation invocation, EcmaValue[] arguments)
 {
     return(new AsyncGenerator(invocation, new GeneratorDelegateEnumerator(generator)));
 }