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/DeprecationReportBody.h"
8 #include "mozilla/dom/ReportingBinding.h"
9 #include "mozilla/JSONWriter.h"
11 namespace mozilla::dom
{
13 DeprecationReportBody::DeprecationReportBody(
14 nsIGlobalObject
* aGlobal
, const nsAString
& aId
,
15 const Nullable
<uint64_t>& aDate
, const nsAString
& aMessage
,
16 const nsAString
& aSourceFile
, const Nullable
<uint32_t>& aLineNumber
,
17 const Nullable
<uint32_t>& aColumnNumber
)
18 : ReportBody(aGlobal
),
22 mSourceFile(aSourceFile
),
23 mLineNumber(aLineNumber
),
24 mColumnNumber(aColumnNumber
) {
28 DeprecationReportBody::~DeprecationReportBody() = default;
30 JSObject
* DeprecationReportBody::WrapObject(JSContext
* aCx
,
31 JS::Handle
<JSObject
*> aGivenProto
) {
32 return DeprecationReportBody_Binding::Wrap(aCx
, this, aGivenProto
);
35 void DeprecationReportBody::GetId(nsAString
& aId
) const { aId
= mId
; }
37 Nullable
<uint64_t> DeprecationReportBody::GetAnticipatedRemoval() const {
41 void DeprecationReportBody::GetMessage(nsAString
& aMessage
) const {
45 void DeprecationReportBody::GetSourceFile(nsAString
& aSourceFile
) const {
46 aSourceFile
= mSourceFile
;
49 Nullable
<uint32_t> DeprecationReportBody::GetLineNumber() const {
53 Nullable
<uint32_t> DeprecationReportBody::GetColumnNumber() const {
57 void DeprecationReportBody::ToJSON(JSONWriter
& aWriter
) const {
58 aWriter
.StringProperty("id", NS_ConvertUTF16toUTF8(mId
));
59 // TODO: anticipatedRemoval? https://github.com/w3c/reporting/issues/132
60 aWriter
.StringProperty("message", NS_ConvertUTF16toUTF8(mMessage
));
62 if (mSourceFile
.IsEmpty()) {
63 aWriter
.NullProperty("sourceFile");
65 aWriter
.StringProperty("sourceFile", NS_ConvertUTF16toUTF8(mSourceFile
));
68 if (mLineNumber
.IsNull()) {
69 aWriter
.NullProperty("lineNumber");
71 aWriter
.IntProperty("lineNumber", mLineNumber
.Value());
74 if (mColumnNumber
.IsNull()) {
75 aWriter
.NullProperty("columnNumber");
77 aWriter
.IntProperty("columnNumber", mColumnNumber
.Value());
81 } // namespace mozilla::dom