Bug 1812499 [wpt PR 38184] - Simplify handling of name-to-subdir mapping in canvas...
[gecko.git] / dom / locks / Lock.cpp
blob24d5456c54154f04d879ea9b35fcf3f93c8d9087
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/Lock.h"
8 #include "mozilla/dom/LockBinding.h"
9 #include "mozilla/dom/LockManager.h"
10 #include "mozilla/dom/Promise.h"
11 #include "mozilla/dom/locks/LockRequestChild.h"
13 namespace mozilla::dom {
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Lock, mOwner, mWaitingPromise,
16 mReleasedPromise)
17 NS_IMPL_CYCLE_COLLECTING_ADDREF(Lock)
18 NS_IMPL_CYCLE_COLLECTING_RELEASE(Lock)
19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Lock)
20 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
21 NS_INTERFACE_MAP_ENTRY(nsISupports)
22 NS_INTERFACE_MAP_END
24 Lock::Lock(nsIGlobalObject* aGlobal,
25 const WeakPtr<locks::LockRequestChild>& aLockRequestChild,
26 const nsString& aName, LockMode aMode,
27 const RefPtr<Promise>& aReleasedPromise, ErrorResult& aRv)
28 : mOwner(aGlobal),
29 mLockRequestChild(aLockRequestChild),
30 mName(aName),
31 mMode(aMode),
32 mWaitingPromise(Promise::Create(aGlobal, aRv)),
33 mReleasedPromise(aReleasedPromise) {
34 MOZ_ASSERT(mLockRequestChild);
35 MOZ_ASSERT(aReleasedPromise);
38 JSObject* Lock::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
39 return Lock_Binding::Wrap(aCx, this, aGivenProto);
42 void Lock::GetName(nsString& aRetVal) const { aRetVal = mName; }
44 LockMode Lock::Mode() const { return mMode; }
46 Promise& Lock::GetWaitingPromise() {
47 MOZ_ASSERT(mWaitingPromise);
48 return *mWaitingPromise;
51 void Lock::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
52 ErrorResult& aRv) {
53 if (mLockRequestChild) {
54 locks::PLockRequestChild::Send__delete__(mLockRequestChild, false);
55 mLockRequestChild = nullptr;
57 mReleasedPromise->MaybeResolve(aValue);
60 void Lock::RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue,
61 ErrorResult& aRv) {
62 if (mLockRequestChild) {
63 locks::PLockRequestChild::Send__delete__(mLockRequestChild, false);
64 mLockRequestChild = nullptr;
66 mReleasedPromise->MaybeReject(aValue);
69 } // namespace mozilla::dom