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 "ProfileAdditionalInformation.h"
11 #include "js/PropertyAndElement.h"
13 #include "mozilla/JSONStringWriteFuncs.h"
14 #include "mozilla/ipc/IPDLParamTraits.h"
16 #ifdef MOZ_GECKO_PROFILER
17 # include "platform.h"
19 void mozilla::ProfileGenerationAdditionalInformation::ToJSValue(
20 JSContext
* aCx
, JS::MutableHandle
<JS::Value
> aRetVal
) const {
21 // Get the shared libraries array.
22 JS::Rooted
<JS::Value
> sharedLibrariesVal(aCx
);
24 JSONStringWriteFunc
<nsCString
> buffer
;
25 JSONWriter
w(buffer
, JSONWriter::SingleLineStyle
);
26 w
.StartArrayElement();
27 AppendSharedLibraries(w
, mSharedLibraries
);
29 NS_ConvertUTF8toUTF16
buffer16(buffer
.StringCRef());
30 MOZ_ALWAYS_TRUE(JS_ParseJSON(aCx
,
31 static_cast<const char16_t
*>(buffer16
.get()),
32 buffer16
.Length(), &sharedLibrariesVal
));
35 JS::Rooted
<JSObject
*> additionalInfoObj(aCx
, JS_NewPlainObject(aCx
));
36 JS_SetProperty(aCx
, additionalInfoObj
, "sharedLibraries", sharedLibrariesVal
);
37 aRetVal
.setObject(*additionalInfoObj
);
39 #endif // MOZ_GECKO_PROFILER
44 struct ParamTraits
<SharedLibrary
> {
45 typedef SharedLibrary paramType
;
47 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
);
48 static bool Read(MessageReader
* aReader
, paramType
* aResult
);
52 struct ParamTraits
<SharedLibraryInfo
> {
53 typedef SharedLibraryInfo paramType
;
55 static void Write(MessageWriter
* aWriter
, const paramType
& aParam
);
56 static bool Read(MessageReader
* aReader
, paramType
* aResult
);
59 void IPC::ParamTraits
<SharedLibrary
>::Write(MessageWriter
* aWriter
,
60 const paramType
& aParam
) {
61 WriteParam(aWriter
, aParam
.mStart
);
62 WriteParam(aWriter
, aParam
.mEnd
);
63 WriteParam(aWriter
, aParam
.mOffset
);
64 WriteParam(aWriter
, aParam
.mBreakpadId
);
65 WriteParam(aWriter
, aParam
.mCodeId
);
66 WriteParam(aWriter
, aParam
.mModuleName
);
67 WriteParam(aWriter
, aParam
.mModulePath
);
68 WriteParam(aWriter
, aParam
.mDebugName
);
69 WriteParam(aWriter
, aParam
.mDebugPath
);
70 WriteParam(aWriter
, aParam
.mVersion
);
71 WriteParam(aWriter
, aParam
.mArch
);
74 bool IPC::ParamTraits
<SharedLibrary
>::Read(MessageReader
* aReader
,
76 return ReadParam(aReader
, &aResult
->mStart
) &&
77 ReadParam(aReader
, &aResult
->mEnd
) &&
78 ReadParam(aReader
, &aResult
->mOffset
) &&
79 ReadParam(aReader
, &aResult
->mBreakpadId
) &&
80 ReadParam(aReader
, &aResult
->mCodeId
) &&
81 ReadParam(aReader
, &aResult
->mModuleName
) &&
82 ReadParam(aReader
, &aResult
->mModulePath
) &&
83 ReadParam(aReader
, &aResult
->mDebugName
) &&
84 ReadParam(aReader
, &aResult
->mDebugPath
) &&
85 ReadParam(aReader
, &aResult
->mVersion
) &&
86 ReadParam(aReader
, &aResult
->mArch
);
89 void IPC::ParamTraits
<SharedLibraryInfo
>::Write(MessageWriter
* aWriter
,
90 const paramType
& aParam
) {
91 paramType
& p
= const_cast<paramType
&>(aParam
);
92 WriteParam(aWriter
, p
.mEntries
);
95 bool IPC::ParamTraits
<SharedLibraryInfo
>::Read(MessageReader
* aReader
,
97 return ReadParam(aReader
, &aResult
->mEntries
);
100 void IPC::ParamTraits
<mozilla::ProfileGenerationAdditionalInformation
>::Write(
101 MessageWriter
* aWriter
, const paramType
& aParam
) {
102 WriteParam(aWriter
, aParam
.mSharedLibraries
);
105 bool IPC::ParamTraits
<mozilla::ProfileGenerationAdditionalInformation
>::Read(
106 MessageReader
* aReader
, paramType
* aResult
) {
107 return ReadParam(aReader
, &aResult
->mSharedLibraries
);