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

Side by Side Diff: src/handles.h

Issue 6568007: Fix array concat to follow the specification in the presence of element getters. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge/build-ia32
Patch Set: git utd 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/array.js ('k') | src/handles-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 21 matching lines...) Expand all
32 32
33 namespace v8 { 33 namespace v8 {
34 namespace internal { 34 namespace internal {
35 35
36 // ---------------------------------------------------------------------------- 36 // ----------------------------------------------------------------------------
37 // A Handle provides a reference to an object that survives relocation by 37 // A Handle provides a reference to an object that survives relocation by
38 // the garbage collector. 38 // the garbage collector.
39 // Handles are only valid within a HandleScope. 39 // Handles are only valid within a HandleScope.
40 // When a handle is created for an object a cell is allocated in the heap. 40 // When a handle is created for an object a cell is allocated in the heap.
41 41
42 template<class T> 42 template<typename T>
43 class Handle { 43 class Handle {
44 public: 44 public:
45 INLINE(explicit Handle(T** location)) { location_ = location; } 45 INLINE(explicit Handle(T** location)) { location_ = location; }
46 INLINE(explicit Handle(T* obj)); 46 INLINE(explicit Handle(T* obj));
47 47
48 INLINE(Handle()) : location_(NULL) {} 48 INLINE(Handle()) : location_(NULL) {}
49 49
50 // Constructor for handling automatic up casting. 50 // Constructor for handling automatic up casting.
51 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected. 51 // Ex. Handle<JSFunction> can be passed when Handle<Object> is expected.
52 template <class S> Handle(Handle<S> handle) { 52 template <class S> Handle(Handle<S> handle) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 // Closes the given scope, but lets this handle escape. See 87 // Closes the given scope, but lets this handle escape. See
88 // implementation in api.h. 88 // implementation in api.h.
89 inline Handle<T> EscapeFrom(v8::HandleScope* scope); 89 inline Handle<T> EscapeFrom(v8::HandleScope* scope);
90 90
91 private: 91 private:
92 T** location_; 92 T** location_;
93 }; 93 };
94 94
95 95
96 // A handle-scope based variable. The value stored in the variable can change
97 // over time. The value stored in the variable at any time is a root
98 // for garbage collection.
99 // The variable is backed by the current HandleScope.
100 template <typename T>
101 class HandleCell {
102 public:
103 // Create a new HandleCell holding the given value.
104 explicit HandleCell(Handle<T> value);
105 explicit HandleCell(T* value);
106
107 // Create an alias of an existing HandleCell.
108 explicit HandleCell(const HandleCell<T>& value)
109 : location_(value.location_) { }
110
111 INLINE(T* operator->() const) { return operator*(); }
112 INLINE(T* operator*() const) {
113 return *location_;
114 }
115 INLINE(void operator=(T* value)) {
116 *location_ = value;
117 }
118 INLINE(void operator=(Handle<T> value)) {
119 *location_ = *value;
120 }
121 INLINE(void operator=(const HandleCell<T>& value)) {
122 *location_ = *value.location_;
123 }
124
125 // Extract the value of the variable and cast it to a give type.
126 // This is typically used for calling methods on a more specialized type.
127 template <typename S>
128 inline S* cast() {
129 S::cast(*location_);
130 return *reinterpret_cast<S**>(location_);
131 }
132
133 Handle<T> ToHandle() const {
134 return Handle<T>(*location_);
135 }
136
137 private:
138 // Prevent implicit constructor from being created.
139 HandleCell();
140
141 T** location_;
142 };
143
144
96 // A stack-allocated class that governs a number of local handles. 145 // A stack-allocated class that governs a number of local handles.
97 // After a handle scope has been created, all local handles will be 146 // After a handle scope has been created, all local handles will be
98 // allocated within that handle scope until either the handle scope is 147 // allocated within that handle scope until either the handle scope is
99 // deleted or another handle scope is created. If there is already a 148 // deleted or another handle scope is created. If there is already a
100 // handle scope and a new one is created, all allocations will take 149 // handle scope and a new one is created, all allocations will take
101 // place in the new handle scope until it is deleted. After that, 150 // place in the new handle scope until it is deleted. After that,
102 // new handles will again be allocated in the original handle scope. 151 // new handles will again be allocated in the original handle scope.
103 // 152 //
104 // After the handle scope of a local handle has been deleted the 153 // After the handle scope of a local handle has been deleted the
105 // garbage collector will no longer track the object stored in the 154 // garbage collector will no longer track the object stored in the
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 private: 433 private:
385 bool has_been_transformed_; // Tells whether the object has been transformed. 434 bool has_been_transformed_; // Tells whether the object has been transformed.
386 int unused_property_fields_; // Captures the unused number of field. 435 int unused_property_fields_; // Captures the unused number of field.
387 Handle<JSObject> object_; // The object being optimized. 436 Handle<JSObject> object_; // The object being optimized.
388 }; 437 };
389 438
390 439
391 } } // namespace v8::internal 440 } } // namespace v8::internal
392 441
393 #endif // V8_HANDLES_H_ 442 #endif // V8_HANDLES_H_
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/handles-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698