示例#1
0
        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));
        }
示例#2
0
        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));