1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 "mozilla/dom/MMICall.h"
9 #include "mozilla/dom/MMICallBinding.h"
10 #include "nsIGlobalObject.h"
12 using namespace mozilla::dom
;
13 using mozilla::ErrorResult
;
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MMICall
, mWindow
)
16 NS_IMPL_CYCLE_COLLECTING_ADDREF(MMICall
)
17 NS_IMPL_CYCLE_COLLECTING_RELEASE(MMICall
)
18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MMICall
)
19 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
20 NS_INTERFACE_MAP_ENTRY(nsISupports
)
23 MMICall::MMICall(nsPIDOMWindow
* aWindow
, const nsAString
& aServiceCode
)
24 : mWindow(aWindow
), mServiceCode(aServiceCode
)
26 nsCOMPtr
<nsIGlobalObject
> global
= do_QueryInterface(mWindow
);
32 nsRefPtr
<Promise
> promise
= Promise::Create(global
, rv
);
45 MMICall::GetParentObject() const
51 MMICall::WrapObject(JSContext
* aCx
)
53 return MMICallBinding::Wrap(aCx
, this);
57 MMICall::NotifyResult(JS::Handle
<JS::Value
> aResult
)
63 mPromise
->MaybeResolve(aResult
);
68 already_AddRefed
<Promise
>
69 MMICall::GetResult(ErrorResult
& aRv
)
72 aRv
.Throw(NS_ERROR_UNEXPECTED
);
76 nsRefPtr
<Promise
> promise
= mPromise
;
77 return promise
.forget();