OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
6 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 6 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
7 | 7 |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "bindings/core/v8/ScriptValueSerializer.h" | 9 #include "bindings/core/v8/ScriptValueSerializer.h" |
10 #include "wtf/ByteOrder.h" | 10 #include "wtf/ByteOrder.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // deserialize() can run arbitrary script (e.g., setters), which could resul
t in |this| being destroyed. | 127 // deserialize() can run arbitrary script (e.g., setters), which could resul
t in |this| being destroyed. |
128 // Holding a RefPtr ensures we are alive (along with our internal data) thro
ughout the operation. | 128 // Holding a RefPtr ensures we are alive (along with our internal data) thro
ughout the operation. |
129 RefPtr<SerializedScriptValue> protect(value); | 129 RefPtr<SerializedScriptValue> protect(value); |
130 return deserialize(value->data(), value->blobDataHandles(), value->arrayBuff
erContentsArray(), isolate, messagePorts, blobInfo); | 130 return deserialize(value->data(), value->blobDataHandles(), value->arrayBuff
erContentsArray(), isolate, messagePorts, blobInfo); |
131 } | 131 } |
132 | 132 |
133 v8::Handle<v8::Value> SerializedScriptValueFactory::deserialize(String& data, Bl
obDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBufferContentsA
rray, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArr
ay* blobInfo) | 133 v8::Handle<v8::Value> SerializedScriptValueFactory::deserialize(String& data, Bl
obDataHandleMap& blobDataHandles, ArrayBufferContentsArray* arrayBufferContentsA
rray, v8::Isolate* isolate, MessagePortArray* messagePorts, const WebBlobInfoArr
ay* blobInfo) |
134 { | 134 { |
135 if (!data.impl()) | 135 if (!data.impl()) |
136 return v8::Null(isolate); | 136 return v8::Null(isolate); |
137 COMPILE_ASSERT(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, Bu
fferValueTypeIsTwoBytes); | 137 static_assert(sizeof(SerializedScriptValueWriter::BufferValueType) == 2, "Bu
fferValueType should be 2 bytes"); |
138 data.ensure16Bit(); | 138 data.ensure16Bit(); |
139 // FIXME: SerializedScriptValue shouldn't use String for its underlying | 139 // FIXME: SerializedScriptValue shouldn't use String for its underlying |
140 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The | 140 // storage. Instead, it should use SharedBuffer or Vector<uint8_t>. The |
141 // information stored in m_data isn't even encoded in UTF-16. Instead, | 141 // information stored in m_data isn't even encoded in UTF-16. Instead, |
142 // unicode characters are encoded as UTF-8 with two code units per UChar. | 142 // unicode characters are encoded as UTF-8 with two code units per UChar. |
143 SerializedScriptValueReader reader(reinterpret_cast<const uint8_t*>(data.imp
l()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, ScriptState:
:current(isolate)); | 143 SerializedScriptValueReader reader(reinterpret_cast<const uint8_t*>(data.imp
l()->characters16()), 2 * data.length(), blobInfo, blobDataHandles, ScriptState:
:current(isolate)); |
144 ScriptValueDeserializer deserializer(reader, messagePorts, arrayBufferConten
tsArray); | 144 ScriptValueDeserializer deserializer(reader, messagePorts, arrayBufferConten
tsArray); |
145 | 145 |
146 // deserialize() can run arbitrary script (e.g., setters), which could resul
t in |this| being destroyed. | 146 // deserialize() can run arbitrary script (e.g., setters), which could resul
t in |this| being destroyed. |
147 // Holding a RefPtr ensures we are alive (along with our internal data) thro
ughout the operation. | 147 // Holding a RefPtr ensures we are alive (along with our internal data) thro
ughout the operation. |
148 return deserializer.deserialize(); | 148 return deserializer.deserialize(); |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 } // namespace blink | 152 } // namespace blink |
OLD | NEW |