| 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 16 matching lines...) Expand all Loading... |
| 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 <memory> | 33 #include <memory> |
| 34 #include "bindings/core/v8/DOMDataStore.h" | 34 #include "bindings/core/v8/DOMDataStore.h" |
| 35 #include "bindings/core/v8/DOMWrapperWorld.h" | 35 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 36 #include "bindings/core/v8/ExceptionState.h" | 36 #include "bindings/core/v8/ExceptionState.h" |
| 37 #include "bindings/core/v8/IDLTypes.h" |
| 38 #include "bindings/core/v8/NativeValueTraitsImpl.h" |
| 37 #include "bindings/core/v8/ScriptState.h" | 39 #include "bindings/core/v8/ScriptState.h" |
| 38 #include "bindings/core/v8/SerializationTag.h" | 40 #include "bindings/core/v8/SerializationTag.h" |
| 39 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 41 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 40 #include "bindings/core/v8/Transferables.h" | 42 #include "bindings/core/v8/Transferables.h" |
| 41 #include "bindings/core/v8/V8ArrayBuffer.h" | 43 #include "bindings/core/v8/V8ArrayBuffer.h" |
| 42 #include "bindings/core/v8/V8ImageBitmap.h" | 44 #include "bindings/core/v8/V8ImageBitmap.h" |
| 43 #include "bindings/core/v8/V8MessagePort.h" | 45 #include "bindings/core/v8/V8MessagePort.h" |
| 44 #include "bindings/core/v8/V8OffscreenCanvas.h" | 46 #include "bindings/core/v8/V8OffscreenCanvas.h" |
| 45 #include "bindings/core/v8/V8SharedArrayBuffer.h" | 47 #include "bindings/core/v8/V8SharedArrayBuffer.h" |
| 46 #include "core/dom/DOMArrayBuffer.h" | 48 #include "core/dom/DOMArrayBuffer.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 368 |
| 367 bool SerializedScriptValue::ExtractTransferables( | 369 bool SerializedScriptValue::ExtractTransferables( |
| 368 v8::Isolate* isolate, | 370 v8::Isolate* isolate, |
| 369 v8::Local<v8::Value> value, | 371 v8::Local<v8::Value> value, |
| 370 int argument_index, | 372 int argument_index, |
| 371 Transferables& transferables, | 373 Transferables& transferables, |
| 372 ExceptionState& exception_state) { | 374 ExceptionState& exception_state) { |
| 373 if (value.IsEmpty() || value->IsUndefined()) | 375 if (value.IsEmpty() || value->IsUndefined()) |
| 374 return true; | 376 return true; |
| 375 | 377 |
| 376 uint32_t length = 0; | 378 Vector<v8::Local<v8::Value>> transferable_array = |
| 377 if (value->IsArray()) { | 379 NativeValueTraits<IDLSequence<v8::Local<v8::Value>>>::NativeValue( |
| 378 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); | 380 isolate, value, exception_state); |
| 379 length = array->Length(); | 381 if (exception_state.HadException()) |
| 380 } else if (!ToV8Sequence(value, length, isolate, exception_state)) { | |
| 381 if (!exception_state.HadException()) | |
| 382 exception_state.ThrowTypeError( | |
| 383 ExceptionMessages::NotAnArrayTypeArgumentOrValue(argument_index + 1)); | |
| 384 return false; | 382 return false; |
| 385 } | |
| 386 | |
| 387 v8::Local<v8::Object> transferable_array = v8::Local<v8::Object>::Cast(value); | |
| 388 | 383 |
| 389 // Validate the passed array of transferables. | 384 // Validate the passed array of transferables. |
| 390 for (unsigned i = 0; i < length; ++i) { | 385 uint32_t i = 0; |
| 391 v8::Local<v8::Value> transferable_object; | 386 for (const auto& transferable_object : transferable_array) { |
| 392 if (!transferable_array->Get(isolate->GetCurrentContext(), i) | |
| 393 .ToLocal(&transferable_object)) | |
| 394 return false; | |
| 395 // Validation of non-null objects, per HTML5 spec 10.3.3. | 387 // Validation of non-null objects, per HTML5 spec 10.3.3. |
| 396 if (IsUndefinedOrNull(transferable_object)) { | 388 if (IsUndefinedOrNull(transferable_object)) { |
| 397 exception_state.ThrowTypeError( | 389 exception_state.ThrowTypeError( |
| 398 "Value at index " + String::Number(i) + " is an untransferable " + | 390 "Value at index " + String::Number(i) + " is an untransferable " + |
| 399 (transferable_object->IsUndefined() ? "'undefined'" : "'null'") + | 391 (transferable_object->IsUndefined() ? "'undefined'" : "'null'") + |
| 400 " value."); | 392 " value."); |
| 401 return false; | 393 return false; |
| 402 } | 394 } |
| 403 // Validation of Objects implementing an interface, per WebIDL spec 4.1.15. | 395 // Validation of Objects implementing an interface, per WebIDL spec 4.1.15. |
| 404 if (V8MessagePort::hasInstance(transferable_object, isolate)) { | 396 if (V8MessagePort::hasInstance(transferable_object, isolate)) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 "OffscreenCanvas at index " + String::Number(i) + | 444 "OffscreenCanvas at index " + String::Number(i) + |
| 453 " is a duplicate of an earlier OffscreenCanvas."); | 445 " is a duplicate of an earlier OffscreenCanvas."); |
| 454 return false; | 446 return false; |
| 455 } | 447 } |
| 456 transferables.offscreen_canvases.push_back(offscreen_canvas); | 448 transferables.offscreen_canvases.push_back(offscreen_canvas); |
| 457 } else { | 449 } else { |
| 458 exception_state.ThrowTypeError("Value at index " + String::Number(i) + | 450 exception_state.ThrowTypeError("Value at index " + String::Number(i) + |
| 459 " does not have a transferable type."); | 451 " does not have a transferable type."); |
| 460 return false; | 452 return false; |
| 461 } | 453 } |
| 454 i++; |
| 462 } | 455 } |
| 463 return true; | 456 return true; |
| 464 } | 457 } |
| 465 | 458 |
| 466 std::unique_ptr<SerializedScriptValue::ArrayBufferContentsArray> | 459 std::unique_ptr<SerializedScriptValue::ArrayBufferContentsArray> |
| 467 SerializedScriptValue::TransferArrayBufferContents( | 460 SerializedScriptValue::TransferArrayBufferContents( |
| 468 v8::Isolate* isolate, | 461 v8::Isolate* isolate, |
| 469 const ArrayBufferArray& array_buffers, | 462 const ArrayBufferArray& array_buffers, |
| 470 ExceptionState& exception_state) { | 463 ExceptionState& exception_state) { |
| 471 if (!array_buffers.size()) | 464 if (!array_buffers.size()) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 // Only (re)register allocation cost for transferables if this | 555 // Only (re)register allocation cost for transferables if this |
| 563 // SerializedScriptValue has explicitly unregistered them before. | 556 // SerializedScriptValue has explicitly unregistered them before. |
| 564 if (array_buffer_contents_array_ && | 557 if (array_buffer_contents_array_ && |
| 565 transferables_need_external_allocation_registration_) { | 558 transferables_need_external_allocation_registration_) { |
| 566 for (auto& buffer : *array_buffer_contents_array_) | 559 for (auto& buffer : *array_buffer_contents_array_) |
| 567 buffer.RegisterExternalAllocationWithCurrentContext(); | 560 buffer.RegisterExternalAllocationWithCurrentContext(); |
| 568 } | 561 } |
| 569 } | 562 } |
| 570 | 563 |
| 571 } // namespace blink | 564 } // namespace blink |
| OLD | NEW |