public static EcmaValue Reject([This] EcmaValue thisValue, EcmaValue reason) { Guard.ArgumentIsObject(thisValue); PromiseCapability capability = PromiseCapability.CreateFromConstructor(thisValue.ToObject()); capability.Reject(reason); return(capability.Promise); }
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); }