| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ScriptValueSerializer_h | 5 #ifndef ScriptValueSerializer_h |
| 6 #define ScriptValueSerializer_h | 6 #define ScriptValueSerializer_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/SerializationTag.h" | 8 #include "bindings/core/v8/SerializationTag.h" |
| 9 #include "bindings/core/v8/SerializedScriptValue.h" | 9 #include "bindings/core/v8/SerializedScriptValue.h" |
| 10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 void writeTransferredArrayBuffer(uint32_t index); | 136 void writeTransferredArrayBuffer(uint32_t index); |
| 137 void writeObjectReference(uint32_t reference); | 137 void writeObjectReference(uint32_t reference); |
| 138 void writeObject(uint32_t numProperties); | 138 void writeObject(uint32_t numProperties); |
| 139 void writeSparseArray(uint32_t numProperties, uint32_t length); | 139 void writeSparseArray(uint32_t numProperties, uint32_t length); |
| 140 void writeDenseArray(uint32_t numProperties, uint32_t length); | 140 void writeDenseArray(uint32_t numProperties, uint32_t length); |
| 141 String takeWireString(); | 141 String takeWireString(); |
| 142 void writeReferenceCount(uint32_t numberOfReferences); | 142 void writeReferenceCount(uint32_t numberOfReferences); |
| 143 void writeGenerateFreshObject(); | 143 void writeGenerateFreshObject(); |
| 144 void writeGenerateFreshSparseArray(uint32_t length); | 144 void writeGenerateFreshSparseArray(uint32_t length); |
| 145 void writeGenerateFreshDenseArray(uint32_t length); | 145 void writeGenerateFreshDenseArray(uint32_t length); |
| 146 void writeGenerateFreshMap(); |
| 147 void writeGenerateFreshSet(); |
| 148 void writeMap(uint32_t length); |
| 149 void writeSet(uint32_t length); |
| 146 | 150 |
| 147 protected: | 151 protected: |
| 148 void doWriteFile(const File&); | 152 void doWriteFile(const File&); |
| 149 void doWriteArrayBuffer(const DOMArrayBuffer&); | 153 void doWriteArrayBuffer(const DOMArrayBuffer&); |
| 150 void doWriteString(const char* data, int length); | 154 void doWriteString(const char* data, int length); |
| 151 void doWriteWebCoreString(const String&); | 155 void doWriteWebCoreString(const String&); |
| 152 int bytesNeededToWireEncode(uint32_t value); | 156 int bytesNeededToWireEncode(uint32_t value); |
| 153 | 157 |
| 154 template<class T> | 158 template<class T> |
| 155 void doWriteUintHelper(T value) | 159 void doWriteUintHelper(T value) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 { | 324 { |
| 321 m_propertyNames = v8::Local<v8::Array>::New(isolate, propertyNames); | 325 m_propertyNames = v8::Local<v8::Array>::New(isolate, propertyNames); |
| 322 } | 326 } |
| 323 | 327 |
| 324 virtual StateBase* advance(ScriptValueSerializer&) override; | 328 virtual StateBase* advance(ScriptValueSerializer&) override; |
| 325 | 329 |
| 326 protected: | 330 protected: |
| 327 virtual StateBase* objectDone(unsigned numProperties, ScriptValueSeriali
zer&) override; | 331 virtual StateBase* objectDone(unsigned numProperties, ScriptValueSeriali
zer&) override; |
| 328 }; | 332 }; |
| 329 | 333 |
| 334 template <typename T> |
| 335 class CollectionState : public State<T> { |
| 336 public: |
| 337 CollectionState(v8::Local<T> collection, StateBase* next) |
| 338 : State<T>(collection, next) |
| 339 , m_entries(collection->AsArray()) |
| 340 , m_index(0) |
| 341 , m_length(m_entries->Length()) |
| 342 { |
| 343 } |
| 344 |
| 345 virtual StateBase* advance(ScriptValueSerializer&) override; |
| 346 |
| 347 private: |
| 348 v8::Local<v8::Array> m_entries; |
| 349 uint32_t m_index; |
| 350 uint32_t m_length; |
| 351 }; |
| 352 |
| 330 // Functions used by serialization states. | 353 // Functions used by serialization states. |
| 331 virtual StateBase* doSerializeValue(v8::Local<v8::Value>, StateBase* next); | 354 virtual StateBase* doSerializeValue(v8::Local<v8::Value>, StateBase* next); |
| 332 | 355 |
| 333 private: | 356 private: |
| 334 StateBase* doSerialize(v8::Local<v8::Value>, StateBase* next); | 357 StateBase* doSerialize(v8::Local<v8::Value>, StateBase* next); |
| 335 StateBase* doSerializeArrayBuffer(v8::Local<v8::Value> arrayBuffer, StateBas
e* next); | 358 StateBase* doSerializeArrayBuffer(v8::Local<v8::Value> arrayBuffer, StateBas
e* next); |
| 336 StateBase* checkException(StateBase*); | 359 StateBase* checkException(StateBase*); |
| 337 StateBase* writeObject(uint32_t numProperties, StateBase*); | 360 StateBase* writeObject(uint32_t numProperties, StateBase*); |
| 338 StateBase* writeSparseArray(uint32_t numProperties, uint32_t length, StateBa
se*); | 361 StateBase* writeSparseArray(uint32_t numProperties, uint32_t length, StateBa
se*); |
| 339 StateBase* writeDenseArray(uint32_t numProperties, uint32_t length, StateBas
e*); | 362 StateBase* writeDenseArray(uint32_t numProperties, uint32_t length, StateBas
e*); |
| 363 StateBase* writeMap(uint32_t length, StateBase*); |
| 364 StateBase* writeSet(uint32_t length, StateBase*); |
| 340 | 365 |
| 341 StateBase* push(StateBase* state) | 366 StateBase* push(StateBase* state) |
| 342 { | 367 { |
| 343 ASSERT(state); | 368 ASSERT(state); |
| 344 ++m_depth; | 369 ++m_depth; |
| 345 return checkComposite(state) ? state : handleError(InputError, "Value be
ing cloned is either cyclic or too deeply nested.", state); | 370 return checkComposite(state) ? state : handleError(InputError, "Value be
ing cloned is either cyclic or too deeply nested.", state); |
| 346 } | 371 } |
| 347 | 372 |
| 348 StateBase* pop(StateBase* state) | 373 StateBase* pop(StateBase* state) |
| 349 { | 374 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 365 StateBase* writeFileList(v8::Local<v8::Value>, StateBase* next); | 390 StateBase* writeFileList(v8::Local<v8::Value>, StateBase* next); |
| 366 void writeImageData(v8::Local<v8::Value>); | 391 void writeImageData(v8::Local<v8::Value>); |
| 367 void writeRegExp(v8::Local<v8::Value>); | 392 void writeRegExp(v8::Local<v8::Value>); |
| 368 StateBase* writeAndGreyArrayBufferView(v8::Local<v8::Object>, StateBase* nex
t); | 393 StateBase* writeAndGreyArrayBufferView(v8::Local<v8::Object>, StateBase* nex
t); |
| 369 StateBase* writeArrayBuffer(v8::Local<v8::Value>, StateBase* next); | 394 StateBase* writeArrayBuffer(v8::Local<v8::Value>, StateBase* next); |
| 370 StateBase* writeTransferredArrayBuffer(v8::Local<v8::Value>, uint32_t index,
StateBase* next); | 395 StateBase* writeTransferredArrayBuffer(v8::Local<v8::Value>, uint32_t index,
StateBase* next); |
| 371 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount); | 396 static bool shouldSerializeDensely(uint32_t length, uint32_t propertyCount); |
| 372 | 397 |
| 373 StateBase* startArrayState(v8::Local<v8::Array>, StateBase* next); | 398 StateBase* startArrayState(v8::Local<v8::Array>, StateBase* next); |
| 374 StateBase* startObjectState(v8::Local<v8::Object>, StateBase* next); | 399 StateBase* startObjectState(v8::Local<v8::Object>, StateBase* next); |
| 400 StateBase* startMapState(v8::Local<v8::Map>, StateBase* next); |
| 401 StateBase* startSetState(v8::Local<v8::Set>, StateBase* next); |
| 375 | 402 |
| 376 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo
ng size, int* index); | 403 bool appendBlobInfo(const String& uuid, const String& type, unsigned long lo
ng size, int* index); |
| 377 bool appendFileInfo(const File*, int* index); | 404 bool appendFileInfo(const File*, int* index); |
| 378 | 405 |
| 379 protected: | 406 protected: |
| 380 // Marks object as having been visited by the serializer and assigns it a un
ique object reference ID. | 407 // Marks object as having been visited by the serializer and assigns it a un
ique object reference ID. |
| 381 // An object may only be greyed once. | 408 // An object may only be greyed once. |
| 382 void greyObject(const v8::Local<v8::Object>&); | 409 void greyObject(const v8::Local<v8::Object>&); |
| 383 | 410 |
| 384 StateBase* handleError(Status errorStatus, const String& message, StateBase*
); | 411 StateBase* handleError(Status errorStatus, const String& message, StateBase*
); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 411 virtual ~ScriptValueCompositeCreator() { } | 438 virtual ~ScriptValueCompositeCreator() { } |
| 412 | 439 |
| 413 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) = 0; | 440 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) = 0; |
| 414 virtual uint32_t objectReferenceCount() = 0; | 441 virtual uint32_t objectReferenceCount() = 0; |
| 415 virtual void pushObjectReference(const v8::Local<v8::Value>&) = 0; | 442 virtual void pushObjectReference(const v8::Local<v8::Value>&) = 0; |
| 416 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) = 0; | 443 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) = 0; |
| 417 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) = 0; | 444 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) = 0; |
| 418 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) = 0; | 445 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) = 0; |
| 419 virtual bool newSparseArray(uint32_t length) = 0; | 446 virtual bool newSparseArray(uint32_t length) = 0; |
| 420 virtual bool newDenseArray(uint32_t length) = 0; | 447 virtual bool newDenseArray(uint32_t length) = 0; |
| 448 virtual bool newMap() = 0; |
| 449 virtual bool newSet() = 0; |
| 421 virtual bool newObject() = 0; | 450 virtual bool newObject() = 0; |
| 422 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) =
0; | 451 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) =
0; |
| 423 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) = 0; | 452 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) = 0; |
| 424 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) = 0; | 453 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) = 0; |
| 454 virtual bool completeMap(uint32_t length, v8::Local<v8::Value>*) = 0; |
| 455 virtual bool completeSet(uint32_t length, v8::Local<v8::Value>*) = 0; |
| 425 }; | 456 }; |
| 426 | 457 |
| 427 // SerializedScriptValueReader is responsible for deserializing primitive types
and | 458 // SerializedScriptValueReader is responsible for deserializing primitive types
and |
| 428 // restoring information about saved objects of composite types. | 459 // restoring information about saved objects of composite types. |
| 429 class CORE_EXPORT SerializedScriptValueReader { | 460 class CORE_EXPORT SerializedScriptValueReader { |
| 430 STACK_ALLOCATED(); | 461 STACK_ALLOCATED(); |
| 431 WTF_MAKE_NONCOPYABLE(SerializedScriptValueReader); | 462 WTF_MAKE_NONCOPYABLE(SerializedScriptValueReader); |
| 432 public: | 463 public: |
| 433 SerializedScriptValueReader(const uint8_t* buffer, int length, const WebBlob
InfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, ScriptState* scriptStat
e) | 464 SerializedScriptValueReader(const uint8_t* buffer, int length, const WebBlob
InfoArray* blobInfo, BlobDataHandleMap& blobDataHandles, ScriptState* scriptStat
e) |
| 434 : m_scriptState(scriptState) | 465 : m_scriptState(scriptState) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 , m_transferredMessagePorts(messagePorts) | 566 , m_transferredMessagePorts(messagePorts) |
| 536 , m_arrayBufferContents(arrayBufferContents) | 567 , m_arrayBufferContents(arrayBufferContents) |
| 537 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) | 568 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) |
| 538 , m_version(0) | 569 , m_version(0) |
| 539 { | 570 { |
| 540 } | 571 } |
| 541 | 572 |
| 542 v8::Local<v8::Value> deserialize(); | 573 v8::Local<v8::Value> deserialize(); |
| 543 virtual bool newSparseArray(uint32_t) override; | 574 virtual bool newSparseArray(uint32_t) override; |
| 544 virtual bool newDenseArray(uint32_t length) override; | 575 virtual bool newDenseArray(uint32_t length) override; |
| 576 virtual bool newMap() override; |
| 577 virtual bool newSet() override; |
| 545 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) override; | 578 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) override; |
| 546 virtual bool newObject() override; | 579 virtual bool newObject() override; |
| 547 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) o
verride; | 580 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) o
verride; |
| 548 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) override; | 581 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) override; |
| 549 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) override; | 582 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) override; |
| 583 virtual bool completeMap(uint32_t length, v8::Local<v8::Value>*) override; |
| 584 virtual bool completeSet(uint32_t length, v8::Local<v8::Value>*) override; |
| 550 virtual void pushObjectReference(const v8::Local<v8::Value>&) override; | 585 virtual void pushObjectReference(const v8::Local<v8::Value>&) override; |
| 551 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) override; | 586 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) override; |
| 552 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) override; | 587 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) override; |
| 553 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) override; | 588 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) override; |
| 554 virtual uint32_t objectReferenceCount() override; | 589 virtual uint32_t objectReferenceCount() override; |
| 555 | 590 |
| 556 protected: | 591 protected: |
| 557 SerializedScriptValueReader& reader() { return m_reader; } | 592 SerializedScriptValueReader& reader() { return m_reader; } |
| 558 virtual bool read(v8::Local<v8::Value>*); | 593 virtual bool read(v8::Local<v8::Value>*); |
| 559 | 594 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 578 Vector<uint32_t> m_openCompositeReferenceStack; | 613 Vector<uint32_t> m_openCompositeReferenceStack; |
| 579 MessagePortArray* m_transferredMessagePorts; | 614 MessagePortArray* m_transferredMessagePorts; |
| 580 ArrayBufferContentsArray* m_arrayBufferContents; | 615 ArrayBufferContentsArray* m_arrayBufferContents; |
| 581 Vector<v8::Local<v8::Value>> m_arrayBuffers; | 616 Vector<v8::Local<v8::Value>> m_arrayBuffers; |
| 582 uint32_t m_version; | 617 uint32_t m_version; |
| 583 }; | 618 }; |
| 584 | 619 |
| 585 } // namespace blink | 620 } // namespace blink |
| 586 | 621 |
| 587 #endif // ScriptValueSerializer_h | 622 #endif // ScriptValueSerializer_h |
| OLD | NEW |