]> git.saurik.com Git - apple/javascriptcore.git/blob - replay/EncodedValue.cpp
JavaScriptCore-7600.1.4.16.1.tar.gz
[apple/javascriptcore.git] / replay / EncodedValue.cpp
1 /*
2 * Copyright (C) 2013 University of Washington. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "config.h"
29 #include "EncodedValue.h"
30
31 #if ENABLE(WEB_REPLAY)
32
33 #include "InspectorValues.h"
34 #include <wtf/text/Base64.h>
35
36 using namespace Inspector;
37
38 namespace JSC {
39
40 PassRefPtr<InspectorObject> EncodedValue::asObject()
41 {
42 RefPtr<InspectorObject> result;
43 bool castSucceeded = m_value->asObject(&result);
44 ASSERT_UNUSED(castSucceeded, castSucceeded);
45
46 return result.release();
47 }
48
49 PassRefPtr<InspectorArray> EncodedValue::asArray()
50 {
51 RefPtr<InspectorArray> result;
52 bool castSucceeded = m_value->asArray(&result);
53 ASSERT_UNUSED(castSucceeded, castSucceeded);
54
55 return result.release();
56 }
57
58 template<> EncodedValue ScalarEncodingTraits<bool>::encodeValue(const bool& value)
59 {
60 return EncodedValue(InspectorBasicValue::create(value));
61 }
62
63 template<> EncodedValue ScalarEncodingTraits<double>::encodeValue(const double& value)
64 {
65 return EncodedValue(InspectorBasicValue::create(value));
66 }
67
68 template<> EncodedValue ScalarEncodingTraits<float>::encodeValue(const float& value)
69 {
70 return EncodedValue(InspectorBasicValue::create((double)value));
71 }
72
73 template<> EncodedValue ScalarEncodingTraits<int32_t>::encodeValue(const int32_t& value)
74 {
75 return EncodedValue(InspectorBasicValue::create((double)value));
76 }
77
78 template<> EncodedValue ScalarEncodingTraits<int64_t>::encodeValue(const int64_t& value)
79 {
80 return EncodedValue(InspectorBasicValue::create((double)value));
81 }
82
83 template<> EncodedValue ScalarEncodingTraits<uint32_t>::encodeValue(const uint32_t& value)
84 {
85 return EncodedValue(InspectorBasicValue::create((double)value));
86 }
87
88 template<> EncodedValue ScalarEncodingTraits<uint64_t>::encodeValue(const uint64_t& value)
89 {
90 return EncodedValue(InspectorBasicValue::create((double)value));
91 }
92
93 template<> EncodedValue ScalarEncodingTraits<unsigned long>::encodeValue(const unsigned long& value)
94 {
95 return EncodedValue(InspectorBasicValue::create((double)value));
96 }
97
98 template<> bool EncodedValue::convertTo<bool>()
99 {
100 bool result;
101 bool castSucceeded = m_value->asBoolean(&result);
102 ASSERT_UNUSED(castSucceeded, castSucceeded);
103
104 return result;
105 }
106
107 template<> double EncodedValue::convertTo<double>()
108 {
109 double result;
110 bool castSucceeded = m_value->asNumber(&result);
111 ASSERT_UNUSED(castSucceeded, castSucceeded);
112
113 return result;
114 }
115
116 template<> float EncodedValue::convertTo<float>()
117 {
118 float result;
119 bool castSucceeded = m_value->asNumber(&result);
120 ASSERT_UNUSED(castSucceeded, castSucceeded);
121
122 return result;
123 }
124
125 template<> int32_t EncodedValue::convertTo<int32_t>()
126 {
127 int32_t result;
128 bool castSucceeded = m_value->asNumber(&result);
129 ASSERT_UNUSED(castSucceeded, castSucceeded);
130
131 return result;
132 }
133
134 template<> int64_t EncodedValue::convertTo<int64_t>()
135 {
136 int64_t result;
137 bool castSucceeded = m_value->asNumber(&result);
138 ASSERT_UNUSED(castSucceeded, castSucceeded);
139
140 return result;
141 }
142
143 template<> uint32_t EncodedValue::convertTo<uint32_t>()
144 {
145 uint32_t result;
146 bool castSucceeded = m_value->asNumber(&result);
147 ASSERT_UNUSED(castSucceeded, castSucceeded);
148
149 return result;
150 }
151
152 template<> uint64_t EncodedValue::convertTo<uint64_t>()
153 {
154 uint64_t result;
155 bool castSucceeded = m_value->asNumber(&result);
156 ASSERT_UNUSED(castSucceeded, castSucceeded);
157
158 return result;
159 }
160
161 template<> unsigned long EncodedValue::convertTo<unsigned long>()
162 {
163 unsigned long result;
164 bool castSucceeded = m_value->asNumber(&result);
165 ASSERT_UNUSED(castSucceeded, castSucceeded);
166
167 return result;
168 }
169
170 template<> String EncodedValue::convertTo<String>()
171 {
172 String result;
173 bool castSucceeded = m_value->asString(&result);
174 ASSERT_UNUSED(castSucceeded, castSucceeded);
175
176 return result;
177 }
178
179 template<>
180 void EncodedValue::put<EncodedValue>(const String& key, const typename EncodingTraits<EncodedValue>::DecodedType& value)
181 {
182 asObject()->setValue(key, value.m_value);
183 }
184
185 template<>
186 void EncodedValue::append<EncodedValue>(const typename EncodingTraits<EncodedValue>::DecodedType& value)
187 {
188 asArray()->pushValue(value.m_value);
189 }
190
191 template<>
192 bool EncodedValue::get<EncodedValue>(const String& key, typename EncodingTraits<EncodedValue>::DecodedType& decodedValue)
193 {
194 RefPtr<Inspector::InspectorValue> inspectorValue(asObject()->get(key));
195 if (!inspectorValue)
196 return false;
197
198 decodedValue = EncodedValue(inspectorValue);
199 return true;
200 }
201
202
203 }; // namespace JSC
204
205 #endif // ENABLE(WEB_REPLAY)