| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "bindings/core/v8/SerializedScriptValue.h" | 31 #include "bindings/core/v8/SerializedScriptValue.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/DOMDataStore.h" | 33 #include "bindings/core/v8/DOMDataStore.h" |
| 34 #include "bindings/core/v8/DOMWrapperWorld.h" | 34 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 35 #include "bindings/core/v8/ExceptionState.h" | 35 #include "bindings/core/v8/ExceptionState.h" |
| 36 #include "bindings/core/v8/ScriptState.h" | 36 #include "bindings/core/v8/ScriptState.h" |
| 37 #include "bindings/core/v8/ScriptValueSerializer.h" | 37 #include "bindings/core/v8/ScriptValueSerializer.h" |
| 38 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 38 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 39 #include "bindings/core/v8/Transferables.h" | 39 #include "bindings/core/v8/Transferables.h" |
| 40 #include "bindings/core/v8/V8ArrayBuffer.h" | |
| 41 #include "bindings/core/v8/V8ImageBitmap.h" | |
| 42 #include "bindings/core/v8/V8MessagePort.h" | |
| 43 #include "bindings/core/v8/V8SharedArrayBuffer.h" | |
| 44 #include "core/dom/DOMArrayBuffer.h" | 40 #include "core/dom/DOMArrayBuffer.h" |
| 45 #include "core/dom/DOMSharedArrayBuffer.h" | 41 #include "core/dom/DOMSharedArrayBuffer.h" |
| 46 #include "core/dom/ExceptionCode.h" | 42 #include "core/dom/ExceptionCode.h" |
| 47 #include "core/dom/MessagePort.h" | 43 #include "core/dom/MessagePort.h" |
| 48 #include "core/frame/ImageBitmap.h" | 44 #include "core/frame/ImageBitmap.h" |
| 49 #include "platform/SharedBuffer.h" | 45 #include "platform/SharedBuffer.h" |
| 50 #include "platform/blob/BlobData.h" | 46 #include "platform/blob/BlobData.h" |
| 51 #include "platform/heap/Handle.h" | 47 #include "platform/heap/Handle.h" |
| 52 #include "wtf/Assertions.h" | 48 #include "wtf/Assertions.h" |
| 53 #include "wtf/ByteOrder.h" | 49 #include "wtf/ByteOrder.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // Validate the passed array of transferables. | 225 // Validate the passed array of transferables. |
| 230 for (unsigned i = 0; i < length; ++i) { | 226 for (unsigned i = 0; i < length; ++i) { |
| 231 v8::Local<v8::Value> transferableObject; | 227 v8::Local<v8::Value> transferableObject; |
| 232 if (!transferableArray->Get(isolate->GetCurrentContext(), i).ToLocal(&tr
ansferableObject)) | 228 if (!transferableArray->Get(isolate->GetCurrentContext(), i).ToLocal(&tr
ansferableObject)) |
| 233 return false; | 229 return false; |
| 234 // Validation of non-null objects, per HTML5 spec 10.3.3. | 230 // Validation of non-null objects, per HTML5 spec 10.3.3. |
| 235 if (isUndefinedOrNull(transferableObject)) { | 231 if (isUndefinedOrNull(transferableObject)) { |
| 236 exceptionState.throwTypeError("Value at index " + String::number(i)
+ " is an untransferable " + (transferableObject->IsUndefined() ? "'undefined'"
: "'null'") + " value."); | 232 exceptionState.throwTypeError("Value at index " + String::number(i)
+ " is an untransferable " + (transferableObject->IsUndefined() ? "'undefined'"
: "'null'") + " value."); |
| 237 return false; | 233 return false; |
| 238 } | 234 } |
| 239 // Validation of Objects implementing an interface, per WebIDL spec 4.1.
15. | 235 if (!SerializedScriptValueFactory::instance().extractTransferables(isola
te, transferables, exceptionState, transferableObject, i)) { |
| 240 if (V8MessagePort::hasInstance(transferableObject, isolate)) { | 236 if (!exceptionState.hadException()) |
| 241 MessagePort* port = V8MessagePort::toImpl(v8::Local<v8::Object>::Cas
t(transferableObject)); | 237 exceptionState.throwTypeError("Value at index " + String::number
(i) + " does not have a transferable type."); |
| 242 // Check for duplicate MessagePorts. | |
| 243 if (transferables.messagePorts.contains(port)) { | |
| 244 exceptionState.throwDOMException(DataCloneError, "Message port a
t index " + String::number(i) + " is a duplicate of an earlier port."); | |
| 245 return false; | |
| 246 } | |
| 247 transferables.messagePorts.append(port); | |
| 248 } else if (V8ArrayBuffer::hasInstance(transferableObject, isolate)) { | |
| 249 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl(v8::Local<v8::Ob
ject>::Cast(transferableObject)); | |
| 250 if (transferables.arrayBuffers.contains(arrayBuffer)) { | |
| 251 exceptionState.throwDOMException(DataCloneError, "ArrayBuffer at
index " + String::number(i) + " is a duplicate of an earlier ArrayBuffer."); | |
| 252 return false; | |
| 253 } | |
| 254 transferables.arrayBuffers.append(arrayBuffer); | |
| 255 } else if (V8SharedArrayBuffer::hasInstance(transferableObject, isolate)
) { | |
| 256 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImp
l(v8::Local<v8::Object>::Cast(transferableObject)); | |
| 257 if (transferables.arrayBuffers.contains(sharedArrayBuffer)) { | |
| 258 exceptionState.throwDOMException(DataCloneError, "SharedArrayBuf
fer at index " + String::number(i) + " is a duplicate of an earlier SharedArrayB
uffer."); | |
| 259 return false; | |
| 260 } | |
| 261 transferables.arrayBuffers.append(sharedArrayBuffer); | |
| 262 } else if (V8ImageBitmap::hasInstance(transferableObject, isolate)) { | |
| 263 ImageBitmap* imageBitmap = V8ImageBitmap::toImpl(v8::Local<v8::Objec
t>::Cast(transferableObject)); | |
| 264 if (transferables.imageBitmaps.contains(imageBitmap)) { | |
| 265 exceptionState.throwDOMException(DataCloneError, "ImageBitmap at
index " + String::number(i) + " is a duplicate of an earlier ImageBitmap."); | |
| 266 return false; | |
| 267 } | |
| 268 transferables.imageBitmaps.append(imageBitmap); | |
| 269 } else { | |
| 270 exceptionState.throwTypeError("Value at index " + String::number(i)
+ " does not have a transferable type."); | |
| 271 return false; | 238 return false; |
| 272 } | 239 } |
| 273 } | 240 } |
| 274 return true; | 241 return true; |
| 275 } | 242 } |
| 276 | 243 |
| 277 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() | 244 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() |
| 278 { | 245 { |
| 279 if (m_externallyAllocatedMemory) | 246 if (m_externallyAllocatedMemory) |
| 280 return; | 247 return; |
| 281 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); | 248 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); |
| 282 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall
yAllocatedMemory); | 249 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall
yAllocatedMemory); |
| 283 } | 250 } |
| 284 | 251 |
| 285 bool SerializedScriptValue::containsTransferableArrayBuffer() const | 252 bool SerializedScriptValue::containsTransferableArrayBuffer() const |
| 286 { | 253 { |
| 287 return m_arrayBufferContentsArray && !m_arrayBufferContentsArray->isEmpty(); | 254 return m_arrayBufferContentsArray && !m_arrayBufferContentsArray->isEmpty(); |
| 288 } | 255 } |
| 289 | 256 |
| 290 } // namespace blink | 257 } // namespace blink |
| OLD | NEW |