Esempio n. 1
0
 private void HandleCompletedPromise(Promise previous)
 {
     try {
         HandleResult(previous.State, previous.Value);
     } catch (Exception ex) {
         RejectCallback.Call(EcmaValue.Undefined, EcmaValueUtility.GetValueFromException(ex));
     }
 }
Esempio n. 2
0
 private void ExecuteCallback(PromiseExecutor executor)
 {
     try {
         executor(ResolveSelf, RejectSelf);
     } catch (Exception ex) {
         RejectSelf(EcmaValueUtility.GetValueFromException(ex));
     }
 }
Esempio n. 3
0
        private void RejectFromFaultedTask(Task task)
        {
            AggregateException ex     = task.Exception.Flatten();
            Exception          reason = ex;

            if (ex.InnerExceptions.Count == 1)
            {
                reason = ex.InnerExceptions[0];
            }
            SetState(PromiseState.Rejected, EcmaValueUtility.GetValueFromException(reason), false);
        }
Esempio n. 4
0
 private void YieldNext()
 {
     if (this.State != GeneratorState.Closed)
     {
         try {
             this.State = GeneratorState.Running;
             if (TryYieldNext(out EcmaValue result))
             {
                 Promise.Resolve(result, ResolveFromYield, RejectFromYield);
                 return;
             }
         } catch (GeneratorClosedException ex) {
             Resolve(ex.ReturnValue, true);
         } catch (Exception ex) {
             Reject(EcmaValueUtility.GetValueFromException(ex));
         }
         if (this.State != GeneratorState.AwaitingReturn)
         {
             Close();
         }
     }
 }
Esempio n. 5
0
        private void SetState(PromiseState state, EcmaValue value, bool finalize)
        {
            PromiseCallback callback = state == PromiseState.Fulfilled ? fulfilledCallback : rejectedCallback;

            fulfilledCallback = null;
            rejectedCallback  = null;
            if (finalize || callback == null)
            {
                SetStateFinalize(state, value);
            }
            else
            {
                RuntimeExecution.Enqueue(() => {
                    try {
                        value = callback(value);
                        ResolveSelf(value, true);
                    } catch (Exception ex) {
                        SetStateFinalize(PromiseState.Rejected, EcmaValueUtility.GetValueFromException(ex));
                    }
                });
            }
        }
Esempio n. 6
0
 private void ResolveSelf(EcmaValue value, bool finalize)
 {
     if (value.Type == EcmaValueType.Object)
     {
         RuntimeObject obj = value.ToObject();
         if (obj == this)
         {
             SetStateFinalize(PromiseState.Rejected, new EcmaTypeErrorException(InternalString.Error.PromiseSelfResolution).ToValue());
             return;
         }
         try {
             RuntimeObject then = obj.GetMethod(WellKnownProperty.Then);
             if (then != null)
             {
                 then.Call(value, (PromiseResolver)ResolveSelf, (PromiseResolver)RejectSelf);
                 return;
             }
         } catch (Exception ex) {
             SetStateFinalize(PromiseState.Rejected, EcmaValueUtility.GetValueFromException(ex));
             return;
         }
     }
     SetState(PromiseState.Fulfilled, value, finalize);
 }
Esempio n. 7
0
 public static Promise Reject(Exception ex)
 {
     return(Reject(EcmaValueUtility.GetValueFromException(ex)));
 }