2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef DOMDataStore_h
32 #define DOMDataStore_h
34 #include "DOMWrapperMap.h"
37 #include <wtf/HashMap.h>
38 #include <wtf/MainThread.h>
39 #include <wtf/Noncopyable.h>
40 #include <wtf/OwnPtr.h>
41 #include <wtf/StdLibExtras.h>
42 #include <wtf/Threading.h>
43 #include <wtf/ThreadSpecific.h>
44 #include <wtf/Vector.h>
49 WTF_MAKE_NONCOPYABLE(DOMDataStore);
57 explicit DOMDataStore(Type);
60 static DOMDataStore* current(v8::Isolate*);
63 inline v8::Handle<v8::Object> get(T* object)
65 if (wrapperIsStoredInObject(object))
66 return getWrapperFromObject(object);
67 return m_wrapperMap.get(object);
71 inline void set(T* object, v8::Persistent<v8::Object> wrapper)
73 if (setWrapperInObject(object, wrapper))
75 m_wrapperMap.set(object, wrapper);
78 void reportMemoryUsage(MemoryObjectInfo*) const;
81 bool wrapperIsStoredInObject(void*) const { return false; }
82 bool wrapperIsStoredInObject(ScriptWrappable*) const { return m_type == MainWorld; }
84 v8::Handle<v8::Object> getWrapperFromObject(void*) const
87 return v8::Handle<v8::Object>();
90 v8::Handle<v8::Object> getWrapperFromObject(ScriptWrappable* object) const
92 ASSERT(m_type == MainWorld);
93 return object->wrapper();
96 bool setWrapperInObject(void*, v8::Persistent<v8::Object>) { return false; }
97 bool setWrapperInObject(ScriptWrappable* object, v8::Persistent<v8::Object> wrapper)
99 if (m_type != MainWorld)
101 ASSERT(object->wrapper().IsEmpty());
102 object->setWrapper(wrapper);
103 wrapper.MakeWeak(object, weakCallback);
107 static void weakCallback(v8::Persistent<v8::Value>, void* context);
110 DOMWrapperMap<void> m_wrapperMap;
113 } // namespace WebCore
115 #endif // DOMDataStore_h