public bool MoveNext() { GeneratorState currentState = this.Iterator.State; switch (currentState) { case GeneratorState.Closed: case GeneratorState.AwaitingReturn: this.Current = EcmaValue.Undefined; return(false); } GeneratorResumeState resumeState = this.Context.ResumeState; try { this.Current = GetNextValue(resumeState, this.Context.ResumeValue); } catch (GeneratorClosedException ex) { this.Current = ex.ReturnValue; if (resumeState != GeneratorResumeState.Return) { return(false); } throw; } return(resumeState != GeneratorResumeState.Resume || this.Iterator.State != GeneratorState.Closed); }
public override EcmaValue Resume(GeneratorResumeState state, EcmaValue value) { PromiseCapability capability = PromiseCapability.Create(); ResumeRecord record = new ResumeRecord(state, value, capability); queue.Enqueue(record); if (this.State != GeneratorState.Running) { ResumeNext(); } return(capability.Promise); }
EcmaValue IGeneratorEnumerable.Resume(GeneratorResumeState state, EcmaValue value) { switch (state) { case GeneratorResumeState.Return: throw new GeneratorClosedException(value); case GeneratorResumeState.Throw: throw EcmaException.FromValue(value); } if (MoveNext()) { return(EcmaValueUtility.CreateIterResultObject(this.Current, false)); } return(EcmaValueUtility.CreateIterResultObject(EcmaValue.Undefined, true)); }
public override EcmaValue Resume(GeneratorResumeState state, EcmaValue value) { if (this.State == GeneratorState.Running) { throw new EcmaTypeErrorException(InternalString.Error.GeneratorRunning); } nextState = state; if (this.State != GeneratorState.SuspendedYield) { switch (state) { case GeneratorResumeState.Throw: Close(); throw EcmaException.FromValue(value); case GeneratorResumeState.Return: Close(); return(EcmaValueUtility.CreateIterResultObject(value, true)); } } else { resumeValue = value; } if (this.State != GeneratorState.Closed) { try { this.State = GeneratorState.Running; if (TryYieldNext(out EcmaValue result)) { return(EcmaValueUtility.CreateIterResultObject(result, false)); } } catch { if (nextState != GeneratorResumeState.Return) { Close(); throw; } } finally { if (this.State != GeneratorState.Closed) { this.State = GeneratorState.SuspendedYield; } } Close(); } return(EcmaValueUtility.CreateIterResultObject(nextState == GeneratorResumeState.Return ? resumeValue : default, true));
public override EcmaValue Resume(GeneratorResumeState state, EcmaValue value) { if (this.State != GeneratorState.Closed) { this.State = GeneratorState.Running; } try { EcmaValue result = default; bool done = true; switch (state) { case GeneratorResumeState.Resume: done = !iterator.MoveNext(value); result = iterator.Current; break; case GeneratorResumeState.Return: if (!TryGetResult(WellKnownProperty.Return, value, out done, out result)) { this.State = GeneratorState.Closed; return(Promise.Resolve(EcmaValueUtility.CreateIterResultObject(value, true))); } break; case GeneratorResumeState.Throw: if (!TryGetResult(WellKnownProperty.Throw, value, out done, out result)) { this.State = GeneratorState.Closed; return(Promise.Reject(value)); } break; } if (done) { this.State = GeneratorState.Closed; } return(Promise.Resolve(result, new ResultHandler(done).CreateIterResultObject, null)); } catch (Exception ex) { return(Promise.Reject(ex)); } }
public abstract EcmaValue Resume(GeneratorResumeState state, EcmaValue value);
protected virtual EcmaValue GetNextValue(GeneratorResumeState state, EcmaValue value) { return(UnwrapResult(this.Iterator.Resume(state, value))); }
public ResumeRecord(GeneratorResumeState state, EcmaValue value, PromiseCapability capability) { this.State = state; this.Value = value; this.Capability = capability; }
protected override EcmaValue GetNextValue(GeneratorResumeState state, EcmaValue value) { return(Promise.Resolve(this.Iterator.Resume(state, value), UnwrapResult, null)); }