Bug 1331092 - Part 2: Implement Async Generator except yield*.

Tag #1287
This commit is contained in:
Gaming4JC 2019-12-13 21:29:23 -05:00 • committed by Roy Tam
commit 10b93afff4
23 changed files with 1015 additions and 55 deletions

View file

@ -916,28 +916,30 @@ js::GetIteratorObject(JSContext* cx, HandleObject obj, uint32_t flags)
return iterator;
}
// ES 2017 draft 7.4.7.
JSObject*
js::CreateItrResultObject(JSContext* cx, HandleValue value, bool done)
js::CreateIterResultObject(JSContext* cx, HandleValue value, bool done)
{
// FIXME: We can cache the iterator result object shape somewhere.
AssertHeapIsIdle(cx);
// Step 1 (implicit).
RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, cx->global()));
if (!proto)
// Step 2.
RootedObject resultObj(cx, NewBuiltinClassInstance<PlainObject>(cx));
if (!resultObj)
return nullptr;
RootedPlainObject obj(cx, NewObjectWithGivenProto<PlainObject>(cx, proto));
if (!obj)
// Step 3.
if (!DefineProperty(cx, resultObj, cx->names().value, value))
return nullptr;
if (!DefineProperty(cx, obj, cx->names().value, value))
// Step 4.
if (!DefineProperty(cx, resultObj, cx->names().done,
done ? TrueHandleValue : FalseHandleValue))
{
return nullptr;
}
RootedValue doneBool(cx, BooleanValue(done));
if (!DefineProperty(cx, obj, cx->names().done, doneBool))
return nullptr;
return obj;
// Step 5.
return resultObj;
}
bool