2014-07-01 21:19:48 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-11-20 00:51:03 -08:00
|
|
|
#include "mozilla/dom/PromiseDebugging.h"
|
|
|
|
|
2014-07-01 21:19:48 -07:00
|
|
|
#include "js/Value.h"
|
|
|
|
|
2014-10-20 10:02:21 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2014-07-01 21:19:48 -07:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
#include "mozilla/dom/PromiseDebuggingBinding.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
PromiseDebugging::GetState(GlobalObject&, Promise& aPromise,
|
|
|
|
PromiseDebuggingStateHolder& aState)
|
|
|
|
{
|
|
|
|
switch (aPromise.mState) {
|
|
|
|
case Promise::Pending:
|
|
|
|
aState.mState = PromiseDebuggingState::Pending;
|
|
|
|
break;
|
|
|
|
case Promise::Resolved:
|
|
|
|
aState.mState = PromiseDebuggingState::Fulfilled;
|
|
|
|
JS::ExposeValueToActiveJS(aPromise.mResult);
|
|
|
|
aState.mValue = aPromise.mResult;
|
|
|
|
break;
|
|
|
|
case Promise::Rejected:
|
|
|
|
aState.mState = PromiseDebuggingState::Rejected;
|
|
|
|
JS::ExposeValueToActiveJS(aPromise.mResult);
|
|
|
|
aState.mReason = aPromise.mResult;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-19 19:27:12 -07:00
|
|
|
/* static */ void
|
|
|
|
PromiseDebugging::GetAllocationStack(GlobalObject&, Promise& aPromise,
|
|
|
|
JS::MutableHandle<JSObject*> aStack)
|
|
|
|
{
|
|
|
|
aStack.set(aPromise.mAllocationStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
PromiseDebugging::GetRejectionStack(GlobalObject&, Promise& aPromise,
|
|
|
|
JS::MutableHandle<JSObject*> aStack)
|
|
|
|
{
|
|
|
|
aStack.set(aPromise.mRejectionStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
PromiseDebugging::GetFullfillmentStack(GlobalObject&, Promise& aPromise,
|
|
|
|
JS::MutableHandle<JSObject*> aStack)
|
|
|
|
{
|
|
|
|
aStack.set(aPromise.mFullfillmentStack);
|
|
|
|
}
|
|
|
|
|
2014-10-19 19:27:36 -07:00
|
|
|
/* static */ void
|
|
|
|
PromiseDebugging::GetDependentPromises(GlobalObject&, Promise& aPromise,
|
|
|
|
nsTArray<nsRefPtr<Promise>>& aPromises)
|
|
|
|
{
|
|
|
|
aPromise.GetDependentPromises(aPromises);
|
|
|
|
}
|
|
|
|
|
2014-10-20 10:02:21 -07:00
|
|
|
/* static */ double
|
|
|
|
PromiseDebugging::GetPromiseLifetime(GlobalObject&, Promise& aPromise)
|
|
|
|
{
|
|
|
|
return (TimeStamp::Now() - aPromise.mCreationTimestamp).ToMilliseconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ double
|
|
|
|
PromiseDebugging::GetTimeToSettle(GlobalObject&, Promise& aPromise,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (aPromise.mState == Promise::Pending) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (aPromise.mSettlementTimestamp -
|
|
|
|
aPromise.mCreationTimestamp).ToMilliseconds();
|
|
|
|
}
|
|
|
|
|
2014-07-01 21:19:48 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|