1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "PromiseNativeHandler.h"
8 #include "mozilla/dom/BindingUtils.h"
9 #include "mozilla/dom/Promise.h"
10 #include "mozilla/dom/DOMException.h"
11 #include "mozilla/dom/DOMExceptionBinding.h"
12 #include "nsISupportsImpl.h"
14 namespace mozilla::dom
{
16 NS_IMPL_ISUPPORTS0(MozPromiseRejectOnDestructionBase
)
18 NS_IMPL_ISUPPORTS0(DomPromiseListener
)
20 DomPromiseListener::DomPromiseListener(CallbackTypeResolved
&& aResolve
,
21 CallbackTypeRejected
&& aReject
)
22 : mResolve(std::move(aResolve
)), mReject(std::move(aReject
)) {}
24 DomPromiseListener::~DomPromiseListener() {
26 mReject(NS_BINDING_ABORTED
);
30 void DomPromiseListener::ResolvedCallback(JSContext
* aCx
,
31 JS::Handle
<JS::Value
> aValue
,
34 mResolve(aCx
, aValue
);
36 // Let's clear the lambdas in case we have a cycle to ourselves.
40 void DomPromiseListener::RejectedCallback(JSContext
* aCx
,
41 JS::Handle
<JS::Value
> aValue
,
44 nsresult errorCode
= NS_ERROR_DOM_NOT_NUMBER_ERR
;
45 if (aValue
.isInt32()) {
46 errorCode
= nsresult(aValue
.toInt32());
47 } else if (aValue
.isObject()) {
48 RefPtr
<::mozilla::dom::DOMException
> domException
;
49 UNWRAP_OBJECT(DOMException
, aValue
, domException
);
51 errorCode
= domException
->GetResult();
56 // Let's clear the lambdas in case we have a cycle to ourselves.
60 void DomPromiseListener::Clear() {
65 } // namespace mozilla::dom