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

Unified Diff: Source/bindings/core/v8/ScriptWrappable.h

Issue 422873002: bindings: Introduces ScriptWrappableBase to provide the internal pointer. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed copyright notice. Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/bindings/core/v8/ScriptWrappable.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/v8/ScriptWrappable.h
diff --git a/Source/bindings/core/v8/ScriptWrappable.h b/Source/bindings/core/v8/ScriptWrappable.h
index b0e176c1f05a95e8a3b42cbfc1207c60a1992462..38ecd9bc24f6816dc9df1ac54e3368b84aded485 100644
--- a/Source/bindings/core/v8/ScriptWrappable.h
+++ b/Source/bindings/core/v8/ScriptWrappable.h
@@ -46,6 +46,30 @@ template <class C> inline void initializeScriptWrappableHelper(C* object)
namespace blink {
/**
+ * The base class of all wrappable objects.
+ *
+ * This class provides the internal pointer to be stored in the wrapper objects,
+ * and its conversions from / to the DOM instances.
+ *
+ * Note that this class must not have vtbl (any virtual function) or any member
+ * variable which increase the size of instances. Some of the classes sensitive
+ * to the size inherit from this class. So this class must be zero size.
+ */
+class ScriptWrappableBase {
+public:
+ template <class T> static T* fromInternalPointer(void* internalPointer)
+ {
+ // Check if T* is castable to ScriptWrappableBase*, which means T
+ // doesn't have two or more ScriptWrappableBase as superclasses.
+ // If T has two ScriptWrappableBase as superclasses, conversions
+ // from T* to ScriptWrappableBase* are ambiguous.
+ ASSERT(static_cast<ScriptWrappableBase*>(static_cast<T*>(static_cast<ScriptWrappableBase*>(internalPointer))));
+ return static_cast<T*>(static_cast<ScriptWrappableBase*>(internalPointer));
+ }
+ void* toInternalPointer() { return this; }
+};
+
+/**
* ScriptWrappable wraps a V8 object and its WrapperTypeInfo.
*
* ScriptWrappable acts much like a v8::Persistent<> in that it keeps a
@@ -74,7 +98,7 @@ namespace blink {
* - disposeWrapper (via setWeakCallback, triggered by V8 garbage collecter):
* remove v8::Persistent and install a TypeInfo of the previous value.
*/
-class ScriptWrappable {
+class ScriptWrappable : public ScriptWrappableBase {
public:
ScriptWrappable() : m_wrapperOrTypeInfo(0) { }
« no previous file with comments | « no previous file | Source/bindings/core/v8/ScriptWrappable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698