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

Side by Side Diff: Source/bindings/core/v8/ScriptWrappable.h

Issue 456683002: bindings: Introduces type-check for the internal pointers. (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
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 * 50 *
51 * This class provides the internal pointer to be stored in the wrapper objects, 51 * This class provides the internal pointer to be stored in the wrapper objects,
52 * and its conversions from / to the DOM instances. 52 * and its conversions from / to the DOM instances.
53 * 53 *
54 * Note that this class must not have vtbl (any virtual function) or any member 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 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. 56 * to the size inherit from this class. So this class must be zero size.
57 */ 57 */
58 class ScriptWrappableBase { 58 class ScriptWrappableBase {
59 public: 59 public:
60 template <class T> static T* fromInternalPointer(void* internalPointer) 60 template <class T> static T* fromInternalPointer(ScriptWrappableBase* intern alPointer)
61 { 61 {
62 // Check if T* is castable to ScriptWrappableBase*, which means T 62 // Check if T* is castable to ScriptWrappableBase*, which means T
63 // doesn't have two or more ScriptWrappableBase as superclasses. 63 // doesn't have two or more ScriptWrappableBase as superclasses.
64 // If T has two ScriptWrappableBase as superclasses, conversions 64 // If T has two ScriptWrappableBase as superclasses, conversions
65 // from T* to ScriptWrappableBase* are ambiguous. 65 // from T* to ScriptWrappableBase* are ambiguous.
66 ASSERT(static_cast<ScriptWrappableBase*>(static_cast<T*>(static_cast<Scr iptWrappableBase*>(internalPointer)))); 66 ASSERT(static_cast<ScriptWrappableBase*>(static_cast<T*>(internalPointer )));
67 return static_cast<T*>(static_cast<ScriptWrappableBase*>(internalPointer )); 67 return static_cast<T*>(internalPointer);
68 } 68 }
69 void* toInternalPointer() { return this; } 69 ScriptWrappableBase* toInternalPointer() { return this; }
70 }; 70 };
71 71
72 /** 72 /**
73 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo. 73 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo.
74 * 74 *
75 * 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
76 * 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
77 * object or an actual v8 persistent (or is empty). 77 * object or an actual v8 persistent (or is empty).
78 * 78 *
79 * The physical state space of ScriptWrappable is: 79 * The physical state space of ScriptWrappable is:
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed 298 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed
299 // inside data.GetParameter()->deref(), which causes Node destructions. We should 299 // inside data.GetParameter()->deref(), which causes Node destructions. We should
300 // make Node destructions incremental. 300 // make Node destructions incremental.
301 releaseObject(data.GetValue()); 301 releaseObject(data.GetValue());
302 } 302 }
303 }; 303 };
304 304
305 } // namespace blink 305 } // namespace blink
306 306
307 #endif // ScriptWrappable_h 307 #endif // ScriptWrappable_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698