- ASSERT(inherits(info()));
-
- m_constructor.set(vm, this, constructor);
-}
-
-void JSPromise::destroy(JSCell* cell)
-{
- static_cast<JSPromise*>(cell)->JSPromise::~JSPromise();
-}
-
-void JSPromise::visitChildren(JSCell* cell, SlotVisitor& visitor)
-{
- JSPromise* thisObject = jsCast<JSPromise*>(cell);
- ASSERT_GC_OBJECT_INHERITS(thisObject, info());
- COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
- ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
-
- Base::visitChildren(thisObject, visitor);
-
- visitor.append(&thisObject->m_result);
- visitor.append(&thisObject->m_constructor);
- visitor.append(thisObject->m_resolveReactions.begin(), thisObject->m_resolveReactions.end());
- visitor.append(thisObject->m_rejectReactions.begin(), thisObject->m_rejectReactions.end());
-}
-
-void JSPromise::reject(VM& vm, JSValue reason)
-{
- // 1. If the value of promise's internal slot [[PromiseStatus]] is not "unresolved", return.
- if (m_status != Status::Unresolved)
- return;
-
- DeferGC deferGC(vm.heap);
-
- // 2. Let 'reactions' be the value of promise's [[RejectReactions]] internal slot.
- Vector<WriteBarrier<JSPromiseReaction>> reactions;
- reactions.swap(m_rejectReactions);
-
- // 3. Set the value of promise's [[Result]] internal slot to reason.
- m_result.set(vm, this, reason);
-
- // 4. Set the value of promise's [[ResolveReactions]] internal slot to undefined.
- m_resolveReactions.clear();
-
- // 5. Set the value of promise's [[RejectReactions]] internal slot to undefined.
- // NOTE: Handled by the swap above.
-
- // 6. Set the value of promise's [[PromiseStatus]] internal slot to "has-rejection".
- m_status = Status::HasRejection;
-
- // 7. Return the result of calling TriggerPromiseReactions(reactions, reason).
- triggerPromiseReactions(vm, globalObject(), reactions, reason);
-}
-
-void JSPromise::resolve(VM& vm, JSValue resolution)
-{
- // 1. If the value of promise's internal slot [[PromiseStatus]] is not "unresolved", return.
- if (m_status != Status::Unresolved)
- return;
-
- DeferGC deferGC(vm.heap);
-
- // 2. Let 'reactions' be the value of promise's [[ResolveReactions]] internal slot.
- Vector<WriteBarrier<JSPromiseReaction>> reactions;
- reactions.swap(m_resolveReactions);
-
- // 3. Set the value of promise's [[Result]] internal slot to resolution.
- m_result.set(vm, this, resolution);
-
- // 4. Set the value of promise's [[ResolveReactions]] internal slot to undefined.
- // NOTE: Handled by the swap above.
-
- // 5. Set the value of promise's [[RejectReactions]] internal slot to undefined.
- m_rejectReactions.clear();
-
- // 6. Set the value of promise's [[PromiseStatus]] internal slot to "has-resolution".
- m_status = Status::HasResolution;
-
- // 7. Return the result of calling TriggerPromiseReactions(reactions, resolution).
- triggerPromiseReactions(vm, globalObject(), reactions, resolution);
-}
-
-void JSPromise::appendResolveReaction(VM& vm, JSPromiseReaction* reaction)
-{
- m_resolveReactions.append(WriteBarrier<JSPromiseReaction>(vm, this, reaction));