| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (exceptionState.hadException()) | 78 if (exceptionState.hadException()) |
| 79 return nullValue(); | 79 return nullValue(); |
| 80 return serialized.release(); | 80 return serialized.release(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create() { | 83 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create() { |
| 84 return adoptRef(new SerializedScriptValue); | 84 return adoptRef(new SerializedScriptValue); |
| 85 } | 85 } |
| 86 | 86 |
| 87 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create( | 87 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create( |
| 88 LongStringPolicy longStringPolicy) { |
| 89 return adoptRef(new SerializedScriptValue(longStringPolicy)); |
| 90 } |
| 91 |
| 92 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create( |
| 88 const String& data) { | 93 const String& data) { |
| 89 return adoptRef(new SerializedScriptValue(data)); | 94 return adoptRef(new SerializedScriptValue(data)); |
| 90 } | 95 } |
| 91 | 96 |
| 92 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create( | 97 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create( |
| 93 const char* data, | 98 const char* data, |
| 94 size_t length) { | 99 size_t length) { |
| 95 if (!data) | 100 if (!data) |
| 96 return create(); | 101 return create(); |
| 97 | 102 |
| 98 // Decode wire data from big endian to host byte order. | 103 // Decode wire data from big endian to host byte order. |
| 99 DCHECK(!(length % sizeof(UChar))); | 104 DCHECK(!(length % sizeof(UChar))); |
| 100 size_t stringLength = length / sizeof(UChar); | 105 size_t stringLength = length / sizeof(UChar); |
| 101 StringBuffer<UChar> buffer(stringLength); | 106 StringBuffer<UChar> buffer(stringLength); |
| 102 const UChar* src = reinterpret_cast<const UChar*>(data); | 107 const UChar* src = reinterpret_cast<const UChar*>(data); |
| 103 UChar* dst = buffer.characters(); | 108 UChar* dst = buffer.characters(); |
| 104 for (size_t i = 0; i < stringLength; i++) | 109 for (size_t i = 0; i < stringLength; i++) |
| 105 dst[i] = ntohs(src[i]); | 110 dst[i] = ntohs(src[i]); |
| 106 | 111 |
| 107 return adoptRef(new SerializedScriptValue(String::adopt(buffer))); | 112 return adoptRef(new SerializedScriptValue(String::adopt(buffer))); |
| 108 } | 113 } |
| 109 | 114 |
| 110 SerializedScriptValue::SerializedScriptValue() | 115 SerializedScriptValue::SerializedScriptValue() |
| 111 : m_hasRegisteredExternalAllocation(false), | 116 : m_hasRegisteredExternalAllocation(false), |
| 112 m_transferablesNeedExternalAllocationRegistration(false) {} | 117 m_transferablesNeedExternalAllocationRegistration(false) {} |
| 113 | 118 |
| 119 SerializedScriptValue::SerializedScriptValue(LongStringPolicy longStringPolicy) |
| 120 : m_longStrings(longStringPolicy), |
| 121 m_hasRegisteredExternalAllocation(false), |
| 122 m_transferablesNeedExternalAllocationRegistration(false) {} |
| 123 |
| 114 SerializedScriptValue::SerializedScriptValue(const String& wireData) | 124 SerializedScriptValue::SerializedScriptValue(const String& wireData) |
| 115 : m_hasRegisteredExternalAllocation(false), | 125 : m_hasRegisteredExternalAllocation(false), |
| 116 m_transferablesNeedExternalAllocationRegistration(false) { | 126 m_transferablesNeedExternalAllocationRegistration(false) { |
| 117 size_t byteLength = wireData.length() * 2; | 127 size_t byteLength = wireData.length() * 2; |
| 118 m_dataBuffer.reset(static_cast<uint8_t*>(WTF::Partitions::bufferMalloc( | 128 m_dataBuffer.reset(static_cast<uint8_t*>(WTF::Partitions::bufferMalloc( |
| 119 byteLength, "SerializedScriptValue buffer"))); | 129 byteLength, "SerializedScriptValue buffer"))); |
| 120 m_dataBufferSize = byteLength; | 130 m_dataBufferSize = byteLength; |
| 121 wireData.copyTo(reinterpret_cast<UChar*>(m_dataBuffer.get()), 0, | 131 wireData.copyTo(reinterpret_cast<UChar*>(m_dataBuffer.get()), 0, |
| 122 wireData.length()); | 132 wireData.length()); |
| 123 } | 133 } |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 // Only (re)register allocation cost for transferables if this | 471 // Only (re)register allocation cost for transferables if this |
| 462 // SerializedScriptValue has explicitly unregistered them before. | 472 // SerializedScriptValue has explicitly unregistered them before. |
| 463 if (m_arrayBufferContentsArray && | 473 if (m_arrayBufferContentsArray && |
| 464 m_transferablesNeedExternalAllocationRegistration) { | 474 m_transferablesNeedExternalAllocationRegistration) { |
| 465 for (auto& buffer : *m_arrayBufferContentsArray) | 475 for (auto& buffer : *m_arrayBufferContentsArray) |
| 466 buffer.registerExternalAllocationWithCurrentContext(); | 476 buffer.registerExternalAllocationWithCurrentContext(); |
| 467 } | 477 } |
| 468 } | 478 } |
| 469 | 479 |
| 470 } // namespace blink | 480 } // namespace blink |
| OLD | NEW |