1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GPU_DeviceLostInfo_H_
7 #define GPU_DeviceLostInfo_H_
9 #include "mozilla/dom/WebGPUBinding.h"
10 #include "mozilla/Maybe.h"
11 #include "nsWrapperCache.h"
12 #include "ObjectModel.h"
14 namespace mozilla::webgpu
{
17 class DeviceLostInfo final
: public nsWrapperCache
{
19 GPU_DECL_CYCLE_COLLECTION(DeviceLostInfo
)
20 GPU_DECL_JS_WRAP(DeviceLostInfo
)
22 explicit DeviceLostInfo(nsIGlobalObject
* const aGlobal
,
23 const nsAString
& aMessage
)
24 : mGlobal(aGlobal
), mMessage(aMessage
) {}
25 DeviceLostInfo(nsIGlobalObject
* const aGlobal
,
26 dom::GPUDeviceLostReason aReason
, const nsAString
& aMessage
)
27 : mGlobal(aGlobal
), mReason(Some(aReason
)), mMessage(aMessage
) {}
30 ~DeviceLostInfo() = default;
33 nsCOMPtr
<nsIGlobalObject
> mGlobal
;
34 const Maybe
<dom::GPUDeviceLostReason
> mReason
;
35 const nsAutoString mMessage
;
38 void GetReason(JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aRetval
) {
39 if (!mReason
|| !dom::ToJSValue(aCx
, mReason
.value(), aRetval
)) {
40 aRetval
.setUndefined();
44 void GetMessage(nsAString
& aValue
) const { aValue
= mMessage
; }
46 nsIGlobalObject
* GetParentObject() const { return mGlobal
; }
49 } // namespace mozilla::webgpu
51 #endif // GPU_DeviceLostInfo_H_