| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 private: | 197 private: |
| 198 Vector<BufferValueType> m_buffer; | 198 Vector<BufferValueType> m_buffer; |
| 199 unsigned m_position; | 199 unsigned m_position; |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 class CORE_EXPORT ScriptValueSerializer { | 202 class CORE_EXPORT ScriptValueSerializer { |
| 203 STACK_ALLOCATED(); | 203 STACK_ALLOCATED(); |
| 204 WTF_MAKE_NONCOPYABLE(ScriptValueSerializer); | 204 WTF_MAKE_NONCOPYABLE(ScriptValueSerializer); |
| 205 protected: | 205 protected: |
| 206 class StateBase; | 206 class StateBase; |
| 207 public: | 207 enum class Status { |
| 208 enum Status { | |
| 209 Success, | 208 Success, |
| 210 InputError, | 209 InputError, |
| 211 DataCloneError, | 210 DataCloneError, |
| 212 JSException | 211 JSException |
| 213 }; | 212 }; |
| 214 | 213 |
| 215 ScriptValueSerializer(SerializedScriptValueWriter&, const Transferables*, We
bBlobInfoArray*, BlobDataHandleMap& blobDataHandles, v8::TryCatch&, ScriptState*
); | 214 public: |
| 215 ScriptValueSerializer(SerializedScriptValueWriter&, const Transferables*, We
bBlobInfoArray*, ScriptState*); |
| 216 v8::Isolate* isolate() { return m_scriptState->isolate(); } | 216 v8::Isolate* isolate() { return m_scriptState->isolate(); } |
| 217 v8::Local<v8::Context> context() { return m_scriptState->context(); } | 217 v8::Local<v8::Context> context() { return m_scriptState->context(); } |
| 218 | 218 |
| 219 Status serialize(v8::Local<v8::Value>); | 219 PassRefPtr<SerializedScriptValue> serialize(v8::Local<v8::Value>, Transferab
les*, ExceptionState&); |
| 220 String errorMessage() { return m_errorMessage; } | 220 String errorMessage() { return m_errorMessage; } |
| 221 | 221 |
| 222 static String serializeWTFString(const String&); | 222 static String serializeWTFString(const String&); |
| 223 static String serializeNullValue(); | 223 static String serializeNullValue(); |
| 224 | 224 |
| 225 protected: | 225 protected: |
| 226 class StateBase { | 226 class StateBase { |
| 227 USING_FAST_MALLOC(StateBase); | 227 USING_FAST_MALLOC(StateBase); |
| 228 WTF_MAKE_NONCOPYABLE(StateBase); | 228 WTF_MAKE_NONCOPYABLE(StateBase); |
| 229 public: | 229 public: |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 367 |
| 368 typedef CollectionState<v8::Map> MapState; | 368 typedef CollectionState<v8::Map> MapState; |
| 369 typedef CollectionState<v8::Set> SetState; | 369 typedef CollectionState<v8::Set> SetState; |
| 370 | 370 |
| 371 // Functions used by serialization states. | 371 // Functions used by serialization states. |
| 372 virtual StateBase* doSerializeObject(v8::Local<v8::Object>, StateBase* next)
; | 372 virtual StateBase* doSerializeObject(v8::Local<v8::Object>, StateBase* next)
; |
| 373 | 373 |
| 374 private: | 374 private: |
| 375 StateBase* doSerialize(v8::Local<v8::Value>, StateBase* next); | 375 StateBase* doSerialize(v8::Local<v8::Value>, StateBase* next); |
| 376 StateBase* doSerializeArrayBuffer(v8::Local<v8::Value> arrayBuffer, StateBas
e* next); | 376 StateBase* doSerializeArrayBuffer(v8::Local<v8::Value> arrayBuffer, StateBas
e* next); |
| 377 void transferData(Transferables*, ExceptionState&, SerializedScriptValue*); |
| 378 |
| 377 StateBase* checkException(StateBase*); | 379 StateBase* checkException(StateBase*); |
| 378 StateBase* writeObject(uint32_t numProperties, StateBase*); | 380 StateBase* writeObject(uint32_t numProperties, StateBase*); |
| 379 StateBase* writeSparseArray(uint32_t numProperties, uint32_t length, StateBa
se*); | 381 StateBase* writeSparseArray(uint32_t numProperties, uint32_t length, StateBa
se*); |
| 380 StateBase* writeDenseArray(uint32_t numProperties, uint32_t length, StateBas
e*); | 382 StateBase* writeDenseArray(uint32_t numProperties, uint32_t length, StateBas
e*); |
| 381 | 383 |
| 382 template <typename T> StateBase* writeCollection(uint32_t length, StateBase*
); | 384 template <typename T> StateBase* writeCollection(uint32_t length, StateBase*
); |
| 383 | 385 |
| 384 StateBase* push(StateBase* state) | 386 StateBase* push(StateBase* state) |
| 385 { | 387 { |
| 386 ASSERT(state); | 388 ASSERT(state); |
| 387 ++m_depth; | 389 ++m_depth; |
| 388 return checkComposite(state) ? state : handleError(InputError, "Value be
ing cloned is either cyclic or too deeply nested.", state); | 390 return checkComposite(state) ? state : handleError(Status::InputError, "
Value being cloned is either cyclic or too deeply nested.", state); |
| 389 } | 391 } |
| 390 | 392 |
| 391 StateBase* pop(StateBase* state) | 393 StateBase* pop(StateBase* state) |
| 392 { | 394 { |
| 393 ASSERT(state); | 395 ASSERT(state); |
| 394 --m_depth; | 396 --m_depth; |
| 395 StateBase* next = state->nextState(); | 397 StateBase* next = state->nextState(); |
| 396 delete state; | 398 delete state; |
| 397 return next; | 399 return next; |
| 398 } | 400 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 434 |
| 433 SerializedScriptValueWriter& writer() { return m_writer; } | 435 SerializedScriptValueWriter& writer() { return m_writer; } |
| 434 uint32_t nextObjectReference() const { return m_nextObjectReference; } | 436 uint32_t nextObjectReference() const { return m_nextObjectReference; } |
| 435 | 437 |
| 436 private: | 438 private: |
| 437 | 439 |
| 438 void copyTransferables(const Transferables&); | 440 void copyTransferables(const Transferables&); |
| 439 | 441 |
| 440 RefPtr<ScriptState> m_scriptState; | 442 RefPtr<ScriptState> m_scriptState; |
| 441 SerializedScriptValueWriter& m_writer; | 443 SerializedScriptValueWriter& m_writer; |
| 442 v8::TryCatch& m_tryCatch; | 444 v8::TryCatch m_tryCatch; |
| 443 int m_depth; | 445 int m_depth; |
| 444 Status m_status; | 446 Status m_status; |
| 445 String m_errorMessage; | 447 String m_errorMessage; |
| 446 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; | 448 typedef V8ObjectMap<v8::Object, uint32_t> ObjectPool; |
| 447 ObjectPool m_objectPool; | 449 ObjectPool m_objectPool; |
| 448 ObjectPool m_transferredMessagePorts; | 450 ObjectPool m_transferredMessagePorts; |
| 449 ObjectPool m_transferredArrayBuffers; | 451 ObjectPool m_transferredArrayBuffers; |
| 450 ObjectPool m_transferredImageBitmaps; | 452 ObjectPool m_transferredImageBitmaps; |
| 451 ObjectPool m_transferredOffscreenCanvas; | 453 ObjectPool m_transferredOffscreenCanvas; |
| 452 uint32_t m_nextObjectReference; | 454 uint32_t m_nextObjectReference; |
| 453 WebBlobInfoArray* m_blobInfo; | 455 WebBlobInfoArray* m_blobInfo; |
| 454 BlobDataHandleMap& m_blobDataHandles; | 456 BlobDataHandleMap* m_blobDataHandles; |
| 455 }; | 457 }; |
| 456 | 458 |
| 457 class ScriptValueDeserializer; | 459 class ScriptValueDeserializer; |
| 458 | 460 |
| 459 // SerializedScriptValueReader is responsible for deserializing primitive types
and | 461 // SerializedScriptValueReader is responsible for deserializing primitive types
and |
| 460 // restoring information about saved objects of composite types. | 462 // restoring information about saved objects of composite types. |
| 461 class CORE_EXPORT SerializedScriptValueReader { | 463 class CORE_EXPORT SerializedScriptValueReader { |
| 462 STACK_ALLOCATED(); | 464 STACK_ALLOCATED(); |
| 463 WTF_MAKE_NONCOPYABLE(SerializedScriptValueReader); | 465 WTF_MAKE_NONCOPYABLE(SerializedScriptValueReader); |
| 464 public: | 466 public: |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 ArrayBufferContentsArray* m_arrayBufferContents; | 625 ArrayBufferContentsArray* m_arrayBufferContents; |
| 624 ImageBitmapContentsArray* m_imageBitmapContents; | 626 ImageBitmapContentsArray* m_imageBitmapContents; |
| 625 Vector<v8::Local<v8::Value>> m_arrayBuffers; | 627 Vector<v8::Local<v8::Value>> m_arrayBuffers; |
| 626 Vector<v8::Local<v8::Value>> m_imageBitmaps; | 628 Vector<v8::Local<v8::Value>> m_imageBitmaps; |
| 627 uint32_t m_version; | 629 uint32_t m_version; |
| 628 }; | 630 }; |
| 629 | 631 |
| 630 } // namespace blink | 632 } // namespace blink |
| 631 | 633 |
| 632 #endif // ScriptValueSerializer_h | 634 #endif // ScriptValueSerializer_h |
| OLD | NEW |