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

Unified Diff: src/handles.h

Issue 6592007: Port revision 6934 and 6993 (plus fix from 6935) to the 3.0 branch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/3.0
Patch Set: Created 9 years, 10 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 | « src/array.js ('k') | src/handles-inl.h » ('j') | src/runtime.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/handles.h
diff --git a/src/handles.h b/src/handles.h
index aa9d8b99995a13db4076e0c4c9c748875100f993..0ce267202a6942c8c5caca968569a1e2202d8002 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,55 @@ class Handle {
};
+// A handle-scope based variable. The value stored in the variable can change
Mads Ager (chromium) 2011/02/28 08:11:20 Please do not introduce a new abstraction for this
+// 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 HandleCell {
+ public:
+ // Create a new HandleCell holding the given value.
+ explicit HandleCell(Handle<T> value);
+ explicit HandleCell(T* value);
+
+ // Create an alias of an existing HandleCell.
+ explicit HandleCell(const HandleCell<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)) {
+ *location_ = *value;
+ }
+ INLINE(void operator=(const HandleCell<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.
+ HandleCell();
+
+ 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
« no previous file with comments | « src/array.js ('k') | src/handles-inl.h » ('j') | src/runtime.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698