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

Side by Side 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, 4 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
« no previous file with comments | « no previous file | Source/bindings/core/v8/ScriptWrappable.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 28 matching lines...) Expand all
39 // Helper to call webCoreInitializeScriptWrappableForInterface in the global nam espace. 39 // Helper to call webCoreInitializeScriptWrappableForInterface in the global nam espace.
40 template <class C> inline void initializeScriptWrappableHelper(C* object) 40 template <class C> inline void initializeScriptWrappableHelper(C* object)
41 { 41 {
42 void webCoreInitializeScriptWrappableForInterface(C*); 42 void webCoreInitializeScriptWrappableForInterface(C*);
43 webCoreInitializeScriptWrappableForInterface(object); 43 webCoreInitializeScriptWrappableForInterface(object);
44 } 44 }
45 45
46 namespace blink { 46 namespace blink {
47 47
48 /** 48 /**
49 * The base class of all wrappable objects.
50 *
51 * This class provides the internal pointer to be stored in the wrapper objects,
52 * and its conversions from / to the DOM instances.
53 *
54 * Note that this class must not have vtbl (any virtual function) or any member
55 * variable which increase the size of instances. Some of the classes sensitive
56 * to the size inherit from this class. So this class must be zero size.
57 */
58 class ScriptWrappableBase {
59 public:
60 template <class T> static T* fromInternalPointer(void* internalPointer)
61 {
62 // Check if T* is castable to ScriptWrappableBase*, which means T
63 // doesn't have two or more ScriptWrappableBase as superclasses.
64 // If T has two ScriptWrappableBase as superclasses, conversions
65 // from T* to ScriptWrappableBase* are ambiguous.
66 ASSERT(static_cast<ScriptWrappableBase*>(static_cast<T*>(static_cast<Scr iptWrappableBase*>(internalPointer))));
67 return static_cast<T*>(static_cast<ScriptWrappableBase*>(internalPointer ));
68 }
69 void* toInternalPointer() { return this; }
70 };
71
72 /**
49 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo. 73 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo.
50 * 74 *
51 * ScriptWrappable acts much like a v8::Persistent<> in that it keeps a 75 * ScriptWrappable acts much like a v8::Persistent<> in that it keeps a
52 * V8 object alive. Under the hood, however, it keeps either a TypeInfo 76 * V8 object alive. Under the hood, however, it keeps either a TypeInfo
53 * object or an actual v8 persistent (or is empty). 77 * object or an actual v8 persistent (or is empty).
54 * 78 *
55 * The physical state space of ScriptWrappable is: 79 * The physical state space of ScriptWrappable is:
56 * - uintptr_t m_wrapperOrTypeInfo; 80 * - uintptr_t m_wrapperOrTypeInfo;
57 * - if 0: the ScriptWrappable is uninitialized/empty. 81 * - if 0: the ScriptWrappable is uninitialized/empty.
58 * - if even: a pointer to blink::TypeInfo 82 * - if even: a pointer to blink::TypeInfo
59 * - if odd: a pointer to v8::Persistent<v8::Object> + 1. 83 * - if odd: a pointer to v8::Persistent<v8::Object> + 1.
60 * 84 *
61 * In other words, one integer represents one of two object pointers, 85 * In other words, one integer represents one of two object pointers,
62 * depending on its least signficiant bit, plus an uninitialized state. 86 * depending on its least signficiant bit, plus an uninitialized state.
63 * This class is meant to mask the logistics behind this. 87 * This class is meant to mask the logistics behind this.
64 * 88 *
65 * typeInfo() and newLocalWrapper will return appropriate values (possibly 89 * typeInfo() and newLocalWrapper will return appropriate values (possibly
66 * 0/empty) in all physical states. 90 * 0/empty) in all physical states.
67 * 91 *
68 * The state transitions are: 92 * The state transitions are:
69 * - new: an empty and invalid ScriptWrappable. 93 * - new: an empty and invalid ScriptWrappable.
70 * - init (to be called by all subclasses in their constructor): 94 * - init (to be called by all subclasses in their constructor):
71 * needs to call setTypeInfo 95 * needs to call setTypeInfo
72 * - setTypeInfo: install a WrapperTypeInfo 96 * - setTypeInfo: install a WrapperTypeInfo
73 * - setWrapper: install a v8::Persistent (or empty) 97 * - setWrapper: install a v8::Persistent (or empty)
74 * - disposeWrapper (via setWeakCallback, triggered by V8 garbage collecter): 98 * - disposeWrapper (via setWeakCallback, triggered by V8 garbage collecter):
75 * remove v8::Persistent and install a TypeInfo of the previous value. 99 * remove v8::Persistent and install a TypeInfo of the previous value.
76 */ 100 */
77 class ScriptWrappable { 101 class ScriptWrappable : public ScriptWrappableBase {
78 public: 102 public:
79 ScriptWrappable() : m_wrapperOrTypeInfo(0) { } 103 ScriptWrappable() : m_wrapperOrTypeInfo(0) { }
80 104
81 // Wrappables need to be initialized with their most derrived type for which 105 // Wrappables need to be initialized with their most derrived type for which
82 // bindings exist, in much the same way that certain other types need to be 106 // bindings exist, in much the same way that certain other types need to be
83 // adopted and so forth. The overloaded initializeScriptWrappableForInterfac e() 107 // adopted and so forth. The overloaded initializeScriptWrappableForInterfac e()
84 // functions are implemented by the generated V8 bindings code. Declaring th e 108 // functions are implemented by the generated V8 bindings code. Declaring th e
85 // extern function in the template avoids making a centralized header of all 109 // extern function in the template avoids making a centralized header of all
86 // the bindings in the universe. C++11's extern template feature may provide 110 // the bindings in the universe. C++11's extern template feature may provide
87 // a cleaner solution someday. 111 // a cleaner solution someday.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed 299 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed
276 // inside data.GetParameter()->deref(), which causes Node destructions. We should 300 // inside data.GetParameter()->deref(), which causes Node destructions. We should
277 // make Node destructions incremental. 301 // make Node destructions incremental.
278 releaseObject(data.GetValue()); 302 releaseObject(data.GetValue());
279 } 303 }
280 }; 304 };
281 305
282 } // namespace blink 306 } // namespace blink
283 307
284 #endif // ScriptWrappable_h 308 #endif // ScriptWrappable_h
OLDNEW
« 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