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); } }
protected void IteratorClose(CompletionType completionType) { _iterator.Close(completionType); }