OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/public/cpp/bindings/lib/wtf_string_serialization.h" | 5 #include "mojo/public/cpp/bindings/lib/wtf_string_serialization.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <queue> | 9 #include <queue> |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 *output = nullptr; | 80 *output = nullptr; |
81 return; | 81 return; |
82 } | 82 } |
83 | 83 |
84 auto& utf8_adaptors = | 84 auto& utf8_adaptors = |
85 static_cast<WTFStringContextImpl*>(context->wtf_string_context.get()) | 85 static_cast<WTFStringContextImpl*>(context->wtf_string_context.get()) |
86 ->utf8_adaptors(); | 86 ->utf8_adaptors(); |
87 | 87 |
88 DCHECK(!utf8_adaptors.empty()); | 88 DCHECK(!utf8_adaptors.empty()); |
89 #if DCHECK_IS_ON() | 89 #if DCHECK_IS_ON() |
90 DCHECK_EQ(utf8_adaptors.front().original_input, | 90 DCHECK_EQ(utf8_adaptors.front().original_input, |
please use gerrit instead
2016/03/17 19:34:31
yzshen@: Why would this DCHECK?
For context, here
yzshen1
2016/03/17 21:41:17
I will look into it. Would you please tell me the
| |
91 reinterpret_cast<uintptr_t>(&input)); | 91 reinterpret_cast<uintptr_t>(&input)) |
92 << " string:'" << input.utf8().data() << "'"; | |
92 #endif | 93 #endif |
93 | 94 |
94 const WTF::StringUTF8Adaptor& adaptor = utf8_adaptors.front().utf8_adaptor; | 95 const WTF::StringUTF8Adaptor& adaptor = utf8_adaptors.front().utf8_adaptor; |
95 | 96 |
96 mojo::internal::String_Data* result = | 97 mojo::internal::String_Data* result = |
97 mojo::internal::String_Data::New(adaptor.length(), buf); | 98 mojo::internal::String_Data::New(adaptor.length(), buf); |
98 if (result) | 99 if (result) |
99 memcpy(result->storage(), adaptor.data(), adaptor.length()); | 100 memcpy(result->storage(), adaptor.data(), adaptor.length()); |
100 | 101 |
101 utf8_adaptors.pop(); | 102 utf8_adaptors.pop(); |
102 | 103 |
103 *output = result; | 104 *output = result; |
104 } | 105 } |
105 | 106 |
106 bool Deserialize_(mojo::internal::String_Data* input, | 107 bool Deserialize_(mojo::internal::String_Data* input, |
107 WTF::String* output, | 108 WTF::String* output, |
108 mojo::internal::SerializationContext* context) { | 109 mojo::internal::SerializationContext* context) { |
109 if (input) { | 110 if (input) { |
110 WTF::String result = WTF::String::fromUTF8(input->storage(), input->size()); | 111 WTF::String result = WTF::String::fromUTF8(input->storage(), input->size()); |
111 output->swap(result); | 112 output->swap(result); |
112 } else if (!output->isNull()) { | 113 } else if (!output->isNull()) { |
113 WTF::String result; | 114 WTF::String result; |
114 output->swap(result); | 115 output->swap(result); |
115 } | 116 } |
116 return true; | 117 return true; |
117 } | 118 } |
118 | 119 |
119 } // namespace WTF | 120 } // namespace WTF |
OLD | NEW |