Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / dom / webauthn / AuthenticatorResponse.cpp
blobd12dc01505232f46421c39774363fbe910fb318e
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/AuthenticatorResponse.h"
9 #include "nsPIDOMWindow.h"
10 #include "nsWrapperCache.h"
12 namespace mozilla::dom {
14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS(
15 AuthenticatorResponse, (mParent), (mClientDataJSONCachedObj))
17 NS_IMPL_CYCLE_COLLECTING_ADDREF(AuthenticatorResponse)
18 NS_IMPL_CYCLE_COLLECTING_RELEASE(AuthenticatorResponse)
20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AuthenticatorResponse)
21 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
22 NS_INTERFACE_MAP_ENTRY(nsISupports)
23 NS_INTERFACE_MAP_END
25 AuthenticatorResponse::AuthenticatorResponse(nsPIDOMWindowInner* aParent)
26 : mParent(aParent), mClientDataJSONCachedObj(nullptr) {
27 // Call HoldJSObjects() in subclasses.
30 AuthenticatorResponse::~AuthenticatorResponse() {
31 // Call DropJSObjects() in subclasses.
34 nsISupports* AuthenticatorResponse::GetParentObject() const { return mParent; }
36 void AuthenticatorResponse::GetClientDataJSON(
37 JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
38 if (!mClientDataJSONCachedObj) {
39 mClientDataJSONCachedObj = mClientDataJSON.ToArrayBuffer(aCx);
41 aRetVal.set(mClientDataJSONCachedObj);
44 nsresult AuthenticatorResponse::SetClientDataJSON(CryptoBuffer& aBuffer) {
45 if (NS_WARN_IF(!mClientDataJSON.Assign(aBuffer))) {
46 return NS_ERROR_OUT_OF_MEMORY;
48 return NS_OK;
51 } // namespace mozilla::dom