| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 v8::Isolate* isolate, | 191 v8::Isolate* isolate, |
| 192 DOMArrayBuffer* object, | 192 DOMArrayBuffer* object, |
| 193 Vector<v8::Local<v8::ArrayBuffer>, 4>& buffers) { | 193 Vector<v8::Local<v8::ArrayBuffer>, 4>& buffers) { |
| 194 if (isMainThread()) { | 194 if (isMainThread()) { |
| 195 Vector<RefPtr<DOMWrapperWorld>> worlds; | 195 Vector<RefPtr<DOMWrapperWorld>> worlds; |
| 196 DOMWrapperWorld::allWorldsInMainThread(worlds); | 196 DOMWrapperWorld::allWorldsInMainThread(worlds); |
| 197 for (size_t i = 0; i < worlds.size(); i++) { | 197 for (size_t i = 0; i < worlds.size(); i++) { |
| 198 v8::Local<v8::Object> wrapper = | 198 v8::Local<v8::Object> wrapper = |
| 199 worlds[i]->domDataStore().get(object, isolate); | 199 worlds[i]->domDataStore().get(object, isolate); |
| 200 if (!wrapper.IsEmpty()) | 200 if (!wrapper.IsEmpty()) |
| 201 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); | 201 buffers.push_back(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); |
| 202 } | 202 } |
| 203 } else { | 203 } else { |
| 204 v8::Local<v8::Object> wrapper = | 204 v8::Local<v8::Object> wrapper = |
| 205 DOMWrapperWorld::current(isolate).domDataStore().get(object, isolate); | 205 DOMWrapperWorld::current(isolate).domDataStore().get(object, isolate); |
| 206 if (!wrapper.IsEmpty()) | 206 if (!wrapper.IsEmpty()) |
| 207 buffers.append(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); | 207 buffers.push_back(v8::Local<v8::ArrayBuffer>::Cast(wrapper)); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 std::unique_ptr<ImageBitmapContentsArray> | 211 std::unique_ptr<ImageBitmapContentsArray> |
| 212 SerializedScriptValue::transferImageBitmapContents( | 212 SerializedScriptValue::transferImageBitmapContents( |
| 213 v8::Isolate* isolate, | 213 v8::Isolate* isolate, |
| 214 const ImageBitmapArray& imageBitmaps, | 214 const ImageBitmapArray& imageBitmaps, |
| 215 ExceptionState& exceptionState) { | 215 ExceptionState& exceptionState) { |
| 216 if (!imageBitmaps.size()) | 216 if (!imageBitmaps.size()) |
| 217 return nullptr; | 217 return nullptr; |
| 218 | 218 |
| 219 for (size_t i = 0; i < imageBitmaps.size(); ++i) { | 219 for (size_t i = 0; i < imageBitmaps.size(); ++i) { |
| 220 if (imageBitmaps[i]->isNeutered()) { | 220 if (imageBitmaps[i]->isNeutered()) { |
| 221 exceptionState.throwDOMException( | 221 exceptionState.throwDOMException( |
| 222 DataCloneError, "ImageBitmap at index " + String::number(i) + | 222 DataCloneError, "ImageBitmap at index " + String::number(i) + |
| 223 " is already detached."); | 223 " is already detached."); |
| 224 return nullptr; | 224 return nullptr; |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 std::unique_ptr<ImageBitmapContentsArray> contents = | 228 std::unique_ptr<ImageBitmapContentsArray> contents = |
| 229 wrapUnique(new ImageBitmapContentsArray); | 229 wrapUnique(new ImageBitmapContentsArray); |
| 230 HeapHashSet<Member<ImageBitmap>> visited; | 230 HeapHashSet<Member<ImageBitmap>> visited; |
| 231 for (size_t i = 0; i < imageBitmaps.size(); ++i) { | 231 for (size_t i = 0; i < imageBitmaps.size(); ++i) { |
| 232 if (visited.contains(imageBitmaps[i])) | 232 if (visited.contains(imageBitmaps[i])) |
| 233 continue; | 233 continue; |
| 234 visited.add(imageBitmaps[i]); | 234 visited.add(imageBitmaps[i]); |
| 235 contents->append(imageBitmaps[i]->transfer()); | 235 contents->push_back(imageBitmaps[i]->transfer()); |
| 236 } | 236 } |
| 237 return contents; | 237 return contents; |
| 238 } | 238 } |
| 239 | 239 |
| 240 void SerializedScriptValue::transferImageBitmaps( | 240 void SerializedScriptValue::transferImageBitmaps( |
| 241 v8::Isolate* isolate, | 241 v8::Isolate* isolate, |
| 242 const ImageBitmapArray& imageBitmaps, | 242 const ImageBitmapArray& imageBitmaps, |
| 243 ExceptionState& exceptionState) { | 243 ExceptionState& exceptionState) { |
| 244 std::unique_ptr<ImageBitmapContentsArray> contents = | 244 std::unique_ptr<ImageBitmapContentsArray> contents = |
| 245 transferImageBitmapContents(isolate, imageBitmaps, exceptionState); | 245 transferImageBitmapContents(isolate, imageBitmaps, exceptionState); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 if (V8MessagePort::hasInstance(transferableObject, isolate)) { | 335 if (V8MessagePort::hasInstance(transferableObject, isolate)) { |
| 336 MessagePort* port = V8MessagePort::toImpl( | 336 MessagePort* port = V8MessagePort::toImpl( |
| 337 v8::Local<v8::Object>::Cast(transferableObject)); | 337 v8::Local<v8::Object>::Cast(transferableObject)); |
| 338 // Check for duplicate MessagePorts. | 338 // Check for duplicate MessagePorts. |
| 339 if (transferables.messagePorts.contains(port)) { | 339 if (transferables.messagePorts.contains(port)) { |
| 340 exceptionState.throwDOMException( | 340 exceptionState.throwDOMException( |
| 341 DataCloneError, "Message port at index " + String::number(i) + | 341 DataCloneError, "Message port at index " + String::number(i) + |
| 342 " is a duplicate of an earlier port."); | 342 " is a duplicate of an earlier port."); |
| 343 return false; | 343 return false; |
| 344 } | 344 } |
| 345 transferables.messagePorts.append(port); | 345 transferables.messagePorts.push_back(port); |
| 346 } else if (transferableObject->IsArrayBuffer()) { | 346 } else if (transferableObject->IsArrayBuffer()) { |
| 347 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl( | 347 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl( |
| 348 v8::Local<v8::Object>::Cast(transferableObject)); | 348 v8::Local<v8::Object>::Cast(transferableObject)); |
| 349 if (transferables.arrayBuffers.contains(arrayBuffer)) { | 349 if (transferables.arrayBuffers.contains(arrayBuffer)) { |
| 350 exceptionState.throwDOMException( | 350 exceptionState.throwDOMException( |
| 351 DataCloneError, "ArrayBuffer at index " + String::number(i) + | 351 DataCloneError, "ArrayBuffer at index " + String::number(i) + |
| 352 " is a duplicate of an earlier ArrayBuffer."); | 352 " is a duplicate of an earlier ArrayBuffer."); |
| 353 return false; | 353 return false; |
| 354 } | 354 } |
| 355 transferables.arrayBuffers.append(arrayBuffer); | 355 transferables.arrayBuffers.push_back(arrayBuffer); |
| 356 } else if (transferableObject->IsSharedArrayBuffer()) { | 356 } else if (transferableObject->IsSharedArrayBuffer()) { |
| 357 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImpl( | 357 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImpl( |
| 358 v8::Local<v8::Object>::Cast(transferableObject)); | 358 v8::Local<v8::Object>::Cast(transferableObject)); |
| 359 if (transferables.arrayBuffers.contains(sharedArrayBuffer)) { | 359 if (transferables.arrayBuffers.contains(sharedArrayBuffer)) { |
| 360 exceptionState.throwDOMException( | 360 exceptionState.throwDOMException( |
| 361 DataCloneError, | 361 DataCloneError, |
| 362 "SharedArrayBuffer at index " + String::number(i) + | 362 "SharedArrayBuffer at index " + String::number(i) + |
| 363 " is a duplicate of an earlier SharedArrayBuffer."); | 363 " is a duplicate of an earlier SharedArrayBuffer."); |
| 364 return false; | 364 return false; |
| 365 } | 365 } |
| 366 transferables.arrayBuffers.append(sharedArrayBuffer); | 366 transferables.arrayBuffers.push_back(sharedArrayBuffer); |
| 367 } else if (V8ImageBitmap::hasInstance(transferableObject, isolate)) { | 367 } else if (V8ImageBitmap::hasInstance(transferableObject, isolate)) { |
| 368 ImageBitmap* imageBitmap = V8ImageBitmap::toImpl( | 368 ImageBitmap* imageBitmap = V8ImageBitmap::toImpl( |
| 369 v8::Local<v8::Object>::Cast(transferableObject)); | 369 v8::Local<v8::Object>::Cast(transferableObject)); |
| 370 if (transferables.imageBitmaps.contains(imageBitmap)) { | 370 if (transferables.imageBitmaps.contains(imageBitmap)) { |
| 371 exceptionState.throwDOMException( | 371 exceptionState.throwDOMException( |
| 372 DataCloneError, "ImageBitmap at index " + String::number(i) + | 372 DataCloneError, "ImageBitmap at index " + String::number(i) + |
| 373 " is a duplicate of an earlier ImageBitmap."); | 373 " is a duplicate of an earlier ImageBitmap."); |
| 374 return false; | 374 return false; |
| 375 } | 375 } |
| 376 transferables.imageBitmaps.append(imageBitmap); | 376 transferables.imageBitmaps.push_back(imageBitmap); |
| 377 } else if (V8OffscreenCanvas::hasInstance(transferableObject, isolate)) { | 377 } else if (V8OffscreenCanvas::hasInstance(transferableObject, isolate)) { |
| 378 OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl( | 378 OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl( |
| 379 v8::Local<v8::Object>::Cast(transferableObject)); | 379 v8::Local<v8::Object>::Cast(transferableObject)); |
| 380 if (transferables.offscreenCanvases.contains(offscreenCanvas)) { | 380 if (transferables.offscreenCanvases.contains(offscreenCanvas)) { |
| 381 exceptionState.throwDOMException( | 381 exceptionState.throwDOMException( |
| 382 DataCloneError, | 382 DataCloneError, |
| 383 "OffscreenCanvas at index " + String::number(i) + | 383 "OffscreenCanvas at index " + String::number(i) + |
| 384 " is a duplicate of an earlier OffscreenCanvas."); | 384 " is a duplicate of an earlier OffscreenCanvas."); |
| 385 return false; | 385 return false; |
| 386 } | 386 } |
| 387 transferables.offscreenCanvases.append(offscreenCanvas); | 387 transferables.offscreenCanvases.push_back(offscreenCanvas); |
| 388 } else { | 388 } else { |
| 389 exceptionState.throwTypeError("Value at index " + String::number(i) + | 389 exceptionState.throwTypeError("Value at index " + String::number(i) + |
| 390 " does not have a transferable type."); | 390 " does not have a transferable type."); |
| 391 return false; | 391 return false; |
| 392 } | 392 } |
| 393 } | 393 } |
| 394 return true; | 394 return true; |
| 395 } | 395 } |
| 396 | 396 |
| 397 std::unique_ptr<ArrayBufferContentsArray> | 397 std::unique_ptr<ArrayBufferContentsArray> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() { | 465 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() { |
| 466 if (m_externallyAllocatedMemory) | 466 if (m_externallyAllocatedMemory) |
| 467 return; | 467 return; |
| 468 | 468 |
| 469 m_externallyAllocatedMemory = static_cast<intptr_t>(dataLengthInBytes()); | 469 m_externallyAllocatedMemory = static_cast<intptr_t>(dataLengthInBytes()); |
| 470 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 470 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
| 471 m_externallyAllocatedMemory); | 471 m_externallyAllocatedMemory); |
| 472 } | 472 } |
| 473 | 473 |
| 474 } // namespace blink | 474 } // namespace blink |
| OLD | NEW |