Bug 1824634 disconnect from GtkIMContext OnDestroyWindow r=masayuki
[gecko.git] / dom / promise / PromiseNativeHandler.cpp
blob88f7edef3ae18ccf051edec1270689f51e2a2dea
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() {
23 if (mReject) {
24 mReject(NS_BINDING_ABORTED);
28 void DomPromiseListener::ResolvedCallback(JSContext* aCx,
29 JS::Handle<JS::Value> aValue,
30 ErrorResult& aRv) {
31 if (mResolve) {
32 mResolve(aCx, aValue);
34 // Let's clear the lambdas in case we have a cycle to ourselves.
35 Clear();
38 void DomPromiseListener::RejectedCallback(JSContext* aCx,
39 JS::Handle<JS::Value> aValue,
40 ErrorResult& aRv) {
41 if (mReject) {
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);
48 if (domException) {
49 errorCode = domException->GetResult();
52 mReject(errorCode);
54 // Let's clear the lambdas in case we have a cycle to ourselves.
55 Clear();
58 void DomPromiseListener::Clear() {
59 mResolve = nullptr;
60 mReject = nullptr;
63 } // namespace mozilla::dom