internal bool TryGetIterator(Realm realm, out IteratorInstance iterator, GeneratorKind hint = GeneratorKind.Sync, ICallable method = null) { var obj = TypeConverter.ToObject(realm, this); if (method is null) { if (hint == GeneratorKind.Async) { method = obj.GetMethod(GlobalSymbolRegistry.AsyncIterator); if (method is null) { var syncMethod = obj.GetMethod(GlobalSymbolRegistry.Iterator); var syncIteratorRecord = obj.GetIterator(realm, GeneratorKind.Sync, syncMethod); // TODO async CreateAsyncFromSyncIterator(syncIteratorRecord); ExceptionHelper.ThrowNotImplementedException("async"); } } else { method = obj.GetMethod(GlobalSymbolRegistry.Iterator); } } if (method is null) { iterator = null; return(false); } var iteratorResult = method.Call(obj, Arguments.Empty) as ObjectInstance; if (iteratorResult is null) { ExceptionHelper.ThrowTypeError(realm, "Result of the Symbol.iterator method is not an object"); } if (iteratorResult is IteratorInstance i) { iterator = i; } else { iterator = new IteratorInstance.ObjectIterator(iteratorResult); } return(true); }
internal bool TryGetIterator(Engine engine, out IIterator iterator) { var objectInstance = TypeConverter.ToObject(engine, this); if (!objectInstance.TryGetValue(GlobalSymbolRegistry.Iterator, out var value) || !(value is ICallable callable)) { iterator = null; return(false); } var obj = callable.Call(this, Arguments.Empty) as ObjectInstance ?? ExceptionHelper.ThrowTypeError <ObjectInstance>(engine, "Result of the Symbol.iterator method is not an object"); if (obj is IIterator i) { iterator = i; } else { iterator = new IteratorInstance.ObjectIterator(obj); } return(true); }