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

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

Issue 2810843002: bindings: Make the sequence conversion code more complaint with WebIDL. (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 16 matching lines...) Expand all
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/SerializedScriptValueFactory.h" 40 #include "bindings/core/v8/SerializedScriptValueFactory.h"
39 #include "bindings/core/v8/Transferables.h" 41 #include "bindings/core/v8/Transferables.h"
40 #include "bindings/core/v8/V8ArrayBuffer.h" 42 #include "bindings/core/v8/V8ArrayBuffer.h"
41 #include "bindings/core/v8/V8ImageBitmap.h" 43 #include "bindings/core/v8/V8ImageBitmap.h"
42 #include "bindings/core/v8/V8MessagePort.h" 44 #include "bindings/core/v8/V8MessagePort.h"
43 #include "bindings/core/v8/V8OffscreenCanvas.h" 45 #include "bindings/core/v8/V8OffscreenCanvas.h"
44 #include "bindings/core/v8/V8SharedArrayBuffer.h" 46 #include "bindings/core/v8/V8SharedArrayBuffer.h"
45 #include "core/dom/DOMArrayBuffer.h" 47 #include "core/dom/DOMArrayBuffer.h"
46 #include "core/dom/DOMSharedArrayBuffer.h" 48 #include "core/dom/DOMSharedArrayBuffer.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 268
267 bool SerializedScriptValue::ExtractTransferables( 269 bool SerializedScriptValue::ExtractTransferables(
268 v8::Isolate* isolate, 270 v8::Isolate* isolate,
269 v8::Local<v8::Value> value, 271 v8::Local<v8::Value> value,
270 int argument_index, 272 int argument_index,
271 Transferables& transferables, 273 Transferables& transferables,
272 ExceptionState& exception_state) { 274 ExceptionState& exception_state) {
273 if (value.IsEmpty() || value->IsUndefined()) 275 if (value.IsEmpty() || value->IsUndefined())
274 return true; 276 return true;
275 277
276 uint32_t length = 0; 278 Vector<v8::Local<v8::Value>> transferable_array =
277 if (value->IsArray()) { 279 NativeValueTraits<IDLSequence<v8::Local<v8::Value>>>::NativeValue(
278 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(value); 280 isolate, value, exception_state);
279 length = array->Length();
280 } else if (!ToV8Sequence(value, length, isolate, exception_state)) {
281 if (!exception_state.HadException())
282 exception_state.ThrowTypeError(
283 ExceptionMessages::NotAnArrayTypeArgumentOrValue(argument_index + 1));
284 return false;
285 }
286
287 v8::Local<v8::Object> transferable_array = v8::Local<v8::Object>::Cast(value);
288 281
289 // Validate the passed array of transferables. 282 // Validate the passed array of transferables.
290 for (unsigned i = 0; i < length; ++i) { 283 uint32_t i = 0;
291 v8::Local<v8::Value> transferable_object; 284 for (const auto& transferable_object : transferable_array) {
292 if (!transferable_array->Get(isolate->GetCurrentContext(), i)
293 .ToLocal(&transferable_object))
294 return false;
295 // Validation of non-null objects, per HTML5 spec 10.3.3. 285 // Validation of non-null objects, per HTML5 spec 10.3.3.
296 if (IsUndefinedOrNull(transferable_object)) { 286 if (IsUndefinedOrNull(transferable_object)) {
297 exception_state.ThrowTypeError( 287 exception_state.ThrowTypeError(
298 "Value at index " + String::Number(i) + " is an untransferable " + 288 "Value at index " + String::Number(i) + " is an untransferable " +
299 (transferable_object->IsUndefined() ? "'undefined'" : "'null'") + 289 (transferable_object->IsUndefined() ? "'undefined'" : "'null'") +
300 " value."); 290 " value.");
301 return false; 291 return false;
302 } 292 }
303 // Validation of Objects implementing an interface, per WebIDL spec 4.1.15. 293 // Validation of Objects implementing an interface, per WebIDL spec 4.1.15.
304 if (V8MessagePort::hasInstance(transferable_object, isolate)) { 294 if (V8MessagePort::hasInstance(transferable_object, isolate)) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 "OffscreenCanvas at index " + String::Number(i) + 342 "OffscreenCanvas at index " + String::Number(i) +
353 " is a duplicate of an earlier OffscreenCanvas."); 343 " is a duplicate of an earlier OffscreenCanvas.");
354 return false; 344 return false;
355 } 345 }
356 transferables.offscreen_canvases.push_back(offscreen_canvas); 346 transferables.offscreen_canvases.push_back(offscreen_canvas);
357 } else { 347 } else {
358 exception_state.ThrowTypeError("Value at index " + String::Number(i) + 348 exception_state.ThrowTypeError("Value at index " + String::Number(i) +
359 " does not have a transferable type."); 349 " does not have a transferable type.");
360 return false; 350 return false;
361 } 351 }
352 i++;
362 } 353 }
363 return true; 354 return true;
364 } 355 }
365 356
366 std::unique_ptr<SerializedScriptValue::ArrayBufferContentsArray> 357 std::unique_ptr<SerializedScriptValue::ArrayBufferContentsArray>
367 SerializedScriptValue::TransferArrayBufferContents( 358 SerializedScriptValue::TransferArrayBufferContents(
368 v8::Isolate* isolate, 359 v8::Isolate* isolate,
369 const ArrayBufferArray& array_buffers, 360 const ArrayBufferArray& array_buffers,
370 ExceptionState& exception_state) { 361 ExceptionState& exception_state) {
371 if (!array_buffers.size()) 362 if (!array_buffers.size())
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // Only (re)register allocation cost for transferables if this 453 // Only (re)register allocation cost for transferables if this
463 // SerializedScriptValue has explicitly unregistered them before. 454 // SerializedScriptValue has explicitly unregistered them before.
464 if (array_buffer_contents_array_ && 455 if (array_buffer_contents_array_ &&
465 transferables_need_external_allocation_registration_) { 456 transferables_need_external_allocation_registration_) {
466 for (auto& buffer : *array_buffer_contents_array_) 457 for (auto& buffer : *array_buffer_contents_array_)
467 buffer.RegisterExternalAllocationWithCurrentContext(); 458 buffer.RegisterExternalAllocationWithCurrentContext();
468 } 459 }
469 } 460 }
470 461
471 } // namespace blink 462 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698