2 * Copyright (C) 2013 University of Washington. All rights reserved.
3 * Copyright (C) 2014 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #include "EncodedValue.h"
31 #if ENABLE(WEB_REPLAY)
33 #include "InspectorValues.h"
34 #include <wtf/text/Base64.h>
36 using namespace Inspector
;
40 PassRefPtr
<InspectorObject
> EncodedValue::asObject()
42 RefPtr
<InspectorObject
> result
;
43 bool castSucceeded
= m_value
->asObject(&result
);
44 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
46 return result
.release();
49 PassRefPtr
<InspectorArray
> EncodedValue::asArray()
51 RefPtr
<InspectorArray
> result
;
52 bool castSucceeded
= m_value
->asArray(&result
);
53 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
55 return result
.release();
58 template<> EncodedValue ScalarEncodingTraits
<bool>::encodeValue(const bool& value
)
60 return EncodedValue(InspectorBasicValue::create(value
));
63 template<> EncodedValue ScalarEncodingTraits
<double>::encodeValue(const double& value
)
65 return EncodedValue(InspectorBasicValue::create(value
));
68 template<> EncodedValue ScalarEncodingTraits
<float>::encodeValue(const float& value
)
70 return EncodedValue(InspectorBasicValue::create((double)value
));
73 template<> EncodedValue ScalarEncodingTraits
<int32_t>::encodeValue(const int32_t& value
)
75 return EncodedValue(InspectorBasicValue::create((double)value
));
78 template<> EncodedValue ScalarEncodingTraits
<int64_t>::encodeValue(const int64_t& value
)
80 return EncodedValue(InspectorBasicValue::create((double)value
));
83 template<> EncodedValue ScalarEncodingTraits
<uint32_t>::encodeValue(const uint32_t& value
)
85 return EncodedValue(InspectorBasicValue::create((double)value
));
88 template<> EncodedValue ScalarEncodingTraits
<uint64_t>::encodeValue(const uint64_t& value
)
90 return EncodedValue(InspectorBasicValue::create((double)value
));
93 template<> EncodedValue ScalarEncodingTraits
<unsigned long>::encodeValue(const unsigned long& value
)
95 return EncodedValue(InspectorBasicValue::create((double)value
));
98 template<> bool EncodedValue::convertTo
<bool>()
101 bool castSucceeded
= m_value
->asBoolean(&result
);
102 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
107 template<> double EncodedValue::convertTo
<double>()
110 bool castSucceeded
= m_value
->asNumber(&result
);
111 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
116 template<> float EncodedValue::convertTo
<float>()
119 bool castSucceeded
= m_value
->asNumber(&result
);
120 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
125 template<> int32_t EncodedValue::convertTo
<int32_t>()
128 bool castSucceeded
= m_value
->asNumber(&result
);
129 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
134 template<> int64_t EncodedValue::convertTo
<int64_t>()
137 bool castSucceeded
= m_value
->asNumber(&result
);
138 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
143 template<> uint32_t EncodedValue::convertTo
<uint32_t>()
146 bool castSucceeded
= m_value
->asNumber(&result
);
147 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
152 template<> uint64_t EncodedValue::convertTo
<uint64_t>()
155 bool castSucceeded
= m_value
->asNumber(&result
);
156 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
161 template<> unsigned long EncodedValue::convertTo
<unsigned long>()
163 unsigned long result
;
164 bool castSucceeded
= m_value
->asNumber(&result
);
165 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
170 template<> String
EncodedValue::convertTo
<String
>()
173 bool castSucceeded
= m_value
->asString(&result
);
174 ASSERT_UNUSED(castSucceeded
, castSucceeded
);
180 void EncodedValue::put
<EncodedValue
>(const String
& key
, const typename EncodingTraits
<EncodedValue
>::DecodedType
& value
)
182 asObject()->setValue(key
, value
.m_value
);
186 void EncodedValue::append
<EncodedValue
>(const typename EncodingTraits
<EncodedValue
>::DecodedType
& value
)
188 asArray()->pushValue(value
.m_value
);
192 bool EncodedValue::get
<EncodedValue
>(const String
& key
, typename EncodingTraits
<EncodedValue
>::DecodedType
& decodedValue
)
194 RefPtr
<Inspector::InspectorValue
> inspectorValue(asObject()->get(key
));
198 decodedValue
= EncodedValue(inspectorValue
);
205 #endif // ENABLE(WEB_REPLAY)