public override IDynamic CreateIterator(IEnvironment environment, IArgs args)
 {
     var scope = Scope.NewDeclarativeEnvironment();
     var generator = new Generator(new GeneratorSteps(Steps));
     var iterator = new HGeneratorIterator(environment, generator, VariableDeclarations, scope);
     return iterator;
 }
 public HGeneratorIterator(IEnvironment environment, Generator generator, ReadOnlyList<string> variableDeclarations, ILexicalEnvironment scope)
     : base(environment)
 {
     Generator = generator;
     VariableDeclarations = variableDeclarations;
     Scope = scope;
 }
Exemple #3
0
 public bool CombineGeneratorWithIterator(Generator generator, IDynamic other)
 {
     var iterable = other.ConvertToObject();
     var createIterator = iterable.Get("createIterator") as ICallable;
     if (createIterator == null)
         throw CreateTypeError("");
     var iterator = createIterator.Call(this, iterable, EmptyArgs).ConvertToObject();
     if (!iterator.HasProperty("current"))
         throw CreateTypeError("");
     var next = iterator.Get("next") as ICallable;
     if (next == null)
         throw CreateTypeError("");
     GeneratorStep step = null; step = (_e, _g) =>
     {
         if (!next.Call(this, Undefined, EmptyArgs).ConvertToBoolean().BaseValue)
             return false;
         generator.Current = iterator.Get("current");
         generator.Steps.Enqueue(step);
         return true;
     };
     return step(this, generator);
 }