Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/SerializedScriptValue.cpp

Issue 2809773003: [SharedArrayBuffer] Throw DataClone error if SharedArrayBuffer can't be sent (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "bindings/core/v8/SerializedScriptValue.h" 31 #include "bindings/core/v8/SerializedScriptValue.h"
32 32
33 #include <algorithm>
33 #include <memory> 34 #include <memory>
34 #include "bindings/core/v8/DOMDataStore.h" 35 #include "bindings/core/v8/DOMDataStore.h"
35 #include "bindings/core/v8/DOMWrapperWorld.h" 36 #include "bindings/core/v8/DOMWrapperWorld.h"
36 #include "bindings/core/v8/ExceptionState.h" 37 #include "bindings/core/v8/ExceptionState.h"
37 #include "bindings/core/v8/ScriptState.h" 38 #include "bindings/core/v8/ScriptState.h"
38 #include "bindings/core/v8/SerializedScriptValueFactory.h" 39 #include "bindings/core/v8/SerializedScriptValueFactory.h"
39 #include "bindings/core/v8/Transferables.h" 40 #include "bindings/core/v8/Transferables.h"
40 #include "bindings/core/v8/V8ArrayBuffer.h" 41 #include "bindings/core/v8/V8ArrayBuffer.h"
41 #include "bindings/core/v8/V8ImageBitmap.h" 42 #include "bindings/core/v8/V8ImageBitmap.h"
42 #include "bindings/core/v8/V8MessagePort.h" 43 #include "bindings/core/v8/V8MessagePort.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 transferables.offscreen_canvases.push_back(offscreen_canvas); 357 transferables.offscreen_canvases.push_back(offscreen_canvas);
357 } else { 358 } else {
358 exception_state.ThrowTypeError("Value at index " + String::Number(i) + 359 exception_state.ThrowTypeError("Value at index " + String::Number(i) +
359 " does not have a transferable type."); 360 " does not have a transferable type.");
360 return false; 361 return false;
361 } 362 }
362 } 363 }
363 return true; 364 return true;
364 } 365 }
365 366
367 ArrayBufferArray SerializedScriptValue::ExtractNonSharedArrayBuffers(
368 Transferables& transferables) {
369 ArrayBufferArray& array_buffers = transferables.array_buffers;
370 ArrayBufferArray result;
371 auto non_shared_begin =
372 std::partition(array_buffers.begin(), array_buffers.end(),
373 [](Member<DOMArrayBufferBase>& array_buffer) {
374 return array_buffer->IsShared();
375 });
376 result.AppendRange(non_shared_begin, array_buffers.end());
377 array_buffers.erase(non_shared_begin - array_buffers.begin(),
378 array_buffers.end() - non_shared_begin);
379 return result;
380 }
381
366 std::unique_ptr<SerializedScriptValue::ArrayBufferContentsArray> 382 std::unique_ptr<SerializedScriptValue::ArrayBufferContentsArray>
367 SerializedScriptValue::TransferArrayBufferContents( 383 SerializedScriptValue::TransferArrayBufferContents(
368 v8::Isolate* isolate, 384 v8::Isolate* isolate,
369 const ArrayBufferArray& array_buffers, 385 const ArrayBufferArray& array_buffers,
370 ExceptionState& exception_state) { 386 ExceptionState& exception_state) {
371 if (!array_buffers.size()) 387 if (!array_buffers.size())
372 return nullptr; 388 return nullptr;
373 389
374 for (auto it = array_buffers.begin(); it != array_buffers.end(); ++it) { 390 for (auto it = array_buffers.begin(); it != array_buffers.end(); ++it) {
375 DOMArrayBufferBase* array_buffer = *it; 391 DOMArrayBufferBase* array_buffer = *it;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // Only (re)register allocation cost for transferables if this 478 // Only (re)register allocation cost for transferables if this
463 // SerializedScriptValue has explicitly unregistered them before. 479 // SerializedScriptValue has explicitly unregistered them before.
464 if (array_buffer_contents_array_ && 480 if (array_buffer_contents_array_ &&
465 transferables_need_external_allocation_registration_) { 481 transferables_need_external_allocation_registration_) {
466 for (auto& buffer : *array_buffer_contents_array_) 482 for (auto& buffer : *array_buffer_contents_array_)
467 buffer.RegisterExternalAllocationWithCurrentContext(); 483 buffer.RegisterExternalAllocationWithCurrentContext();
468 } 484 }
469 } 485 }
470 486
471 } // namespace blink 487 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698