| 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 21 matching lines...) Expand all Loading... |
| 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/ScriptState.h" |
| 38 #include "bindings/core/v8/ScriptValueSerializer.h" | 38 #include "bindings/core/v8/ScriptValueSerializer.h" |
| 39 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 39 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 40 #include "bindings/core/v8/V8ArrayBuffer.h" | 40 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 41 #include "bindings/core/v8/V8MessagePort.h" | 41 #include "bindings/core/v8/V8MessagePort.h" |
| 42 #include "bindings/core/v8/V8SharedArrayBuffer.h" |
| 42 #include "core/dom/ExceptionCode.h" | 43 #include "core/dom/ExceptionCode.h" |
| 43 #include "platform/SharedBuffer.h" | 44 #include "platform/SharedBuffer.h" |
| 44 #include "platform/blob/BlobData.h" | 45 #include "platform/blob/BlobData.h" |
| 45 #include "platform/heap/Handle.h" | 46 #include "platform/heap/Handle.h" |
| 46 #include "wtf/Assertions.h" | 47 #include "wtf/Assertions.h" |
| 47 #include "wtf/ByteOrder.h" | 48 #include "wtf/ByteOrder.h" |
| 48 #include "wtf/Vector.h" | 49 #include "wtf/Vector.h" |
| 49 #include "wtf/text/StringBuffer.h" | 50 #include "wtf/text/StringBuffer.h" |
| 50 #include "wtf/text/StringHash.h" | 51 #include "wtf/text/StringHash.h" |
| 51 | 52 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 107 |
| 107 for (size_t i = 0; i < arrayBuffers.size(); i++) { | 108 for (size_t i = 0; i < arrayBuffers.size(); i++) { |
| 108 if (arrayBuffers[i]->isNeutered()) { | 109 if (arrayBuffers[i]->isNeutered()) { |
| 109 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind
ex " + String::number(i) + " is already neutered."); | 110 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind
ex " + String::number(i) + " is already neutered."); |
| 110 return nullptr; | 111 return nullptr; |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 OwnPtr<ArrayBufferContentsArray> contents = adoptPtr(new ArrayBufferContents
Array(arrayBuffers.size())); | 115 OwnPtr<ArrayBufferContentsArray> contents = adoptPtr(new ArrayBufferContents
Array(arrayBuffers.size())); |
| 115 | 116 |
| 116 HashSet<DOMArrayBuffer*> visited; | 117 HashSet<DOMArrayBufferBase*> visited; |
| 117 for (size_t i = 0; i < arrayBuffers.size(); i++) { | 118 for (size_t i = 0; i < arrayBuffers.size(); i++) { |
| 118 if (visited.contains(arrayBuffers[i].get())) | 119 if (visited.contains(arrayBuffers[i].get())) |
| 119 continue; | 120 continue; |
| 120 visited.add(arrayBuffers[i].get()); | 121 visited.add(arrayBuffers[i].get()); |
| 121 | 122 |
| 122 Vector<v8::Local<v8::ArrayBuffer>, 4> bufferHandles; | 123 if (arrayBuffers[i]->isShared()) { |
| 123 v8::HandleScope handleScope(isolate); | 124 bool result = arrayBuffers[i]->shareContentsWith(contents->at(i)); |
| 124 acculumateArrayBuffersForAllWorlds(isolate, arrayBuffers[i].get(), buffe
rHandles); | 125 if (!result) { |
| 125 bool isNeuterable = true; | 126 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf
fer at index " + String::number(i) + " could not be transferred."); |
| 126 for (size_t j = 0; j < bufferHandles.size(); j++) | 127 return nullptr; |
| 127 isNeuterable &= bufferHandles[j]->IsNeuterable(); | 128 } |
| 129 } else { |
| 130 Vector<v8::Local<v8::ArrayBuffer>, 4> bufferHandles; |
| 131 v8::HandleScope handleScope(isolate); |
| 132 acculumateArrayBuffersForAllWorlds(isolate, static_pointer_cast<DOMA
rrayBuffer>(arrayBuffers[i]).get(), bufferHandles); |
| 133 bool isNeuterable = true; |
| 134 for (size_t j = 0; j < bufferHandles.size(); j++) |
| 135 isNeuterable &= bufferHandles[j]->IsNeuterable(); |
| 128 | 136 |
| 129 RefPtr<DOMArrayBuffer> toTransfer = arrayBuffers[i]; | 137 RefPtr<DOMArrayBufferBase> toTransfer = arrayBuffers[i]; |
| 130 if (!isNeuterable) | 138 if (!isNeuterable) |
| 131 toTransfer = DOMArrayBuffer::create(arrayBuffers[i]->buffer()); | 139 toTransfer = DOMArrayBuffer::create(arrayBuffers[i]->buffer()); |
| 132 bool result = toTransfer->transfer(contents->at(i)); | 140 bool result = toTransfer->transfer(contents->at(i)); |
| 133 if (!result) { | 141 if (!result) { |
| 134 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at ind
ex " + String::number(i) + " could not be transferred."); | 142 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at
index " + String::number(i) + " could not be transferred."); |
| 135 return nullptr; | 143 return nullptr; |
| 144 } |
| 145 |
| 146 if (isNeuterable) |
| 147 for (size_t j = 0; j < bufferHandles.size(); j++) |
| 148 bufferHandles[j]->Neuter(); |
| 136 } | 149 } |
| 137 | 150 |
| 138 if (isNeuterable) | |
| 139 for (size_t j = 0; j < bufferHandles.size(); j++) | |
| 140 bufferHandles[j]->Neuter(); | |
| 141 } | 151 } |
| 152 |
| 142 return contents.release(); | 153 return contents.release(); |
| 143 } | 154 } |
| 144 | 155 |
| 145 SerializedScriptValue::SerializedScriptValue(const String& wireData) | 156 SerializedScriptValue::SerializedScriptValue(const String& wireData) |
| 146 : m_externallyAllocatedMemory(0) | 157 : m_externallyAllocatedMemory(0) |
| 147 { | 158 { |
| 148 m_data = wireData.isolatedCopy(); | 159 m_data = wireData.isolatedCopy(); |
| 149 } | 160 } |
| 150 | 161 |
| 151 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag
ePorts) | 162 v8::Local<v8::Value> SerializedScriptValue::deserialize(MessagePortArray* messag
ePorts) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 return false; | 208 return false; |
| 198 } | 209 } |
| 199 ports.append(port); | 210 ports.append(port); |
| 200 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) { | 211 } else if (V8ArrayBuffer::hasInstance(transferrable, isolate)) { |
| 201 RefPtr<DOMArrayBuffer> arrayBuffer = V8ArrayBuffer::toImpl(v8::Local
<v8::Object>::Cast(transferrable)); | 212 RefPtr<DOMArrayBuffer> arrayBuffer = V8ArrayBuffer::toImpl(v8::Local
<v8::Object>::Cast(transferrable)); |
| 202 if (arrayBuffers.contains(arrayBuffer)) { | 213 if (arrayBuffers.contains(arrayBuffer)) { |
| 203 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at
index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer."); | 214 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at
index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer."); |
| 204 return false; | 215 return false; |
| 205 } | 216 } |
| 206 arrayBuffers.append(arrayBuffer.release()); | 217 arrayBuffers.append(arrayBuffer.release()); |
| 218 } else if (V8SharedArrayBuffer::hasInstance(transferrable, isolate)) { |
| 219 RefPtr<DOMSharedArrayBuffer> sharedArrayBuffer = V8SharedArrayBuffer
::toImpl(v8::Local<v8::Object>::Cast(transferrable)); |
| 220 if (arrayBuffers.contains(sharedArrayBuffer)) { |
| 221 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf
fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB
uffer."); |
| 222 return false; |
| 223 } |
| 224 arrayBuffers.append(sharedArrayBuffer.release()); |
| 207 } else { | 225 } else { |
| 208 exceptionState.throwTypeError("Value at index " + String::number(i)
+ " does not have a transferable type."); | 226 exceptionState.throwTypeError("Value at index " + String::number(i)
+ " does not have a transferable type."); |
| 209 return false; | 227 return false; |
| 210 } | 228 } |
| 211 } | 229 } |
| 212 return true; | 230 return true; |
| 213 } | 231 } |
| 214 | 232 |
| 215 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() | 233 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() |
| 216 { | 234 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 230 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 248 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
| 231 } | 249 } |
| 232 } | 250 } |
| 233 | 251 |
| 234 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff
erArray& arrayBuffers, ExceptionState& exceptionState) | 252 void SerializedScriptValue::transferArrayBuffers(v8::Isolate* isolate, ArrayBuff
erArray& arrayBuffers, ExceptionState& exceptionState) |
| 235 { | 253 { |
| 236 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep
tionState); | 254 m_arrayBufferContentsArray = createArrayBuffers(isolate, arrayBuffers, excep
tionState); |
| 237 } | 255 } |
| 238 | 256 |
| 239 } // namespace blink | 257 } // namespace blink |
| OLD | NEW |