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/. */
6
7 #include "mozilla/dom/DeprecationReportBody.h"
8 #include "mozilla/dom/ReportingBinding.h"
9 #include "mozilla/JSONWriter.h"
10
11 namespace mozilla {
12 namespace dom {
13
DeprecationReportBody(nsIGlobalObject * aGlobal,const nsAString & aId,const Nullable<uint64_t> & aDate,const nsAString & aMessage,const nsAString & aSourceFile,const Nullable<uint32_t> & aLineNumber,const Nullable<uint32_t> & aColumnNumber)14 DeprecationReportBody::DeprecationReportBody(
15 nsIGlobalObject* aGlobal, const nsAString& aId,
16 const Nullable<uint64_t>& aDate, const nsAString& aMessage,
17 const nsAString& aSourceFile, const Nullable<uint32_t>& aLineNumber,
18 const Nullable<uint32_t>& aColumnNumber)
19 : ReportBody(aGlobal),
20 mId(aId),
21 mDate(aDate),
22 mMessage(aMessage),
23 mSourceFile(aSourceFile),
24 mLineNumber(aLineNumber),
25 mColumnNumber(aColumnNumber) {
26 MOZ_ASSERT(aGlobal);
27 }
28
29 DeprecationReportBody::~DeprecationReportBody() = default;
30
WrapObject(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)31 JSObject* DeprecationReportBody::WrapObject(JSContext* aCx,
32 JS::Handle<JSObject*> aGivenProto) {
33 return DeprecationReportBody_Binding::Wrap(aCx, this, aGivenProto);
34 }
35
GetId(nsAString & aId) const36 void DeprecationReportBody::GetId(nsAString& aId) const { aId = mId; }
37
GetAnticipatedRemoval() const38 Nullable<uint64_t> DeprecationReportBody::GetAnticipatedRemoval() const {
39 return mDate;
40 }
41
GetMessage(nsAString & aMessage) const42 void DeprecationReportBody::GetMessage(nsAString& aMessage) const {
43 aMessage = mMessage;
44 }
45
GetSourceFile(nsAString & aSourceFile) const46 void DeprecationReportBody::GetSourceFile(nsAString& aSourceFile) const {
47 aSourceFile = mSourceFile;
48 }
49
GetLineNumber() const50 Nullable<uint32_t> DeprecationReportBody::GetLineNumber() const {
51 return mLineNumber;
52 }
53
GetColumnNumber() const54 Nullable<uint32_t> DeprecationReportBody::GetColumnNumber() const {
55 return mColumnNumber;
56 }
57
ToJSON(JSONWriter & aWriter) const58 void DeprecationReportBody::ToJSON(JSONWriter& aWriter) const {
59 aWriter.StringProperty("id", NS_ConvertUTF16toUTF8(mId));
60 // TODO: anticipatedRemoval? https://github.com/w3c/reporting/issues/132
61 aWriter.StringProperty("message", NS_ConvertUTF16toUTF8(mMessage));
62
63 if (mSourceFile.IsEmpty()) {
64 aWriter.NullProperty("sourceFile");
65 } else {
66 aWriter.StringProperty("sourceFile", NS_ConvertUTF16toUTF8(mSourceFile));
67 }
68
69 if (mLineNumber.IsNull()) {
70 aWriter.NullProperty("lineNumber");
71 } else {
72 aWriter.IntProperty("lineNumber", mLineNumber.Value());
73 }
74
75 if (mColumnNumber.IsNull()) {
76 aWriter.NullProperty("columnNumber");
77 } else {
78 aWriter.IntProperty("columnNumber", mColumnNumber.Value());
79 }
80 }
81
82 } // namespace dom
83 } // namespace mozilla
84