Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: Source/bindings/v8/DOMDataStore.h

Issue 18778002: Inherit EventTarget interface instead of duplicating its code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 class Node; 44 class Node;
45 45
46 class DOMDataStore { 46 class DOMDataStore {
47 WTF_MAKE_NONCOPYABLE(DOMDataStore); 47 WTF_MAKE_NONCOPYABLE(DOMDataStore);
48 public: 48 public:
49 explicit DOMDataStore(WrapperWorldType); 49 explicit DOMDataStore(WrapperWorldType);
50 ~DOMDataStore(); 50 ~DOMDataStore();
51 51
52 static DOMDataStore* current(v8::Isolate*); 52 static DOMDataStore* current(v8::Isolate*);
53 53
54 template<typename T, typename HolderContainer, typename Wrappable> 54 template<typename V8T, typename T, typename HolderContainer, typename Wrappa ble>
55 static v8::Handle<v8::Object> getWrapperFast(T* object, const HolderContaine r& container, Wrappable* holder) 55 static v8::Handle<v8::Object> getWrapperFast(T* object, const HolderContaine r& container, Wrappable* holder)
56 { 56 {
57 // What we'd really like to check here is whether we're in the 57 // What we'd really like to check here is whether we're in the
58 // main world or in an isolated world. The fastest way to do that 58 // main world or in an isolated world. The fastest way to do that
59 // is to check that there is no isolated world and the 'object' 59 // is to check that there is no isolated world and the 'object'
60 // is an object that can exist in the main world. The second fastest 60 // is an object that can exist in the main world. The second fastest
61 // way is to check whether the wrappable's wrapper is the same as 61 // way is to check whether the wrappable's wrapper is the same as
62 // the holder. 62 // the holder.
63 if ((!DOMWrapperWorld::isolatedWorldsExist() && !canExistInWorker(object )) || holderContainsWrapper(container, holder)) { 63 if ((!DOMWrapperWorld::isolatedWorldsExist() && !canExistInWorker(object )) || holderContainsWrapper(container, holder)) {
64 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) { 64 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) {
65 v8::Handle<v8::Object> result = ScriptWrappable::getUnsafeWrappe rFromObject(object).handle(); 65 v8::Handle<v8::Object> result = ScriptWrappable::getUnsafeWrappe rFromObject(object).handle();
66 // Security: always guard against malicious tampering. 66 // Security: always guard against malicious tampering.
67 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.IsEmpty() || res ult->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == static_cast< void*>(object)); 67 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.IsEmpty() || res ult->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == V8T::toInter nalPointer(object));
68 return result; 68 return result;
69 } 69 }
70 return mainWorldStore()->m_wrapperMap.get(object); 70 return mainWorldStore()->m_wrapperMap.get(V8T::toInternalPointer(obj ect));
71 } 71 }
72 return current(container.GetIsolate())->get(object); 72 return current(container.GetIsolate())->template get<V8T>(object);
73 } 73 }
74 74
75 template<typename T> 75 template<typename V8T, typename T>
76 static v8::Handle<v8::Object> getWrapper(T* object, v8::Isolate* isolate) 76 static v8::Handle<v8::Object> getWrapper(T* object, v8::Isolate* isolate)
77 { 77 {
78 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) { 78 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) {
79 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) { 79 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) {
80 v8::Handle<v8::Object> result = ScriptWrappable::getUnsafeWrappe rFromObject(object).handle(); 80 v8::Handle<v8::Object> result = ScriptWrappable::getUnsafeWrappe rFromObject(object).handle();
81 // Security: always guard against malicious tampering. 81 // Security: always guard against malicious tampering.
82 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.IsEmpty() || res ult->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == static_cast< void*>(object)); 82 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.IsEmpty() || res ult->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == V8T::toInter nalPointer(object));
83 return result; 83 return result;
84 } 84 }
85 } 85 }
86 return current(isolate)->get(object); 86 return current(isolate)->template get<V8T>(object);
87 } 87 }
88 88
89 template<typename T> 89 template<typename V8T, typename T>
90 static v8::Handle<v8::Object> getWrapperForMainWorld(T* object) 90 static v8::Handle<v8::Object> getWrapperForMainWorld(T* object)
91 { 91 {
92 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) 92 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
93 return ScriptWrappable::getUnsafeWrapperFromObject(object).handle(); 93 return ScriptWrappable::getUnsafeWrapperFromObject(object).handle();
94 return mainWorldStore()->get(object); 94 return mainWorldStore()->template get<V8T>(object);
95 } 95 }
96 96
97 template<typename T> 97 template<typename V8T, typename T>
98 static void setWrapper(T* object, v8::Handle<v8::Object> wrapper, v8::Isolat e* isolate, const WrapperConfiguration& configuration) 98 static void setWrapper(T* object, v8::Handle<v8::Object> wrapper, v8::Isolat e* isolate, const WrapperConfiguration& configuration)
99 { 99 {
100 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) { 100 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) {
101 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) { 101 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) {
102 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, co nfiguration); 102 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, co nfiguration);
103 return; 103 return;
104 } 104 }
105 } 105 }
106 return current(isolate)->set(object, wrapper, isolate, configuration); 106 return current(isolate)->template set<V8T>(object, wrapper, isolate, con figuration);
107 } 107 }
108 108
109 template<typename T> 109 template<typename V8T, typename T>
110 inline v8::Handle<v8::Object> get(T* object) 110 inline v8::Handle<v8::Object> get(T* object)
111 { 111 {
112 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai nWorld) 112 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai nWorld)
113 return ScriptWrappable::getUnsafeWrapperFromObject(object).handle(); 113 return ScriptWrappable::getUnsafeWrapperFromObject(object).handle();
114 return m_wrapperMap.get(object); 114 return m_wrapperMap.get(V8T::toInternalPointer(object));
115 } 115 }
116 116
117 void reportMemoryUsage(MemoryObjectInfo*) const; 117 void reportMemoryUsage(MemoryObjectInfo*) const;
118 118
119 private: 119 private:
120 template<typename T> 120 template<typename V8T, typename T>
121 inline void set(T* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isol ate, const WrapperConfiguration& configuration) 121 inline void set(T* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isol ate, const WrapperConfiguration& configuration)
122 { 122 {
123 ASSERT(!!object); 123 ASSERT(!!object);
124 ASSERT(!wrapper.IsEmpty()); 124 ASSERT(!wrapper.IsEmpty());
125 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai nWorld) { 125 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai nWorld) {
126 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, config uration); 126 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, config uration);
127 return; 127 return;
128 } 128 }
129 m_wrapperMap.set(object, wrapper, configuration); 129 m_wrapperMap.set(V8T::toInternalPointer(object), wrapper, configuration) ;
130 } 130 }
131 131
132 static DOMDataStore* mainWorldStore(); 132 static DOMDataStore* mainWorldStore();
133 133
134 static bool canExistInWorker(void*) { return true; } 134 static bool canExistInWorker(void*) { return true; }
135 static bool canExistInWorker(Node*) { return false; } 135 static bool canExistInWorker(Node*) { return false; }
136 136
137 template<typename HolderContainer> 137 template<typename HolderContainer>
138 static bool holderContainsWrapper(const HolderContainer&, void*) 138 static bool holderContainsWrapper(const HolderContainer&, void*)
139 { 139 {
140 return false; 140 return false;
141 } 141 }
142 142
143 template<typename HolderContainer> 143 template<typename HolderContainer>
144 static bool holderContainsWrapper(const HolderContainer& container, ScriptWr appable* wrappable) 144 static bool holderContainsWrapper(const HolderContainer& container, ScriptWr appable* wrappable)
145 { 145 {
146 // Verify our assumptions about the main world. 146 // Verify our assumptions about the main world.
147 ASSERT(wrappable->unsafePersistent().handle().IsEmpty() || container.Hol der() != wrappable->unsafePersistent().handle() || current(v8::Isolate::GetCurre nt())->m_type == MainWorld); 147 ASSERT(wrappable->unsafePersistent().handle().IsEmpty() || container.Hol der() != wrappable->unsafePersistent().handle() || current(v8::Isolate::GetCurre nt())->m_type == MainWorld);
148 return container.Holder() == wrappable->unsafePersistent().handle(); 148 return container.Holder() == wrappable->unsafePersistent().handle();
149 } 149 }
150 150
151 WrapperWorldType m_type; 151 WrapperWorldType m_type;
152 DOMWrapperMap<void> m_wrapperMap; 152 DOMWrapperMap<void> m_wrapperMap;
153 }; 153 };
154 154
155 } // namespace WebCore 155 } // namespace WebCore
156 156
157 #endif // DOMDataStore_h 157 #endif // DOMDataStore_h
OLDNEW
« no previous file with comments | « Source/bindings/v8/CustomElementWrapper.cpp ('k') | Source/bindings/v8/SerializedScriptValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698