Bug 1016196 - Patch 2/2: Add logs for Promise in BluetoothReplyRunnable, r=echou

This commit is contained in:
Ben Tian 2014-06-16 15:50:45 +08:00
parent 998ca4e528
commit da7d01840d
3 changed files with 25 additions and 7 deletions

View File

@ -686,12 +686,14 @@ BluetoothAdapter::EnableDisable(bool aEnable)
return promise.forget();
}
nsString methodName;
if (aEnable) {
// Enable local adapter
if (mState != BluetoothAdapterState::Disabled) {
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
return promise.forget();
}
methodName.AssignLiteral("Enable");
mState = BluetoothAdapterState::Enabling;
} else {
// Disable local adapter
@ -699,12 +701,15 @@ BluetoothAdapter::EnableDisable(bool aEnable)
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
return promise.forget();
}
methodName.AssignLiteral("Disable");
mState = BluetoothAdapterState::Disabling;
}
// TODO: Fire attr changed event for this state change
nsRefPtr<BluetoothReplyRunnable> result =
new BluetoothVoidReplyRunnable(nullptr /* DOMRequest */, promise);
new BluetoothVoidReplyRunnable(nullptr, /* DOMRequest */
promise,
methodName);
if(NS_FAILED(bs->EnableDisable(aEnable, result))) {
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);

View File

@ -16,10 +16,16 @@ using namespace mozilla::dom;
USING_BLUETOOTH_NAMESPACE
BluetoothReplyRunnable::BluetoothReplyRunnable(nsIDOMDOMRequest* aReq,
Promise* aPromise)
Promise* aPromise,
const nsAString& aName)
: mDOMRequest(aReq)
, mPromise(aPromise)
{}
, mName(aName)
{
if (aPromise) {
BT_API2_LOGR("<%s>", NS_ConvertUTF16toUTF8(mName).get());
}
}
void
BluetoothReplyRunnable::SetReply(BluetoothReply* aReply)
@ -53,6 +59,7 @@ BluetoothReplyRunnable::FireReplySuccess(JS::Handle<JS::Value> aVal)
// Promise
if (mPromise) {
BT_API2_LOGR("<%s>", NS_ConvertUTF16toUTF8(mName).get());
mPromise->MaybeResolve(aVal);
}
@ -73,6 +80,8 @@ BluetoothReplyRunnable::FireErrorString()
// Promise
if (mPromise) {
BT_API2_LOGR("<%s>", NS_ConvertUTF16toUTF8(mName).get());
/**
* Always reject with NS_ERROR_DOM_OPERATION_ERR.
*
@ -120,8 +129,9 @@ BluetoothReplyRunnable::Run()
}
BluetoothVoidReplyRunnable::BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq,
Promise* aPromise)
: BluetoothReplyRunnable(aReq, aPromise)
Promise* aPromise,
const nsAString& aName)
: BluetoothReplyRunnable(aReq, aPromise, aName)
{}
BluetoothVoidReplyRunnable::~BluetoothVoidReplyRunnable()

View File

@ -30,7 +30,8 @@ public:
NS_DECL_NSIRUNNABLE
BluetoothReplyRunnable(nsIDOMDOMRequest* aReq,
Promise* aPromise = nullptr);
Promise* aPromise = nullptr,
const nsAString& aName = EmptyString());
void SetReply(BluetoothReply* aReply);
@ -67,13 +68,15 @@ private:
nsRefPtr<Promise> mPromise;
nsString mErrorString;
nsString mName; // for debugging
};
class BluetoothVoidReplyRunnable : public BluetoothReplyRunnable
{
public:
BluetoothVoidReplyRunnable(nsIDOMDOMRequest* aReq,
Promise* aPromise = nullptr);
Promise* aPromise = nullptr,
const nsAString& aName = EmptyString());
~BluetoothVoidReplyRunnable();
protected: