예제 #1
0
 public bool SetException(Exception ex)
 {
     if (state == State.Finally)
     {
         throw ex;
     }
     if (state == State.Try && catchBlock != null)
     {
         afterYield = false;
         state      = State.Catch;
         iterator.Dispose();
         iterator = catchBlock(EcmaValueUtility.GetValueFromException(ex)).GetEnumerator();
         return(true);
     }
     exception = ex;
     return(SetFinally());
 }
예제 #2
0
        public static EcmaValue Race([This] EcmaValue thisValue, EcmaValue iterable)
        {
            Guard.ArgumentIsObject(thisValue);
            PromiseCapability capability = PromiseCapability.CreateFromConstructor(thisValue.ToObject());

            try {
                using (EcmaIteratorEnumerator iterator = iterable.ForOf()) {
                    EcmaValue resolve = thisValue[WellKnownProperty.Resolve];
                    while (MoveNextSafe(iterator))
                    {
                        EcmaValue thenable = resolve.Call(thisValue, iterator.Current);
                        thenable.Invoke(WellKnownProperty.Then, capability.ResolveCallback, capability.RejectCallback);
                    }
                }
            } catch (Exception ex) {
                capability.Reject(EcmaValueUtility.GetValueFromException(ex));
            }
            return(capability.Promise);
        }
예제 #3
0
        public static EcmaValue All([This] EcmaValue thisValue, EcmaValue iterable)
        {
            Guard.ArgumentIsObject(thisValue);
            PromiseCapability capability = PromiseCapability.CreateFromConstructor(thisValue.ToObject());
            PromiseAggregator aggregator = new AllFulfilledAggregator(capability);

            try {
                using (EcmaIteratorEnumerator iterator = iterable.ForOf()) {
                    EcmaValue resolve = thisValue[WellKnownProperty.Resolve];
                    while (MoveNextSafe(iterator))
                    {
                        EcmaValue thenable = resolve.Call(thisValue, iterator.Current);
                        thenable.Invoke(WellKnownProperty.Then, (PromiseResolver)aggregator.CreateHandler().ResolveHandler, capability.RejectCallback);
                    }
                }
                aggregator.ResolveIfConditionMet();
            } catch (Exception ex) {
                capability.Reject(EcmaValueUtility.GetValueFromException(ex));
            }
            return(capability.Promise);
        }
예제 #4
0
        protected override bool Matches(object actual)
        {
            EcmaValue value = EcmaValueUtility.GetValueFromException((Exception)actual);

            return(value.InstanceOf(fn));
        }
예제 #5
0
        public static void SendUnhandledException(Exception ex)
        {
            Guard.ArgumentNotNull(ex, "ex");
            RuntimeExecution current = EnsureInstance();

            current.UnhandledException?.Invoke(null, new RuntimeUnhandledExceptionEventArgs(ex, EcmaValueUtility.GetValueFromException(ex)));
        }