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" |
40 #include "core/dom/DOMArrayBuffer.h" | 44 #include "core/dom/DOMArrayBuffer.h" |
41 #include "core/dom/DOMSharedArrayBuffer.h" | 45 #include "core/dom/DOMSharedArrayBuffer.h" |
42 #include "core/dom/ExceptionCode.h" | 46 #include "core/dom/ExceptionCode.h" |
43 #include "core/dom/MessagePort.h" | 47 #include "core/dom/MessagePort.h" |
44 #include "core/frame/ImageBitmap.h" | 48 #include "core/frame/ImageBitmap.h" |
45 #include "platform/SharedBuffer.h" | 49 #include "platform/SharedBuffer.h" |
46 #include "platform/blob/BlobData.h" | 50 #include "platform/blob/BlobData.h" |
47 #include "platform/heap/Handle.h" | 51 #include "platform/heap/Handle.h" |
48 #include "wtf/Assertions.h" | 52 #include "wtf/Assertions.h" |
49 #include "wtf/ByteOrder.h" | 53 #include "wtf/ByteOrder.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Validate the passed array of transferables. | 229 // Validate the passed array of transferables. |
226 for (unsigned i = 0; i < length; ++i) { | 230 for (unsigned i = 0; i < length; ++i) { |
227 v8::Local<v8::Value> transferableObject; | 231 v8::Local<v8::Value> transferableObject; |
228 if (!transferableArray->Get(isolate->GetCurrentContext(), i).ToLocal(&tr
ansferableObject)) | 232 if (!transferableArray->Get(isolate->GetCurrentContext(), i).ToLocal(&tr
ansferableObject)) |
229 return false; | 233 return false; |
230 // Validation of non-null objects, per HTML5 spec 10.3.3. | 234 // Validation of non-null objects, per HTML5 spec 10.3.3. |
231 if (isUndefinedOrNull(transferableObject)) { | 235 if (isUndefinedOrNull(transferableObject)) { |
232 exceptionState.throwTypeError("Value at index " + String::number(i)
+ " is an untransferable " + (transferableObject->IsUndefined() ? "'undefined'"
: "'null'") + " value."); | 236 exceptionState.throwTypeError("Value at index " + String::number(i)
+ " is an untransferable " + (transferableObject->IsUndefined() ? "'undefined'"
: "'null'") + " value."); |
233 return false; | 237 return false; |
234 } | 238 } |
235 if (!SerializedScriptValueFactory::instance().extractTransferables(isola
te, transferables, exceptionState, transferableObject, i)) { | 239 // Validation of Objects implementing an interface, per WebIDL spec 4.1.
15. |
236 if (!exceptionState.hadException()) | 240 if (V8MessagePort::hasInstance(transferableObject, isolate)) { |
237 exceptionState.throwTypeError("Value at index " + String::number
(i) + " does not have a transferable type."); | 241 MessagePort* port = V8MessagePort::toImpl(v8::Local<v8::Object>::Cas
t(transferableObject)); |
| 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."); |
238 return false; | 271 return false; |
239 } | 272 } |
240 } | 273 } |
241 return true; | 274 return true; |
242 } | 275 } |
243 | 276 |
244 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() | 277 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() |
245 { | 278 { |
246 if (m_externallyAllocatedMemory) | 279 if (m_externallyAllocatedMemory) |
247 return; | 280 return; |
248 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); | 281 m_externallyAllocatedMemory = static_cast<intptr_t>(m_data.length()); |
249 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall
yAllocatedMemory); | 282 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(m_externall
yAllocatedMemory); |
250 } | 283 } |
251 | 284 |
252 bool SerializedScriptValue::containsTransferableArrayBuffer() const | 285 bool SerializedScriptValue::containsTransferableArrayBuffer() const |
253 { | 286 { |
254 return m_arrayBufferContentsArray && !m_arrayBufferContentsArray->isEmpty(); | 287 return m_arrayBufferContentsArray && !m_arrayBufferContentsArray->isEmpty(); |
255 } | 288 } |
256 | 289 |
257 } // namespace blink | 290 } // namespace blink |
OLD | NEW |