Backed out 2 changesets (bug 1818237) for causing xpc failures on browser/components...
[gecko.git] / dom / webgpu / DeviceLostInfo.h
blob1ab77610c702f30e3def0558c64a708cc509ff7b
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 {
15 class Device;
17 class DeviceLostInfo final : public nsWrapperCache {
18 public:
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) {}
29 private:
30 ~DeviceLostInfo() = default;
31 void Cleanup() {}
33 nsCOMPtr<nsIGlobalObject> mGlobal;
34 const Maybe<dom::GPUDeviceLostReason> mReason;
35 const nsAutoString mMessage;
37 public:
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_