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

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: 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 return static_cast<T*>(static_cast<ScriptWrappableBase*>(internalPointer ));
kouhei (in TOK) 2014/07/28 13:40:05 As previously discussed, woudl it be possible to a
Yuki 2014/07/28 15:26:03 Done.
63 }
64 void* toInternalPointer() { return this; }
65 };
66
67 /**
49 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo. 68 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo.
50 * 69 *
51 * ScriptWrappable acts much like a v8::Persistent<> in that it keeps a 70 * 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 71 * V8 object alive. Under the hood, however, it keeps either a TypeInfo
53 * object or an actual v8 persistent (or is empty). 72 * object or an actual v8 persistent (or is empty).
54 * 73 *
55 * The physical state space of ScriptWrappable is: 74 * The physical state space of ScriptWrappable is:
56 * - uintptr_t m_wrapperOrTypeInfo; 75 * - uintptr_t m_wrapperOrTypeInfo;
57 * - if 0: the ScriptWrappable is uninitialized/empty. 76 * - if 0: the ScriptWrappable is uninitialized/empty.
58 * - if even: a pointer to blink::TypeInfo 77 * - if even: a pointer to blink::TypeInfo
59 * - if odd: a pointer to v8::Persistent<v8::Object> + 1. 78 * - if odd: a pointer to v8::Persistent<v8::Object> + 1.
60 * 79 *
61 * In other words, one integer represents one of two object pointers, 80 * In other words, one integer represents one of two object pointers,
62 * depending on its least signficiant bit, plus an uninitialized state. 81 * depending on its least signficiant bit, plus an uninitialized state.
63 * This class is meant to mask the logistics behind this. 82 * This class is meant to mask the logistics behind this.
64 * 83 *
65 * typeInfo() and newLocalWrapper will return appropriate values (possibly 84 * typeInfo() and newLocalWrapper will return appropriate values (possibly
66 * 0/empty) in all physical states. 85 * 0/empty) in all physical states.
67 * 86 *
68 * The state transitions are: 87 * The state transitions are:
69 * - new: an empty and invalid ScriptWrappable. 88 * - new: an empty and invalid ScriptWrappable.
70 * - init (to be called by all subclasses in their constructor): 89 * - init (to be called by all subclasses in their constructor):
71 * needs to call setTypeInfo 90 * needs to call setTypeInfo
72 * - setTypeInfo: install a WrapperTypeInfo 91 * - setTypeInfo: install a WrapperTypeInfo
73 * - setWrapper: install a v8::Persistent (or empty) 92 * - setWrapper: install a v8::Persistent (or empty)
74 * - disposeWrapper (via setWeakCallback, triggered by V8 garbage collecter): 93 * - disposeWrapper (via setWeakCallback, triggered by V8 garbage collecter):
75 * remove v8::Persistent and install a TypeInfo of the previous value. 94 * remove v8::Persistent and install a TypeInfo of the previous value.
76 */ 95 */
77 class ScriptWrappable { 96 class ScriptWrappable : public ScriptWrappableBase {
78 public: 97 public:
79 ScriptWrappable() : m_wrapperOrTypeInfo(0) { } 98 ScriptWrappable() : m_wrapperOrTypeInfo(0) { }
80 99
81 // Wrappables need to be initialized with their most derrived type for which 100 // 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 101 // bindings exist, in much the same way that certain other types need to be
83 // adopted and so forth. The overloaded initializeScriptWrappableForInterfac e() 102 // adopted and so forth. The overloaded initializeScriptWrappableForInterfac e()
84 // functions are implemented by the generated V8 bindings code. Declaring th e 103 // 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 104 // 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 105 // the bindings in the universe. C++11's extern template feature may provide
87 // a cleaner solution someday. 106 // 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 294 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed
276 // inside data.GetParameter()->deref(), which causes Node destructions. We should 295 // inside data.GetParameter()->deref(), which causes Node destructions. We should
277 // make Node destructions incremental. 296 // make Node destructions incremental.
278 releaseObject(data.GetValue()); 297 releaseObject(data.GetValue());
279 } 298 }
280 }; 299 };
281 300
282 } // namespace blink 301 } // namespace blink
283 302
284 #endif // ScriptWrappable_h 303 #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