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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "platform/blob/BlobData.h" | 51 #include "platform/blob/BlobData.h" |
52 #include "platform/heap/Handle.h" | 52 #include "platform/heap/Handle.h" |
53 #include "wtf/Assertions.h" | 53 #include "wtf/Assertions.h" |
54 #include "wtf/ByteOrder.h" | 54 #include "wtf/ByteOrder.h" |
55 #include "wtf/Vector.h" | 55 #include "wtf/Vector.h" |
56 #include "wtf/text/StringBuffer.h" | 56 #include "wtf/text/StringBuffer.h" |
57 #include "wtf/text/StringHash.h" | 57 #include "wtf/text/StringHash.h" |
58 | 58 |
59 namespace blink { | 59 namespace blink { |
60 | 60 |
| 61 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create() |
| 62 { |
| 63 return adoptRef(new SerializedScriptValue); |
| 64 } |
| 65 |
| 66 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const String& da
ta) |
| 67 { |
| 68 return adoptRef(new SerializedScriptValue(data)); |
| 69 } |
| 70 |
| 71 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(const char* data
, size_t length) |
| 72 { |
| 73 if (!data) |
| 74 return create(); |
| 75 |
| 76 // Decode wire data from big endian to host byte order. |
| 77 DCHECK(!(length % sizeof(UChar))); |
| 78 size_t stringLength = length / sizeof(UChar); |
| 79 StringBuffer<UChar> buffer(stringLength); |
| 80 const UChar* src = reinterpret_cast<const UChar*>(data); |
| 81 UChar* dst = buffer.characters(); |
| 82 for (size_t i = 0; i < stringLength; i++) |
| 83 dst[i] = ntohs(src[i]); |
| 84 |
| 85 return adoptRef(new SerializedScriptValue(String::adopt(buffer))); |
| 86 } |
| 87 |
61 SerializedScriptValue::SerializedScriptValue() | 88 SerializedScriptValue::SerializedScriptValue() |
62 : m_externallyAllocatedMemory(0) | 89 : m_externallyAllocatedMemory(0) |
63 { | 90 { |
64 } | 91 } |
65 | 92 |
| 93 SerializedScriptValue::SerializedScriptValue(const String& wireData) |
| 94 : m_data(wireData.isolatedCopy()) |
| 95 , m_externallyAllocatedMemory(0) |
| 96 { |
| 97 } |
| 98 |
66 SerializedScriptValue::~SerializedScriptValue() | 99 SerializedScriptValue::~SerializedScriptValue() |
67 { | 100 { |
68 // If the allocated memory was not registered before, then this class is lik
ely | 101 // If the allocated memory was not registered before, then this class is lik
ely |
69 // used in a context other than Worker's onmessage environment and the prese
nce of | 102 // used in a context other than Worker's onmessage environment and the prese
nce of |
70 // current v8 context is not guaranteed. Avoid calling v8 then. | 103 // current v8 context is not guaranteed. Avoid calling v8 then. |
71 if (m_externallyAllocatedMemory) { | 104 if (m_externallyAllocatedMemory) { |
72 ASSERT(v8::Isolate::GetCurrent()); | 105 ASSERT(v8::Isolate::GetCurrent()); |
73 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 106 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
74 } | 107 } |
75 } | 108 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 241 |
209 if (isNeuterable) | 242 if (isNeuterable) |
210 for (size_t j = 0; j < bufferHandles.size(); ++j) | 243 for (size_t j = 0; j < bufferHandles.size(); ++j) |
211 bufferHandles[j]->Neuter(); | 244 bufferHandles[j]->Neuter(); |
212 } | 245 } |
213 | 246 |
214 } | 247 } |
215 m_arrayBufferContentsArray = std::move(contents); | 248 m_arrayBufferContentsArray = std::move(contents); |
216 } | 249 } |
217 | 250 |
218 SerializedScriptValue::SerializedScriptValue(const String& wireData) | |
219 : m_externallyAllocatedMemory(0) | |
220 { | |
221 m_data = wireData.isolatedCopy(); | |
222 } | |
223 | |
224 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag
ePorts) | 251 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag
ePorts) |
225 { | 252 { |
226 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); | 253 return deserialize(v8::Isolate::GetCurrent(), messagePorts, 0); |
227 } | 254 } |
228 | 255 |
229 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me
ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) | 256 v8::Local<v8::Value> SerializedScriptValue::deserialize(v8::Isolate* isolate, Me
ssagePortArray* messagePorts, const WebBlobInfoArray* blobInfo) |
230 { | 257 { |
231 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m
essagePorts, blobInfo); | 258 return SerializedScriptValueFactory::instance().deserialize(this, isolate, m
essagePorts, blobInfo); |
232 } | 259 } |
233 | 260 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); | 337 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); |
311 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall
yAllocatedMemory); | 338 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall
yAllocatedMemory); |
312 } | 339 } |
313 | 340 |
314 bool SerializedScriptValue::containsTransferableArrayBuffer() const | 341 bool SerializedScriptValue::containsTransferableArrayBuffer() const |
315 { | 342 { |
316 return m_arrayBufferContentsArray && !m_arrayBufferContentsArray->isEmpty(); | 343 return m_arrayBufferContentsArray && !m_arrayBufferContentsArray->isEmpty(); |
317 } | 344 } |
318 | 345 |
319 } // namespace blink | 346 } // namespace blink |
OLD | NEW |