Bug 1835710 - Cancel off-thread JIT compilation before changing nursery allocation...
[gecko.git] / dom / push / PushSubscriptionOptions.cpp
blob1de3d96a2ee5468a50814e247b215511012ab9d4
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 "mozilla/dom/PushSubscriptionOptions.h"
9 #include "MainThreadUtils.h"
10 #include "mozilla/dom/PushSubscriptionOptionsBinding.h"
11 #include "mozilla/ErrorResult.h"
12 #include "mozilla/HoldDropJSObjects.h"
13 #include "mozilla/dom/PushUtil.h"
14 #include "nsIGlobalObject.h"
15 #include "nsWrapperCache.h"
17 namespace mozilla::dom {
19 PushSubscriptionOptions::PushSubscriptionOptions(
20 nsIGlobalObject* aGlobal, nsTArray<uint8_t>&& aRawAppServerKey)
21 : mGlobal(aGlobal),
22 mRawAppServerKey(std::move(aRawAppServerKey)),
23 mAppServerKey(nullptr) {
24 // There's only one global on a worker, so we don't need to pass a global
25 // object to the constructor.
26 MOZ_ASSERT_IF(NS_IsMainThread(), mGlobal);
27 mozilla::HoldJSObjects(this);
30 PushSubscriptionOptions::~PushSubscriptionOptions() {
31 mozilla::DropJSObjects(this);
34 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS(PushSubscriptionOptions,
35 (mGlobal),
36 (mAppServerKey))
38 NS_IMPL_CYCLE_COLLECTING_ADDREF(PushSubscriptionOptions)
39 NS_IMPL_CYCLE_COLLECTING_RELEASE(PushSubscriptionOptions)
41 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PushSubscriptionOptions)
42 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
43 NS_INTERFACE_MAP_ENTRY(nsISupports)
44 NS_INTERFACE_MAP_END
46 JSObject* PushSubscriptionOptions::WrapObject(
47 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
48 return PushSubscriptionOptions_Binding::Wrap(aCx, this, aGivenProto);
51 void PushSubscriptionOptions::GetApplicationServerKey(
52 JSContext* aCx, JS::MutableHandle<JSObject*> aKey, ErrorResult& aRv) {
53 if (!mRawAppServerKey.IsEmpty() && !mAppServerKey) {
54 JS::Rooted<JSObject*> appServerKey(aCx);
55 PushUtil::CopyArrayToArrayBuffer(aCx, mRawAppServerKey, &appServerKey, aRv);
56 if (aRv.Failed()) {
57 return;
59 MOZ_ASSERT(appServerKey);
60 mAppServerKey = appServerKey;
62 aKey.set(mAppServerKey);
65 } // namespace mozilla::dom