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 14 matching lines...) Expand all Loading... |
63 // never needs to be rebuilt across garbage collections at the expense of do
ing additional allocation | 64 // never needs to be rebuilt across garbage collections at the expense of do
ing additional allocation |
64 // and making more round trips into V8. Note that since GetIdentityHash() is
defined only on | 65 // and making more round trips into V8. Note that since GetIdentityHash() is
defined only on |
65 // v8::Objects, this V8ObjectMap cannot be used to map v8::Strings to T (bec
ause the public V8 API | 66 // v8::Objects, this V8ObjectMap cannot be used to map v8::Strings to T (bec
ause the public V8 API |
66 // considers a v8::String to be a v8::Primitive). | 67 // considers a v8::String to be a v8::Primitive). |
67 | 68 |
68 // If V8 exposes a way to get at the address of the object held by a handle,
then we can produce | 69 // If V8 exposes a way to get at the address of the object held by a handle,
then we can produce |
69 // an alternate implementation that does not need to do any V8-side allocati
on; however, it will | 70 // an alternate implementation that does not need to do any V8-side allocati
on; however, it will |
70 // need to rehash after every garbage collection because a key object may ha
ve been moved. | 71 // need to rehash after every garbage collection because a key object may ha
ve been moved. |
71 template<typename G> | 72 template<typename G> |
72 struct V8HandlePtrHash { | 73 struct V8HandlePtrHash { |
| 74 STATIC_ONLY(V8HandlePtrHash); |
73 static v8::Local<G> unsafeHandleFromRawValue(const G* value) | 75 static v8::Local<G> unsafeHandleFromRawValue(const G* value) |
74 { | 76 { |
75 const v8::Local<G>* handle = reinterpret_cast<const v8::Local<G>*>(&
value); | 77 const v8::Local<G>* handle = reinterpret_cast<const v8::Local<G>*>(&
value); |
76 return *handle; | 78 return *handle; |
77 } | 79 } |
78 | 80 |
79 static unsigned hash(const G* key) | 81 static unsigned hash(const G* key) |
80 { | 82 { |
81 return static_cast<unsigned>(unsafeHandleFromRawValue(key)->GetIdent
ityHash()); | 83 return static_cast<unsigned>(unsafeHandleFromRawValue(key)->GetIdent
ityHash()); |
82 } | 84 } |
(...skipping 119 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 |