예제 #1
0
 protected IteratorProtocol(
     Engine engine,
     IteratorInstance iterator,
     int argCount)
 {
     _engine   = engine;
     _iterator = iterator;
     _argCount = argCount;
 }
예제 #2
0
        internal IteratorInstance Construct(IEnumerable <JsValue> enumerable)
        {
            var instance = new IteratorInstance(Engine, enumerable)
            {
                _prototype = this
            };

            return(instance);
        }
        internal ObjectInstance Construct(IEnumerable <JsValue> enumerable)
        {
            var instance = new IteratorInstance(Engine, enumerable)
            {
                _prototype = GenericIteratorPrototypeObject
            };

            return(instance);
        }
예제 #4
0
        internal ObjectInstance Construct(IEnumerable <JsValue> enumerable)
        {
            var instance = new IteratorInstance(Engine, enumerable)
            {
                Prototype  = PrototypeObject,
                Extensible = true
            };

            return(instance);
        }
예제 #5
0
        internal static void AddEntriesFromIterable(ObjectInstance target, IteratorInstance iterable, object adder)
        {
            var callable = adder as ICallable;

            if (callable is null)
            {
                ExceptionHelper.ThrowTypeError(target.Engine.Realm, "adder must be callable");
            }

            var args = target.Engine._jsValueArrayPool.RentArray(2);

            var skipClose = true;

            try
            {
                do
                {
                    if (!iterable.TryIteratorStep(out var nextItem))
                    {
                        return;
                    }

                    var temp = nextItem.Get(CommonProperties.Value);

                    skipClose = false;
                    var oi = temp as ObjectInstance;
                    if (oi is null)
                    {
                        ExceptionHelper.ThrowTypeError(target.Engine.Realm, "iterator's value must be an object");
                    }

                    var k = oi.Get(JsString.NumberZeroString);
                    var v = oi.Get(JsString.NumberOneString);

                    args[0] = k;
                    args[1] = v;

                    callable.Call(target, args);
                } while (true);
            }
            catch
            {
                if (!skipClose)
                {
                    iterable.Close(CompletionType.Throw);
                }
                throw;
            }
            finally
            {
                target.Engine._jsValueArrayPool.ReturnArray(args);
            }
        }