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(DomPromiseListener
)
18 DomPromiseListener::DomPromiseListener(CallbackTypeResolved
&& aResolve
,
19 CallbackTypeRejected
&& aReject
)
20 : mResolve(std::move(aResolve
)), mReject(std::move(aReject
)) {}
22 DomPromiseListener::~DomPromiseListener() {
24 mReject(NS_BINDING_ABORTED
);
28 void DomPromiseListener::ResolvedCallback(JSContext
* aCx
,
29 JS::Handle
<JS::Value
> aValue
,
32 mResolve(aCx
, aValue
);
34 // Let's clear the lambdas in case we have a cycle to ourselves.
38 void DomPromiseListener::RejectedCallback(JSContext
* aCx
,
39 JS::Handle
<JS::Value
> aValue
,
42 nsresult errorCode
= NS_ERROR_DOM_NOT_NUMBER_ERR
;
43 if (aValue
.isInt32()) {
44 errorCode
= nsresult(aValue
.toInt32());
45 } else if (aValue
.isObject()) {
46 RefPtr
<::mozilla::dom::DOMException
> domException
;
47 UNWRAP_OBJECT(DOMException
, aValue
, domException
);
49 errorCode
= domException
->GetResult();
54 // Let's clear the lambdas in case we have a cycle to ourselves.
58 void DomPromiseListener::Clear() {
63 } // namespace mozilla::dom