bool ForOfIterator::next(MutableHandleValue vp, bool* done) { MOZ_ASSERT(iterator); if (index != NOT_ARRAY) { ForOfPIC::Chain* stubChain = ForOfPIC::getOrCreate(cx_); if (!stubChain) return false; if (stubChain->isArrayNextStillSane()) return nextFromOptimizedArray(vp, done); // ArrayIterator.prototype.next changed, materialize a proper // ArrayIterator instance and fall through to slowpath case. if (!materializeArrayIterator()) return false; } RootedValue method(cx_); if (!GetProperty(cx_, iterator, iterator, cx_->names().next, &method)) return false; InvokeArgs args(cx_); if (!args.init(1)) return false; args.setCallee(method); args.setThis(ObjectValue(*iterator)); args[0].setUndefined(); if (!Invoke(cx_, args)) return false; RootedObject resultObj(cx_, ToObject(cx_, args.rval())); if (!resultObj) return false; RootedValue doneVal(cx_); if (!GetProperty(cx_, resultObj, resultObj, cx_->names().done, &doneVal)) return false; *done = ToBoolean(doneVal); if (*done) { vp.setUndefined(); return true; } return GetProperty(cx_, resultObj, resultObj, cx_->names().value, vp); }
bool ForOfIterator::next(MutableHandleValue vp, bool* done) { MOZ_ASSERT(iterator); if (index != NOT_ARRAY) { ForOfPIC::Chain* stubChain = ForOfPIC::getOrCreate(cx_); if (!stubChain) return false; if (stubChain->isArrayNextStillSane()) return nextFromOptimizedArray(vp, done); // ArrayIterator.prototype.next changed, materialize a proper // ArrayIterator instance and fall through to slowpath case. if (!materializeArrayIterator()) return false; } RootedValue v(cx_); if (!GetProperty(cx_, iterator, iterator, cx_->names().next, &v)) return false; if (!js::Call(cx_, v, iterator, &v)) return false; if (!v.isObject()) return ThrowCheckIsObject(cx_, CheckIsObjectKind::IteratorNext); RootedObject resultObj(cx_, &v.toObject()); if (!GetProperty(cx_, resultObj, resultObj, cx_->names().done, &v)) return false; *done = ToBoolean(v); if (*done) { vp.setUndefined(); return true; } return GetProperty(cx_, resultObj, resultObj, cx_->names().value, vp); }