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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 std::unique_ptr<SerializedScriptValue::ImageBitmapContentsArray> | 207 std::unique_ptr<SerializedScriptValue::ImageBitmapContentsArray> |
208 SerializedScriptValue::transferImageBitmapContents( | 208 SerializedScriptValue::transferImageBitmapContents( |
209 v8::Isolate* isolate, | 209 v8::Isolate* isolate, |
210 const ImageBitmapArray& imageBitmaps, | 210 const ImageBitmapArray& imageBitmaps, |
211 ExceptionState& exceptionState) { | 211 ExceptionState& exceptionState) { |
212 if (!imageBitmaps.size()) | 212 if (!imageBitmaps.size()) |
213 return nullptr; | 213 return nullptr; |
214 | 214 |
215 for (size_t i = 0; i < imageBitmaps.size(); ++i) { | 215 for (size_t i = 0; i < imageBitmaps.size(); ++i) { |
216 if (imageBitmaps[i]->isNeutered()) { | 216 if (imageBitmaps[i]->isNeutered()) { |
217 exceptionState.throwDOMException( | 217 exceptionState.throwDOMException(DataCloneError, |
218 DataCloneError, "ImageBitmap at index " + String::number(i) + | 218 "ImageBitmap at index " + |
219 " is already detached."); | 219 String::number(i) + |
| 220 " is already detached."); |
220 return nullptr; | 221 return nullptr; |
221 } | 222 } |
222 } | 223 } |
223 | 224 |
224 std::unique_ptr<ImageBitmapContentsArray> contents = | 225 std::unique_ptr<ImageBitmapContentsArray> contents = |
225 WTF::wrapUnique(new ImageBitmapContentsArray); | 226 WTF::wrapUnique(new ImageBitmapContentsArray); |
226 HeapHashSet<Member<ImageBitmap>> visited; | 227 HeapHashSet<Member<ImageBitmap>> visited; |
227 for (size_t i = 0; i < imageBitmaps.size(); ++i) { | 228 for (size_t i = 0; i < imageBitmaps.size(); ++i) { |
228 if (visited.contains(imageBitmaps[i])) | 229 if (visited.contains(imageBitmaps[i])) |
229 continue; | 230 continue; |
(...skipping 17 matching lines...) Expand all Loading... |
247 const OffscreenCanvasArray& offscreenCanvases, | 248 const OffscreenCanvasArray& offscreenCanvases, |
248 ExceptionState& exceptionState) { | 249 ExceptionState& exceptionState) { |
249 if (!offscreenCanvases.size()) | 250 if (!offscreenCanvases.size()) |
250 return; | 251 return; |
251 | 252 |
252 HeapHashSet<Member<OffscreenCanvas>> visited; | 253 HeapHashSet<Member<OffscreenCanvas>> visited; |
253 for (size_t i = 0; i < offscreenCanvases.size(); i++) { | 254 for (size_t i = 0; i < offscreenCanvases.size(); i++) { |
254 if (visited.contains(offscreenCanvases[i].get())) | 255 if (visited.contains(offscreenCanvases[i].get())) |
255 continue; | 256 continue; |
256 if (offscreenCanvases[i]->isNeutered()) { | 257 if (offscreenCanvases[i]->isNeutered()) { |
257 exceptionState.throwDOMException( | 258 exceptionState.throwDOMException(DataCloneError, |
258 DataCloneError, "OffscreenCanvas at index " + String::number(i) + | 259 "OffscreenCanvas at index " + |
259 " is already detached."); | 260 String::number(i) + |
| 261 " is already detached."); |
260 return; | 262 return; |
261 } | 263 } |
262 if (offscreenCanvases[i]->renderingContext()) { | 264 if (offscreenCanvases[i]->renderingContext()) { |
263 exceptionState.throwDOMException( | 265 exceptionState.throwDOMException(DataCloneError, |
264 DataCloneError, "OffscreenCanvas at index " + String::number(i) + | 266 "OffscreenCanvas at index " + |
265 " has an associated context."); | 267 String::number(i) + |
| 268 " has an associated context."); |
266 return; | 269 return; |
267 } | 270 } |
268 visited.insert(offscreenCanvases[i].get()); | 271 visited.insert(offscreenCanvases[i].get()); |
269 offscreenCanvases[i].get()->setNeutered(); | 272 offscreenCanvases[i].get()->setNeutered(); |
270 } | 273 } |
271 } | 274 } |
272 | 275 |
273 void SerializedScriptValue::transferArrayBuffers( | 276 void SerializedScriptValue::transferArrayBuffers( |
274 v8::Isolate* isolate, | 277 v8::Isolate* isolate, |
275 const ArrayBufferArray& arrayBuffers, | 278 const ArrayBufferArray& arrayBuffers, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 " value."); | 330 " value."); |
328 return false; | 331 return false; |
329 } | 332 } |
330 // Validation of Objects implementing an interface, per WebIDL spec 4.1.15. | 333 // Validation of Objects implementing an interface, per WebIDL spec 4.1.15. |
331 if (V8MessagePort::hasInstance(transferableObject, isolate)) { | 334 if (V8MessagePort::hasInstance(transferableObject, isolate)) { |
332 MessagePort* port = V8MessagePort::toImpl( | 335 MessagePort* port = V8MessagePort::toImpl( |
333 v8::Local<v8::Object>::Cast(transferableObject)); | 336 v8::Local<v8::Object>::Cast(transferableObject)); |
334 // Check for duplicate MessagePorts. | 337 // Check for duplicate MessagePorts. |
335 if (transferables.messagePorts.contains(port)) { | 338 if (transferables.messagePorts.contains(port)) { |
336 exceptionState.throwDOMException( | 339 exceptionState.throwDOMException( |
337 DataCloneError, "Message port at index " + String::number(i) + | 340 DataCloneError, |
338 " is a duplicate of an earlier port."); | 341 "Message port at index " + String::number(i) + |
| 342 " is a duplicate of an earlier port."); |
339 return false; | 343 return false; |
340 } | 344 } |
341 transferables.messagePorts.push_back(port); | 345 transferables.messagePorts.push_back(port); |
342 } else if (transferableObject->IsArrayBuffer()) { | 346 } else if (transferableObject->IsArrayBuffer()) { |
343 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl( | 347 DOMArrayBuffer* arrayBuffer = V8ArrayBuffer::toImpl( |
344 v8::Local<v8::Object>::Cast(transferableObject)); | 348 v8::Local<v8::Object>::Cast(transferableObject)); |
345 if (transferables.arrayBuffers.contains(arrayBuffer)) { | 349 if (transferables.arrayBuffers.contains(arrayBuffer)) { |
346 exceptionState.throwDOMException( | 350 exceptionState.throwDOMException( |
347 DataCloneError, "ArrayBuffer at index " + String::number(i) + | 351 DataCloneError, |
348 " is a duplicate of an earlier ArrayBuffer."); | 352 "ArrayBuffer at index " + String::number(i) + |
| 353 " is a duplicate of an earlier ArrayBuffer."); |
349 return false; | 354 return false; |
350 } | 355 } |
351 transferables.arrayBuffers.push_back(arrayBuffer); | 356 transferables.arrayBuffers.push_back(arrayBuffer); |
352 } else if (transferableObject->IsSharedArrayBuffer()) { | 357 } else if (transferableObject->IsSharedArrayBuffer()) { |
353 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImpl( | 358 DOMSharedArrayBuffer* sharedArrayBuffer = V8SharedArrayBuffer::toImpl( |
354 v8::Local<v8::Object>::Cast(transferableObject)); | 359 v8::Local<v8::Object>::Cast(transferableObject)); |
355 if (transferables.arrayBuffers.contains(sharedArrayBuffer)) { | 360 if (transferables.arrayBuffers.contains(sharedArrayBuffer)) { |
356 exceptionState.throwDOMException( | 361 exceptionState.throwDOMException( |
357 DataCloneError, | 362 DataCloneError, |
358 "SharedArrayBuffer at index " + String::number(i) + | 363 "SharedArrayBuffer at index " + String::number(i) + |
359 " is a duplicate of an earlier SharedArrayBuffer."); | 364 " is a duplicate of an earlier SharedArrayBuffer."); |
360 return false; | 365 return false; |
361 } | 366 } |
362 transferables.arrayBuffers.push_back(sharedArrayBuffer); | 367 transferables.arrayBuffers.push_back(sharedArrayBuffer); |
363 } else if (V8ImageBitmap::hasInstance(transferableObject, isolate)) { | 368 } else if (V8ImageBitmap::hasInstance(transferableObject, isolate)) { |
364 ImageBitmap* imageBitmap = V8ImageBitmap::toImpl( | 369 ImageBitmap* imageBitmap = V8ImageBitmap::toImpl( |
365 v8::Local<v8::Object>::Cast(transferableObject)); | 370 v8::Local<v8::Object>::Cast(transferableObject)); |
366 if (transferables.imageBitmaps.contains(imageBitmap)) { | 371 if (transferables.imageBitmaps.contains(imageBitmap)) { |
367 exceptionState.throwDOMException( | 372 exceptionState.throwDOMException( |
368 DataCloneError, "ImageBitmap at index " + String::number(i) + | 373 DataCloneError, |
369 " is a duplicate of an earlier ImageBitmap."); | 374 "ImageBitmap at index " + String::number(i) + |
| 375 " is a duplicate of an earlier ImageBitmap."); |
370 return false; | 376 return false; |
371 } | 377 } |
372 transferables.imageBitmaps.push_back(imageBitmap); | 378 transferables.imageBitmaps.push_back(imageBitmap); |
373 } else if (V8OffscreenCanvas::hasInstance(transferableObject, isolate)) { | 379 } else if (V8OffscreenCanvas::hasInstance(transferableObject, isolate)) { |
374 OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl( | 380 OffscreenCanvas* offscreenCanvas = V8OffscreenCanvas::toImpl( |
375 v8::Local<v8::Object>::Cast(transferableObject)); | 381 v8::Local<v8::Object>::Cast(transferableObject)); |
376 if (transferables.offscreenCanvases.contains(offscreenCanvas)) { | 382 if (transferables.offscreenCanvases.contains(offscreenCanvas)) { |
377 exceptionState.throwDOMException( | 383 exceptionState.throwDOMException( |
378 DataCloneError, | 384 DataCloneError, |
379 "OffscreenCanvas at index " + String::number(i) + | 385 "OffscreenCanvas at index " + String::number(i) + |
(...skipping 15 matching lines...) Expand all Loading... |
395 v8::Isolate* isolate, | 401 v8::Isolate* isolate, |
396 const ArrayBufferArray& arrayBuffers, | 402 const ArrayBufferArray& arrayBuffers, |
397 ExceptionState& exceptionState) { | 403 ExceptionState& exceptionState) { |
398 if (!arrayBuffers.size()) | 404 if (!arrayBuffers.size()) |
399 return nullptr; | 405 return nullptr; |
400 | 406 |
401 for (auto it = arrayBuffers.begin(); it != arrayBuffers.end(); ++it) { | 407 for (auto it = arrayBuffers.begin(); it != arrayBuffers.end(); ++it) { |
402 DOMArrayBufferBase* arrayBuffer = *it; | 408 DOMArrayBufferBase* arrayBuffer = *it; |
403 if (arrayBuffer->isNeutered()) { | 409 if (arrayBuffer->isNeutered()) { |
404 size_t index = std::distance(arrayBuffers.begin(), it); | 410 size_t index = std::distance(arrayBuffers.begin(), it); |
405 exceptionState.throwDOMException( | 411 exceptionState.throwDOMException(DataCloneError, |
406 DataCloneError, "ArrayBuffer at index " + String::number(index) + | 412 "ArrayBuffer at index " + |
407 " is already neutered."); | 413 String::number(index) + |
| 414 " is already neutered."); |
408 return nullptr; | 415 return nullptr; |
409 } | 416 } |
410 } | 417 } |
411 | 418 |
412 std::unique_ptr<ArrayBufferContentsArray> contents = | 419 std::unique_ptr<ArrayBufferContentsArray> contents = |
413 WTF::wrapUnique(new ArrayBufferContentsArray(arrayBuffers.size())); | 420 WTF::wrapUnique(new ArrayBufferContentsArray(arrayBuffers.size())); |
414 | 421 |
415 HeapHashSet<Member<DOMArrayBufferBase>> visited; | 422 HeapHashSet<Member<DOMArrayBufferBase>> visited; |
416 for (auto it = arrayBuffers.begin(); it != arrayBuffers.end(); ++it) { | 423 for (auto it = arrayBuffers.begin(); it != arrayBuffers.end(); ++it) { |
417 DOMArrayBufferBase* arrayBuffer = *it; | 424 DOMArrayBufferBase* arrayBuffer = *it; |
(...skipping 18 matching lines...) Expand all Loading... |
436 bool isNeuterable = true; | 443 bool isNeuterable = true; |
437 for (const auto& bufferHandle : bufferHandles) | 444 for (const auto& bufferHandle : bufferHandles) |
438 isNeuterable &= bufferHandle->IsNeuterable(); | 445 isNeuterable &= bufferHandle->IsNeuterable(); |
439 | 446 |
440 DOMArrayBufferBase* toTransfer = arrayBuffer; | 447 DOMArrayBufferBase* toTransfer = arrayBuffer; |
441 if (!isNeuterable) { | 448 if (!isNeuterable) { |
442 toTransfer = DOMArrayBuffer::create( | 449 toTransfer = DOMArrayBuffer::create( |
443 arrayBuffer->buffer()->data(), arrayBuffer->buffer()->byteLength()); | 450 arrayBuffer->buffer()->data(), arrayBuffer->buffer()->byteLength()); |
444 } | 451 } |
445 if (!toTransfer->transfer(contents->at(index))) { | 452 if (!toTransfer->transfer(contents->at(index))) { |
446 exceptionState.throwDOMException( | 453 exceptionState.throwDOMException(DataCloneError, |
447 DataCloneError, "ArrayBuffer at index " + String::number(index) + | 454 "ArrayBuffer at index " + |
448 " could not be transferred."); | 455 String::number(index) + |
| 456 " could not be transferred."); |
449 return nullptr; | 457 return nullptr; |
450 } | 458 } |
451 | 459 |
452 if (isNeuterable) { | 460 if (isNeuterable) { |
453 for (const auto& bufferHandle : bufferHandles) | 461 for (const auto& bufferHandle : bufferHandles) |
454 bufferHandle->Neuter(); | 462 bufferHandle->Neuter(); |
455 } | 463 } |
456 } | 464 } |
457 } | 465 } |
458 return contents; | 466 return contents; |
459 } | 467 } |
460 | 468 |
461 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() { | 469 void SerializedScriptValue::registerMemoryAllocatedWithCurrentScriptContext() { |
462 if (m_externallyAllocatedMemory) | 470 if (m_externallyAllocatedMemory) |
463 return; | 471 return; |
464 | 472 |
465 m_externallyAllocatedMemory = static_cast<intptr_t>(dataLengthInBytes()); | 473 m_externallyAllocatedMemory = static_cast<intptr_t>(dataLengthInBytes()); |
466 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( | 474 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory( |
467 m_externallyAllocatedMemory); | 475 m_externallyAllocatedMemory); |
468 } | 476 } |
469 | 477 |
470 } // namespace blink | 478 } // namespace blink |
OLD | NEW |