Bug 966471. Add some facilities for examining the state of a promise via a PromiseDebugging utility namespace. r=nsm,peterv

This commit is contained in:
Boris Zbarsky 2014-07-02 00:19:48 -04:00
parent 20075d3df1
commit 5118eea016
7 changed files with 98 additions and 1 deletions

View File

@ -997,6 +997,10 @@ DOMInterfaces = {
'implicitJSContext': [ 'then', 'catch' ],
},
'PromiseDebugging': {
'concrete': False,
},
'PropertyNodeList': {
'headerFile': 'HTMLPropertiesCollection.h',
'resultNotAddRefed': [ 'item' ]

View File

@ -30,6 +30,7 @@ class DOMError;
class PromiseCallback;
class PromiseInit;
class PromiseNativeHandler;
class PromiseDebugging;
class Promise;
class PromiseReportRejectFeature : public workers::WorkerFeature
@ -154,6 +155,8 @@ public:
void AppendNativeHandler(PromiseNativeHandler* aRunnable);
private:
friend class PromiseDebugging;
enum PromiseState {
Pending,
Resolved,

View File

@ -0,0 +1,40 @@
/* -*- 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/. */
#include "mozilla/dom/PromiseDebugging.h"
#include "js/Value.h"
#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;
}
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,27 @@
/* -*- 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/. */
#ifndef mozilla_dom_PromiseDebugging_h
#define mozilla_dom_PromiseDebugging_h
namespace mozilla {
namespace dom {
class Promise;
struct PromiseDebuggingStateHolder;
class GlobalObject;
class PromiseDebugging
{
public:
static void GetState(GlobalObject&, Promise& aPromise,
PromiseDebuggingStateHolder& aState);
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PromiseDebugging_h

View File

@ -8,13 +8,15 @@ TEST_DIRS += ['tests']
EXPORTS.mozilla.dom += [
'Promise.h',
'PromiseDebugging.h',
'PromiseNativeHandler.h',
'PromiseWorkerProxy.h',
]
SOURCES += [
UNIFIED_SOURCES += [
'Promise.cpp',
'PromiseCallback.cpp',
'PromiseDebugging.cpp'
]
FAIL_ON_WARNINGS = True

View File

@ -0,0 +1,20 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
/* This is a utility namespace for promise-debugging functionality */
dictionary PromiseDebuggingStateHolder {
PromiseDebuggingState state = "pending";
any value;
any reason;
};
enum PromiseDebuggingState { "pending", "fulfilled", "rejected" };
[ChromeOnly]
interface PromiseDebugging {
static PromiseDebuggingStateHolder getState(Promise p);
};

View File

@ -297,6 +297,7 @@ WEBIDL_FILES = [
'PositionError.webidl',
'ProcessingInstruction.webidl',
'Promise.webidl',
'PromiseDebugging.webidl',
'PushManager.webidl',
'Range.webidl',
'Rect.webidl',