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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 }; | 235 }; |
236 | 236 |
237 // Dummy state that is used to signal serialization errors. | 237 // Dummy state that is used to signal serialization errors. |
238 class ErrorState final : public StateBase { | 238 class ErrorState final : public StateBase { |
239 public: | 239 public: |
240 ErrorState() | 240 ErrorState() |
241 : StateBase(v8Undefined(), 0) | 241 : StateBase(v8Undefined(), 0) |
242 { | 242 { |
243 } | 243 } |
244 | 244 |
245 virtual StateBase* advance(ScriptValueSerializer&) override | 245 StateBase* advance(ScriptValueSerializer&) override |
246 { | 246 { |
247 delete this; | 247 delete this; |
248 return 0; | 248 return 0; |
249 } | 249 } |
250 }; | 250 }; |
251 | 251 |
252 template <typename T> | 252 template <typename T> |
253 class State : public StateBase { | 253 class State : public StateBase { |
254 public: | 254 public: |
255 v8::Local<T> composite() { return v8::Local<T>::Cast(StateBase::composit
e()); } | 255 v8::Local<T> composite() { return v8::Local<T>::Cast(StateBase::composit
e()); } |
(...skipping 28 matching lines...) Expand all Loading... |
284 bool m_nameDone; | 284 bool m_nameDone; |
285 }; | 285 }; |
286 | 286 |
287 class ObjectState final : public AbstractObjectState { | 287 class ObjectState final : public AbstractObjectState { |
288 public: | 288 public: |
289 ObjectState(v8::Local<v8::Object> object, StateBase* next) | 289 ObjectState(v8::Local<v8::Object> object, StateBase* next) |
290 : AbstractObjectState(object, next) | 290 : AbstractObjectState(object, next) |
291 { | 291 { |
292 } | 292 } |
293 | 293 |
294 virtual StateBase* advance(ScriptValueSerializer&) override; | 294 StateBase* advance(ScriptValueSerializer&) override; |
295 | 295 |
296 protected: | 296 protected: |
297 virtual StateBase* objectDone(unsigned numProperties, ScriptValueSeriali
zer&) override; | 297 StateBase* objectDone(unsigned numProperties, ScriptValueSerializer&) ov
erride; |
298 }; | 298 }; |
299 | 299 |
300 class DenseArrayState final : public AbstractObjectState { | 300 class DenseArrayState final : public AbstractObjectState { |
301 public: | 301 public: |
302 DenseArrayState(v8::Local<v8::Array> array, v8::Local<v8::Array> propert
yNames, StateBase* next, v8::Isolate* isolate) | 302 DenseArrayState(v8::Local<v8::Array> array, v8::Local<v8::Array> propert
yNames, StateBase* next, v8::Isolate* isolate) |
303 : AbstractObjectState(array, next) | 303 : AbstractObjectState(array, next) |
304 , m_arrayIndex(0) | 304 , m_arrayIndex(0) |
305 , m_arrayLength(array->Length()) | 305 , m_arrayLength(array->Length()) |
306 { | 306 { |
307 m_propertyNames = v8::Local<v8::Array>::New(isolate, propertyNames); | 307 m_propertyNames = v8::Local<v8::Array>::New(isolate, propertyNames); |
308 } | 308 } |
309 | 309 |
310 virtual StateBase* advance(ScriptValueSerializer&) override; | 310 StateBase* advance(ScriptValueSerializer&) override; |
311 | 311 |
312 protected: | 312 protected: |
313 virtual StateBase* objectDone(unsigned numProperties, ScriptValueSeriali
zer&) override; | 313 StateBase* objectDone(unsigned numProperties, ScriptValueSerializer&) ov
erride; |
314 | 314 |
315 private: | 315 private: |
316 uint32_t m_arrayIndex; | 316 uint32_t m_arrayIndex; |
317 uint32_t m_arrayLength; | 317 uint32_t m_arrayLength; |
318 }; | 318 }; |
319 | 319 |
320 class SparseArrayState final : public AbstractObjectState { | 320 class SparseArrayState final : public AbstractObjectState { |
321 public: | 321 public: |
322 SparseArrayState(v8::Local<v8::Array> array, v8::Local<v8::Array> proper
tyNames, StateBase* next, v8::Isolate* isolate) | 322 SparseArrayState(v8::Local<v8::Array> array, v8::Local<v8::Array> proper
tyNames, StateBase* next, v8::Isolate* isolate) |
323 : AbstractObjectState(array, next) | 323 : AbstractObjectState(array, next) |
324 { | 324 { |
325 m_propertyNames = v8::Local<v8::Array>::New(isolate, propertyNames); | 325 m_propertyNames = v8::Local<v8::Array>::New(isolate, propertyNames); |
326 } | 326 } |
327 | 327 |
328 virtual StateBase* advance(ScriptValueSerializer&) override; | 328 StateBase* advance(ScriptValueSerializer&) override; |
329 | 329 |
330 protected: | 330 protected: |
331 virtual StateBase* objectDone(unsigned numProperties, ScriptValueSeriali
zer&) override; | 331 StateBase* objectDone(unsigned numProperties, ScriptValueSerializer&) ov
erride; |
332 }; | 332 }; |
333 | 333 |
334 template <typename T> | 334 template <typename T> |
335 class CollectionState : public State<T> { | 335 class CollectionState : public State<T> { |
336 public: | 336 public: |
337 CollectionState(v8::Local<T> collection, StateBase* next) | 337 CollectionState(v8::Local<T> collection, StateBase* next) |
338 : State<T>(collection, next) | 338 : State<T>(collection, next) |
339 , m_entries(collection->AsArray()) | 339 , m_entries(collection->AsArray()) |
340 , m_index(0) | 340 , m_index(0) |
341 , m_length(m_entries->Length()) | 341 , m_length(m_entries->Length()) |
342 { | 342 { |
343 } | 343 } |
344 | 344 |
345 virtual StateBase* advance(ScriptValueSerializer&) override; | 345 StateBase* advance(ScriptValueSerializer&) override; |
346 | 346 |
347 private: | 347 private: |
348 v8::Local<v8::Array> m_entries; | 348 v8::Local<v8::Array> m_entries; |
349 uint32_t m_index; | 349 uint32_t m_index; |
350 uint32_t m_length; | 350 uint32_t m_length; |
351 }; | 351 }; |
352 | 352 |
353 typedef CollectionState<v8::Map> MapState; | 353 typedef CollectionState<v8::Map> MapState; |
354 typedef CollectionState<v8::Set> SetState; | 354 typedef CollectionState<v8::Set> SetState; |
355 | 355 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 ScriptValueDeserializer(SerializedScriptValueReader& reader, MessagePortArra
y* messagePorts, ArrayBufferContentsArray* arrayBufferContents) | 567 ScriptValueDeserializer(SerializedScriptValueReader& reader, MessagePortArra
y* messagePorts, ArrayBufferContentsArray* arrayBufferContents) |
568 : m_reader(reader) | 568 : m_reader(reader) |
569 , m_transferredMessagePorts(messagePorts) | 569 , m_transferredMessagePorts(messagePorts) |
570 , m_arrayBufferContents(arrayBufferContents) | 570 , m_arrayBufferContents(arrayBufferContents) |
571 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) | 571 , m_arrayBuffers(arrayBufferContents ? arrayBufferContents->size() : 0) |
572 , m_version(0) | 572 , m_version(0) |
573 { | 573 { |
574 } | 574 } |
575 | 575 |
576 v8::Local<v8::Value> deserialize(); | 576 v8::Local<v8::Value> deserialize(); |
577 virtual bool newSparseArray(uint32_t) override; | 577 bool newSparseArray(uint32_t) override; |
578 virtual bool newDenseArray(uint32_t length) override; | 578 bool newDenseArray(uint32_t length) override; |
579 virtual bool newMap() override; | 579 bool newMap() override; |
580 virtual bool newSet() override; | 580 bool newSet() override; |
581 virtual bool consumeTopOfStack(v8::Local<v8::Value>*) override; | 581 bool consumeTopOfStack(v8::Local<v8::Value>*) override; |
582 virtual bool newObject() override; | 582 bool newObject() override; |
583 virtual bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) o
verride; | 583 bool completeObject(uint32_t numProperties, v8::Local<v8::Value>*) override; |
584 virtual bool completeSparseArray(uint32_t numProperties, uint32_t length, v8
::Local<v8::Value>*) override; | 584 bool completeSparseArray(uint32_t numProperties, uint32_t length, v8::Local<
v8::Value>*) override; |
585 virtual bool completeDenseArray(uint32_t numProperties, uint32_t length, v8:
:Local<v8::Value>*) override; | 585 bool completeDenseArray(uint32_t numProperties, uint32_t length, v8::Local<v
8::Value>*) override; |
586 virtual bool completeMap(uint32_t length, v8::Local<v8::Value>*) override; | 586 bool completeMap(uint32_t length, v8::Local<v8::Value>*) override; |
587 virtual bool completeSet(uint32_t length, v8::Local<v8::Value>*) override; | 587 bool completeSet(uint32_t length, v8::Local<v8::Value>*) override; |
588 virtual void pushObjectReference(const v8::Local<v8::Value>&) override; | 588 void pushObjectReference(const v8::Local<v8::Value>&) override; |
589 virtual bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Valu
e>*) override; | 589 bool tryGetTransferredMessagePort(uint32_t index, v8::Local<v8::Value>*) ove
rride; |
590 virtual bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Valu
e>*) override; | 590 bool tryGetTransferredArrayBuffer(uint32_t index, v8::Local<v8::Value>*) ove
rride; |
591 virtual bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v
8::Value>*) override; | 591 bool tryGetObjectFromObjectReference(uint32_t reference, v8::Local<v8::Value
>*) override; |
592 virtual uint32_t objectReferenceCount() override; | 592 uint32_t objectReferenceCount() override; |
593 | 593 |
594 protected: | 594 protected: |
595 SerializedScriptValueReader& reader() { return m_reader; } | 595 SerializedScriptValueReader& reader() { return m_reader; } |
596 virtual bool read(v8::Local<v8::Value>*); | 596 virtual bool read(v8::Local<v8::Value>*); |
597 | 597 |
598 private: | 598 private: |
599 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc
al<v8::Value>*); | 599 bool initializeObject(v8::Local<v8::Object>, uint32_t numProperties, v8::Loc
al<v8::Value>*); |
600 bool doDeserialize(); | 600 bool doDeserialize(); |
601 void push(v8::Local<v8::Value> value) { m_stack.append(value); }; | 601 void push(v8::Local<v8::Value> value) { m_stack.append(value); }; |
602 void pop(unsigned length) | 602 void pop(unsigned length) |
(...skipping 13 matching lines...) Expand all Loading... |
616 Vector<uint32_t> m_openCompositeReferenceStack; | 616 Vector<uint32_t> m_openCompositeReferenceStack; |
617 MessagePortArray* m_transferredMessagePorts; | 617 MessagePortArray* m_transferredMessagePorts; |
618 ArrayBufferContentsArray* m_arrayBufferContents; | 618 ArrayBufferContentsArray* m_arrayBufferContents; |
619 Vector<v8::Local<v8::Value>> m_arrayBuffers; | 619 Vector<v8::Local<v8::Value>> m_arrayBuffers; |
620 uint32_t m_version; | 620 uint32_t m_version; |
621 }; | 621 }; |
622 | 622 |
623 } // namespace blink | 623 } // namespace blink |
624 | 624 |
625 #endif // ScriptValueSerializer_h | 625 #endif // ScriptValueSerializer_h |
OLD | NEW |