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()); }
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); }
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); }
protected override bool Matches(object actual) { EcmaValue value = EcmaValueUtility.GetValueFromException((Exception)actual); return(value.InstanceOf(fn)); }
public static void SendUnhandledException(Exception ex) { Guard.ArgumentNotNull(ex, "ex"); RuntimeExecution current = EnsureInstance(); current.UnhandledException?.Invoke(null, new RuntimeUnhandledExceptionEventArgs(ex, EcmaValueUtility.GetValueFromException(ex))); }