Chromium Code Reviews| Index: src/handles.h | 
| diff --git a/src/handles.h b/src/handles.h | 
| index d95ca9117022d8d33c3bdfc5cc9dc32c8e7762e5..b038c1f34c1eb96d00ddc68c7b30a428154d72c3 100644 | 
| --- a/src/handles.h | 
| +++ b/src/handles.h | 
| @@ -39,7 +39,7 @@ namespace internal { | 
| // Handles are only valid within a HandleScope. | 
| // When a handle is created for an object a cell is allocated in the heap. | 
| -template<class T> | 
| +template<typename T> | 
| class Handle { | 
| public: | 
| INLINE(explicit Handle(T** location)) { location_ = location; } | 
| @@ -93,6 +93,54 @@ class Handle { | 
| }; | 
| +// A handle-scope based variable. The value stored in the variable can change | 
| +// over time. The value stored in the variable at any time is a root | 
| +// for garbage collection. | 
| +// The variable is backed by the current HandleScope. | 
| +template <typename T> | 
| +class RootVar { | 
| 
 
Erik Corry
2011/02/24 10:36:57
I think I would prefer MutableHandle as a name wit
 
Lasse Reichstein
2011/02/24 13:44:41
Renamed to HandleCell.
The name MutableHandle seem
 
 | 
| + public: | 
| + // Create a new RootVar holding the given value. | 
| + explicit RootVar(Handle<T> value); | 
| + explicit RootVar(T* value); | 
| + | 
| + // Create an alias of an existing RootVar. | 
| + explicit RootVar(const RootVar<T>& value) : location_(value.location_) { } | 
| + | 
| + INLINE(T* operator->() const) { return operator*(); } | 
| + INLINE(T* operator*() const) { | 
| + return *location_; | 
| + } | 
| + INLINE(void operator=(T* value)) { | 
| + *location_ = value; | 
| + } | 
| + INLINE(void operator=(Handle<T> value)) { | 
| 
 
Erik Corry
2011/02/24 10:36:57
Would it be premature generalization to provide th
 
Lasse Reichstein
2011/02/24 13:44:41
I would prefer only having explicit ways to extrac
 
 | 
| + *location_ = *value; | 
| + } | 
| + INLINE(void operator=(const RootVar<T>& value)) { | 
| + *location_ = *value.location_; | 
| + } | 
| + | 
| + // Extract the value of the variable and cast it to a give type. | 
| + // This is typically used for calling methods on a more specialized type. | 
| + template <typename S> | 
| + inline S* cast() { | 
| + S::cast(*location_); | 
| + return *reinterpret_cast<S**>(location_); | 
| + } | 
| + | 
| + Handle<T> ToHandle() const { | 
| + return Handle<T>(*location_); | 
| + } | 
| + | 
| + private: | 
| + // Prevent implicit constructor from being created. | 
| + RootVar(); | 
| + | 
| + T** location_; | 
| +}; | 
| + | 
| + | 
| // A stack-allocated class that governs a number of local handles. | 
| // After a handle scope has been created, all local handles will be | 
| // allocated within that handle scope until either the handle scope is |