Files
palemoon27/dom/base/DOMRequest.h
T
roytam1 09c7525bc8 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1132213 - Remove newChannel2 and asyncFetch2 calls in the "jsdownloads" folder. r=paolo (15afbc22f6)
- Bug 1223437 - Use channel.asyncOpen2 in toolkit/components/jsdownloads/test/unit (r=sicking) (62de0552b6)
- Bug 1225641 - Change default security flags within NetUtil.newChannel (r=sicking) (f04a8d6a1d)
- Bug 1224467 - Add a preference for controlling whether oneCRL blocklists are updated via AMO. Also add a test. r=keeler,mossop (06c4ce13f9)
- Bug 1170760 part 1. Introduce a PromiseCapability struct. r=baku,efaust (068615a4cd)
- Bug 1170760 part 2. Pass in the 'this' value to Promise static methods. r=peterv (170fd5de55)
- Bug 1170760 part 3. Add an @@species getter on Promise. r=peterv (182a90f4ee)
- Bug 1170760 part 4. Change Promise::Constructor to run in the Xray compartment when new Promise happens over Xrays. r=peterv (ac9bf8968b)
- Bug 1170760 part 5. Implement NewPromiseCapability which can either return a PromiseCapability as in the spec, or one that has a native promise and maybe resolve/reject functions if the consumer asked for them. r=baku,efaust (6c74f4ebdf)
- Bug 1170760 part 6. Fix GetDependentPromise to deal with a situation when someone called then() and passed it the resolve/reject functions that come from a promise's constructor. r=baku (fa6504ca29)
- Bug 1170760 part 7. Add subclassing support to Promise::Race. r=baku,efaust (d43c0782d6)
- Bug 1170760 part 8. Add subclassing support to Promise::All. r=baku,efaust (37d8577256)
- Bug 1170760 part 9. Stop using Promise::Resolve in the bindings for PromiseDebugging. r=baku (3c3073d0fa)
- Bug 1170760 part 10. Add subclassing support to Promise::Resolve. r=baku,efaust (22a5f2b385)
- Bug 1170760 part 11. Add subclassing support to Promise::Reject. r=baku,efaust (c696a0a9fe)
- Bug 1170760 part 12. Rip out the promise-resolved-with-promise fast path. r=baku (a1815842e2)
- Bug 1170760 part 13. Add subclassing support to Promise::Then/Catch. r=baku,efaust (3fd8f2502d)
2023-03-30 10:36:09 +08:00

122 lines
3.0 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=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_domrequest_h__
#define mozilla_dom_domrequest_h__
#include "nsIDOMDOMRequest.h"
#include "mozilla/Attributes.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/DOMError.h"
#include "mozilla/dom/DOMRequestBinding.h"
#include "nsCOMPtr.h"
namespace mozilla {
class ErrorResult;
namespace dom {
class AnyCallback;
class Promise;
class DOMRequest : public DOMEventTargetHelper,
public nsIDOMDOMRequest
{
protected:
JS::Heap<JS::Value> mResult;
RefPtr<DOMError> mError;
RefPtr<Promise> mPromise;
bool mDone;
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOMDOMREQUEST
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DOMRequest,
DOMEventTargetHelper)
// WrapperCache
nsPIDOMWindow* GetParentObject() const
{
return GetOwner();
}
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
// WebIDL Interface
DOMRequestReadyState ReadyState() const
{
return mDone ? DOMRequestReadyState::Done
: DOMRequestReadyState::Pending;
}
void GetResult(JSContext*, JS::MutableHandle<JS::Value> aRetval) const
{
NS_ASSERTION(mDone || mResult.isUndefined(),
"Result should be undefined when pending");
JS::ExposeValueToActiveJS(mResult);
aRetval.set(mResult);
}
DOMError* GetError() const
{
NS_ASSERTION(mDone || !mError,
"Error should be null when pending");
return mError;
}
IMPL_EVENT_HANDLER(success)
IMPL_EVENT_HANDLER(error)
void
Then(JSContext* aCx, AnyCallback* aResolveCallback,
AnyCallback* aRejectCallback,
JS::MutableHandle<JS::Value> aRetval,
mozilla::ErrorResult& aRv);
void FireSuccess(JS::Handle<JS::Value> aResult);
void FireError(const nsAString& aError);
void FireError(nsresult aError);
void FireDetailedError(DOMError* aError);
explicit DOMRequest(nsPIDOMWindow* aWindow);
explicit DOMRequest(nsIGlobalObject* aGlobal);
protected:
virtual ~DOMRequest();
void FireEvent(const nsAString& aType, bool aBubble, bool aCancelable);
void RootResultVal();
};
class DOMRequestService final : public nsIDOMRequestService
{
~DOMRequestService() {}
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMREQUESTSERVICE
// Returns an owning reference! No one should call this but the factory.
static DOMRequestService* FactoryCreate()
{
DOMRequestService* res = new DOMRequestService;
NS_ADDREF(res);
return res;
}
};
} // namespace dom
} // namespace mozilla
#define DOMREQUEST_SERVICE_CONTRACTID "@mozilla.org/dom/dom-request-service;1"
#endif // mozilla_dom_domrequest_h__