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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // V8ObjectMap is a map from V8 objects to arbitrary values of type T. | 30 // V8ObjectMap is a map from V8 objects to arbitrary values of type T. |
31 // V8 objects (or handles to V8 objects) cannot be used as keys in ordinary wtf:
:HashMaps; | 31 // V8 objects (or handles to V8 objects) cannot be used as keys in ordinary wtf:
:HashMaps; |
32 // this class should be used instead. GCObject must be a subtype of v8::Object. | 32 // this class should be used instead. GCObject must be a subtype of v8::Object. |
33 // Suggested usage: | 33 // Suggested usage: |
34 // V8ObjectMap<v8::Object, int> map; | 34 // V8ObjectMap<v8::Object, int> map; |
35 // v8::Local<v8::Object> obj = ...; | 35 // v8::Local<v8::Object> obj = ...; |
36 // map.set(obj, 42); | 36 // map.set(obj, 42); |
37 template<typename GCObject, typename T> | 37 template<typename GCObject, typename T> |
38 class V8ObjectMap { | 38 class V8ObjectMap { |
| 39 STACK_ALLOCATED(); |
39 public: | 40 public: |
40 bool contains(const v8::Local<GCObject>& handle) | 41 bool contains(const v8::Local<GCObject>& handle) |
41 { | 42 { |
42 return m_map.contains(*handle); | 43 return m_map.contains(*handle); |
43 } | 44 } |
44 | 45 |
45 bool tryGet(const v8::Local<GCObject>& handle, T* valueOut) | 46 bool tryGet(const v8::Local<GCObject>& handle, T* valueOut) |
46 { | 47 { |
47 typename HandleToT::iterator result = m_map.find(*handle); | 48 typename HandleToT::iterator result = m_map.find(*handle); |
48 if (result != m_map.end()) { | 49 if (result != m_map.end()) { |
(...skipping 30 matching lines...) Expand all Loading... |
79 static unsigned hash(const G* key) | 80 static unsigned hash(const G* key) |
80 { | 81 { |
81 return static_cast<unsigned>(unsafeHandleFromRawValue(key)->GetIdent
ityHash()); | 82 return static_cast<unsigned>(unsafeHandleFromRawValue(key)->GetIdent
ityHash()); |
82 } | 83 } |
83 static bool equal(const G* a, const G* b) | 84 static bool equal(const G* a, const G* b) |
84 { | 85 { |
85 return unsafeHandleFromRawValue(a) == unsafeHandleFromRawValue(b); | 86 return unsafeHandleFromRawValue(a) == unsafeHandleFromRawValue(b); |
86 } | 87 } |
87 // For HashArg. | 88 // For HashArg. |
88 static const bool safeToCompareToEmptyOrDeleted = false; | 89 static const bool safeToCompareToEmptyOrDeleted = false; |
| 90 STATIC_ONLY(V8HandlePtrHash); |
89 }; | 91 }; |
90 | 92 |
91 typedef WTF::HashMap<GCObject*, T, V8HandlePtrHash<GCObject>> HandleToT; | 93 typedef WTF::HashMap<GCObject*, T, V8HandlePtrHash<GCObject>> HandleToT; |
92 HandleToT m_map; | 94 HandleToT m_map; |
93 }; | 95 }; |
94 | 96 |
95 // SerializedScriptValueWriter is responsible for serializing primitive types an
d storing | 97 // SerializedScriptValueWriter is responsible for serializing primitive types an
d storing |
96 // information used to reconstruct composite types. | 98 // information used to reconstruct composite types. |
97 class CORE_EXPORT SerializedScriptValueWriter { | 99 class CORE_EXPORT SerializedScriptValueWriter { |
98 STACK_ALLOCATED(); | 100 STACK_ALLOCATED(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 204 |
203 ScriptValueSerializer(SerializedScriptValueWriter&, MessagePortArray* messag
ePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray*, BlobDataHandleMap& bl
obDataHandles, v8::TryCatch&, ScriptState*); | 205 ScriptValueSerializer(SerializedScriptValueWriter&, MessagePortArray* messag
ePorts, ArrayBufferArray* arrayBuffers, WebBlobInfoArray*, BlobDataHandleMap& bl
obDataHandles, v8::TryCatch&, ScriptState*); |
204 v8::Isolate* isolate() { return m_scriptState->isolate(); } | 206 v8::Isolate* isolate() { return m_scriptState->isolate(); } |
205 v8::Local<v8::Context> context() { return m_scriptState->context(); } | 207 v8::Local<v8::Context> context() { return m_scriptState->context(); } |
206 | 208 |
207 Status serialize(v8::Local<v8::Value>); | 209 Status serialize(v8::Local<v8::Value>); |
208 String errorMessage() { return m_errorMessage; } | 210 String errorMessage() { return m_errorMessage; } |
209 | 211 |
210 protected: | 212 protected: |
211 class StateBase { | 213 class StateBase { |
| 214 WTF_MAKE_FAST_ALLOCATED(StateBase); |
212 WTF_MAKE_NONCOPYABLE(StateBase); | 215 WTF_MAKE_NONCOPYABLE(StateBase); |
213 public: | 216 public: |
214 virtual ~StateBase() { } | 217 virtual ~StateBase() { } |
215 | 218 |
216 // Link to the next state to form a stack. | 219 // Link to the next state to form a stack. |
217 StateBase* nextState() { return m_next; } | 220 StateBase* nextState() { return m_next; } |
218 | 221 |
219 // Composite object we're processing in this state. | 222 // Composite object we're processing in this state. |
220 v8::Local<v8::Value> composite() { return m_composite; } | 223 v8::Local<v8::Value> composite() { return m_composite; } |
221 | 224 |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 Vector<uint32_t> m_openCompositeReferenceStack; | 624 Vector<uint32_t> m_openCompositeReferenceStack; |
622 MessagePortArray* m_transferredMessagePorts; | 625 MessagePortArray* m_transferredMessagePorts; |
623 ArrayBufferContentsArray* m_arrayBufferContents; | 626 ArrayBufferContentsArray* m_arrayBufferContents; |
624 Vector<v8::Local<v8::Value>> m_arrayBuffers; | 627 Vector<v8::Local<v8::Value>> m_arrayBuffers; |
625 uint32_t m_version; | 628 uint32_t m_version; |
626 }; | 629 }; |
627 | 630 |
628 } // namespace blink | 631 } // namespace blink |
629 | 632 |
630 #endif // ScriptValueSerializer_h | 633 #endif // ScriptValueSerializer_h |
OLD | NEW |