/* Function to iterate and return the next element value. NOTE: this is not a method of Array. Rather, it is a callback function for Iterator */ static EjsObj *nextValue(Ejs *ejs, EjsIterator *ip, int argc, EjsObj **argv) { EjsFile *fp; fp = (EjsFile*) ip->target; if (!ejsIs(ejs, fp, File)) { ejsThrowReferenceError(ejs, "Wrong type"); return 0; } if (ip->index < fp->info.size) { #if !ME_CC_MMU || 1 if (mprSeekFile(fp->file, SEEK_CUR, 0) != ip->index) { if (mprSeekFile(fp->file, SEEK_SET, ip->index) != ip->index) { ejsThrowIOError(ejs, "Cannot seek to %d", ip->index); return 0; } } ip->index++; return (EjsObj*) ejsCreateNumber(ejs, mprGetFileChar(fp->file)); #else return (EjsObj*) ejsCreateNumber(ejs, fp->mapped[ip->index++]); #endif } #if ME_CC_MMU && FUTURE unmapFile(fp); fp->mapped = 0; #endif ejsThrowStopIteration(ejs); return 0; }
/* Function to iterate and return the next element value. NOTE: this is not a method of Array. Rather, it is a callback function for Iterator */ static EjsObj *nextArrayValue(Ejs *ejs, EjsIterator *ip, int argc, EjsObj **argv) { EjsArray *ap; EjsObj *vp, **data; ap = (EjsArray*) ip->target; if (!ejsIs(ejs, ap, Array)) { ejsThrowReferenceError(ejs, "Wrong type"); return 0; } data = ap->data; if (ap->length < ip->length) { ip->length = ap->length; } for (; ip->index < ip->length; ip->index++) { vp = data[ip->index]; assert(vp); if (ejsIs(ejs, vp, Void)) { continue; } ip->index++; return vp; } ejsThrowStopIteration(ejs); return 0; }
/* Call the supplied next() function to return the next enumerable item */ static EjsObj *nextIterator(Ejs *ejs, EjsIterator *ip, int argc, EjsObj **argv) { if (ip->nativeNext) { return (ip->nativeNext)(ejs, ip, argc, argv); } else { ejsThrowStopIteration(ejs); return 0; } }
/* Function to iterate and return the next element index. NOTE: this is not a method of Array. Rather, it is a callback function for Iterator */ static EjsNumber *nextKey(Ejs *ejs, EjsIterator *ip, int argc, EjsObj **argv) { EjsFile *fp; fp = (EjsFile*) ip->target; if (!ejsIs(ejs, fp, File)) { ejsThrowReferenceError(ejs, "Wrong type"); return 0; } if (ip->index < fp->info.size) { return ejsCreateNumber(ejs, ip->index++); } ejsThrowStopIteration(ejs); return 0; }
/* * Call the supplied next() function to return the next enumerable item */ static EjsVar *nextIterator(Ejs *ejs, EjsIterator *ip, int argc, EjsVar **argv) { if (ip->nativeNext) { return (ip->nativeNext)(ejs, (EjsVar*) ip, argc, argv); } else { ejsThrowStopIteration(ejs); return 0; } #if UNUSED && TODO if (ip->nativeNext) { return (ip->nativeNext)(ejs, (EjsVar*) ip, argc, argv); } return ejsRunFunction(ejs, ip->next, ip->target, argc, argv); #endif }
/* Function to iterate and return the next element name. NOTE: this is not a method of Xml. Rather, it is a callback function for Iterator */ static EjsObj *nextXmlKey(Ejs *ejs, EjsIterator *ip, int argc, EjsObj **argv) { EjsXML *xml; xml = (EjsXML*) ip->target; if (!ejsIsXML(ejs, xml)) { ejsThrowReferenceError(ejs, "Wrong type"); return 0; } if (ip->index < mprGetListLength(xml->elements)) { return (EjsObj*) ejsCreateNumber(ejs, ip->index++); } ejsThrowStopIteration(ejs); return 0; }
/* Function to iterate and return the next element value. NOTE: this is not a method of Xml. Rather, it is a callback function for Iterator */ static EjsObj *nextXmlValue(Ejs *ejs, EjsIterator *ip, int argc, EjsObj **argv) { EjsXML *xml, *vp; xml = (EjsXML*) ip->target; if (!ejsIsXML(ejs, xml)) { ejsThrowReferenceError(ejs, "Wrong type"); return 0; } for (; ip->index < mprGetListLength(xml->elements); ip->index++) { vp = (EjsXML*) mprGetItem(xml->elements, ip->index); if (vp == 0) { continue; } ip->index++; return (EjsObj*) vp; } ejsThrowStopIteration(ejs); return 0; }
/* * Function to iterate and return the next element name. * NOTE: this is not a method of Array. Rather, it is a callback function for Iterator */ static EjsVar *nextArrayKey(Ejs *ejs, EjsIterator *ip, int argc, EjsVar **argv) { EjsArray *ap; EjsVar *vp, **data; ap = (EjsArray*) ip->target; if (!ejsIsArray(ap)) { ejsThrowReferenceError(ejs, "Wrong type"); return 0; } data = ap->data; for (; ip->index < ap->length; ip->index++) { vp = data[ip->index]; if (vp == 0) { continue; } return (EjsVar*) ejsCreateNumber(ejs, ip->index++); } ejsThrowStopIteration(ejs); return 0; }