OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/core/v8/SerializedScriptValue.h" | 32 #include "bindings/core/v8/SerializedScriptValue.h" |
33 | 33 |
34 #include "bindings/core/v8/DOMDataStore.h" | 34 #include "bindings/core/v8/DOMDataStore.h" |
35 #include "bindings/core/v8/DOMWrapperWorld.h" | 35 #include "bindings/core/v8/DOMWrapperWorld.h" |
36 #include "bindings/core/v8/ExceptionState.h" | 36 #include "bindings/core/v8/ExceptionState.h" |
37 #include "bindings/core/v8/ScriptState.h" | |
37 #include "bindings/core/v8/ScriptValueSerializer.h" | 38 #include "bindings/core/v8/ScriptValueSerializer.h" |
38 #include "bindings/core/v8/V8ArrayBuffer.h" | 39 #include "bindings/core/v8/V8ArrayBuffer.h" |
39 #include "bindings/core/v8/V8ArrayBufferView.h" | |
40 #include "bindings/core/v8/V8Binding.h" | |
41 #include "bindings/core/v8/V8MessagePort.h" | 40 #include "bindings/core/v8/V8MessagePort.h" |
42 #include "core/dom/DOMArrayBuffer.h" | |
43 #include "core/dom/ExceptionCode.h" | 41 #include "core/dom/ExceptionCode.h" |
44 #include "platform/SharedBuffer.h" | 42 #include "platform/SharedBuffer.h" |
45 #include "platform/blob/BlobData.h" | 43 #include "platform/blob/BlobData.h" |
46 #include "platform/heap/Handle.h" | 44 #include "platform/heap/Handle.h" |
47 #include "public/platform/Platform.h" | |
48 #include "wtf/ArrayBuffer.h" | |
49 #include "wtf/ArrayBufferContents.h" | |
50 #include "wtf/ArrayBufferView.h" | |
51 #include "wtf/Assertions.h" | 45 #include "wtf/Assertions.h" |
52 #include "wtf/ByteOrder.h" | 46 #include "wtf/ByteOrder.h" |
53 #include "wtf/Uint8ClampedArray.h" | |
54 #include "wtf/Vector.h" | 47 #include "wtf/Vector.h" |
55 #include "wtf/text/StringBuffer.h" | 48 #include "wtf/text/StringBuffer.h" |
56 #include "wtf/text/StringHash.h" | 49 #include "wtf/text/StringHash.h" |
57 #include "wtf/text/StringUTF8Adaptor.h" | |
58 | 50 |
59 namespace blink { | 51 namespace blink { |
60 | 52 |
61 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V alue> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, Exc eptionState& exceptionState, v8::Isolate* isolate) | |
tasak
2014/11/14 08:07:39
"create" methods are moved to SerializedScriptValu
| |
62 { | |
63 return adoptRef(new SerializedScriptValue(value, messagePorts, arrayBuffers, 0, exceptionState, isolate)); | |
64 } | |
65 | |
66 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createAndSwallowExcepti ons(v8::Isolate* isolate, v8::Handle<v8::Value> value) | |
67 { | |
68 TrackExceptionState exceptionState; | |
69 return adoptRef(new SerializedScriptValue(value, 0, 0, 0, exceptionState, is olate)); | |
70 } | |
71 | |
72 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const ScriptValu e& value, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState, v8::Isolat e* isolate) | |
73 { | |
74 ASSERT(isolate->InContext()); | |
75 return adoptRef(new SerializedScriptValue(value.v8Value(), 0, 0, blobInfo, e xceptionState, isolate)); | |
76 } | |
77 | |
78 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(const St ring& data) | |
79 { | |
80 return adoptRef(new SerializedScriptValue(data)); | |
81 } | |
82 | |
83 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWireBytes(con st Vector<uint8_t>& data) | |
84 { | |
85 // Decode wire data from big endian to host byte order. | |
86 ASSERT(!(data.size() % sizeof(UChar))); | |
87 size_t length = data.size() / sizeof(UChar); | |
88 StringBuffer<UChar> buffer(length); | |
89 const UChar* src = reinterpret_cast<const UChar*>(data.data()); | |
90 UChar* dst = buffer.characters(); | |
91 for (size_t i = 0; i < length; i++) | |
92 dst[i] = ntohs(src[i]); | |
93 | |
94 return createFromWire(String::adopt(buffer)); | |
95 } | |
96 | |
97 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const String& da ta) | |
98 { | |
99 return create(data, v8::Isolate::GetCurrent()); | |
100 } | |
101 | |
102 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const String& da ta, v8::Isolate* isolate) | |
103 { | |
104 SerializedScriptValueInternal::Writer writer; | |
105 writer.writeWebCoreString(data); | |
106 String wireData = writer.takeWireString(); | |
107 return adoptRef(new SerializedScriptValue(wireData)); | |
108 } | |
109 | |
110 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create() | |
111 { | |
112 return adoptRef(new SerializedScriptValue()); | |
113 } | |
114 | |
115 PassRefPtr<SerializedScriptValue> SerializedScriptValue::nullValue() | 53 PassRefPtr<SerializedScriptValue> SerializedScriptValue::nullValue() |
116 { | 54 { |
117 SerializedScriptValueInternal::Writer writer; | 55 SerializedScriptValueInternal::Writer writer; |
118 writer.writeNull(); | 56 writer.writeNull(); |
119 String wireData = writer.takeWireString(); | 57 String wireData = writer.takeWireString(); |
120 return adoptRef(new SerializedScriptValue(wireData)); | 58 return adoptRef(new SerializedScriptValue(wireData)); |
121 } | 59 } |
122 | 60 |
123 // Convert serialized string to big endian wire data. | 61 // Convert serialized string to big endian wire data. |
124 void SerializedScriptValue::toWireBytes(Vector<char>& result) const | 62 void SerializedScriptValue::toWireBytes(Vector<char>& result) const |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 } | 97 } |
160 } else { | 98 } else { |
161 v8::Handle<v8::Object> wrapper = DOMWrapperWorld::current(isolate).domDa taStore().get(object, isolate); | 99 v8::Handle<v8::Object> wrapper = DOMWrapperWorld::current(isolate).domDa taStore().get(object, isolate); |
162 if (!wrapper.IsEmpty()) { | 100 if (!wrapper.IsEmpty()) { |
163 ASSERT(wrapper->IsArrayBuffer()); | 101 ASSERT(wrapper->IsArrayBuffer()); |
164 v8::Handle<v8::ArrayBuffer>::Cast(wrapper)->Neuter(); | 102 v8::Handle<v8::ArrayBuffer>::Cast(wrapper)->Neuter(); |
165 } | 103 } |
166 } | 104 } |
167 } | 105 } |
168 | 106 |
169 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::transferArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Ex ceptionState& exceptionState) | 107 PassOwnPtr<SerializedScriptValue::ArrayBufferContentsArray> SerializedScriptValu e::createArrayBuffers(v8::Isolate* isolate, ArrayBufferArray& arrayBuffers, Exce ptionState& exceptionState) |
170 { | 108 { |
171 ASSERT(arrayBuffers.size()); | 109 ASSERT(arrayBuffers.size()); |
172 | 110 |
173 for (size_t i = 0; i < arrayBuffers.size(); i++) { | 111 for (size_t i = 0; i < arrayBuffers.size(); i++) { |
174 if (arrayBuffers[i]->isNeutered()) { | 112 if (arrayBuffers[i]->isNeutered()) { |
175 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); | 113 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind ex " + String::number(i) + " is already neutered."); |
176 return nullptr; | 114 return nullptr; |
177 } | 115 } |
178 } | 116 } |
179 | 117 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 } | 153 } |
216 switch (status) { | 154 switch (status) { |
217 case SerializedScriptValueInternal::Serializer::InputError: | 155 case SerializedScriptValueInternal::Serializer::InputError: |
218 case SerializedScriptValueInternal::Serializer::DataCloneError: | 156 case SerializedScriptValueInternal::Serializer::DataCloneError: |
219 exceptionState.throwDOMException(DataCloneError, errorMessage); | 157 exceptionState.throwDOMException(DataCloneError, errorMessage); |
220 return; | 158 return; |
221 case SerializedScriptValueInternal::Serializer::Success: | 159 case SerializedScriptValueInternal::Serializer::Success: |
222 m_data = writer.takeWireString(); | 160 m_data = writer.takeWireString(); |
223 ASSERT(m_data.impl()->hasOneRef()); | 161 ASSERT(m_data.impl()->hasOneRef()); |
224 if (arrayBuffers && arrayBuffers->size()) | 162 if (arrayBuffers && arrayBuffers->size()) |
225 m_arrayBufferContentsArray = transferArrayBuffers(isolate, *arrayBuf fers, exceptionState); | 163 transferArrayBuffers(isolate, *arrayBuffers, exceptionState); |
226 return; | 164 return; |
227 case SerializedScriptValueInternal::Serializer::JSException: | 165 case SerializedScriptValueInternal::Serializer::JSException: |
228 ASSERT_NOT_REACHED(); | 166 ASSERT_NOT_REACHED(); |
229 break; | 167 break; |
230 } | 168 } |
231 ASSERT_NOT_REACHED(); | 169 ASSERT_NOT_REACHED(); |
232 } | 170 } |
233 | 171 |
234 SerializedScriptValue::SerializedScriptValue(const String& wireData) | 172 SerializedScriptValue::SerializedScriptValue(const String& wireData) |
235 : m_externallyAllocatedMemory(0) | 173 : m_externallyAllocatedMemory(0) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 { | 263 { |
326 // If the allocated memory was not registered before, then this class is lik ely | 264 // If the allocated memory was not registered before, then this class is lik ely |
327 // used in a context other then Worker's onmessage environment and the prese nce of | 265 // used in a context other then Worker's onmessage environment and the prese nce of |
328 // current v8 context is not guaranteed. Avoid calling v8 then. | 266 // current v8 context is not guaranteed. Avoid calling v8 then. |
329 if (m_externallyAllocatedMemory) { | 267 if (m_externallyAllocatedMemory) { |
330 ASSERT(v8::Isolate::GetCurrent()); | 268 ASSERT(v8::Isolate::GetCurrent()); |
331 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); | 269 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnallyAllocatedMemory); |
332 } | 270 } |
333 } | 271 } |
334 | 272 |
273 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff erArray& arrayBuffers, ExceptionState& exceptionState) | |
274 { | |
275 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep tionState); | |
276 } | |
277 | |
335 } // namespace blink | 278 } // namespace blink |
OLD | NEW |