OLD | NEW |
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 24 matching lines...) Expand all Loading... |
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<class T> |
43 class Handle { | 43 class Handle { |
44 public: | 44 public: |
45 INLINE(Handle(T** location)) { location_ = location; } | 45 INLINE(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) { |
53 #ifdef DEBUG | 53 #ifdef DEBUG |
54 T* a = NULL; | 54 T* a = NULL; |
55 S* b = NULL; | 55 S* b = NULL; |
56 a = b; // Fake assignment to enforce type checks. | 56 a = b; // Fake assignment to enforce type checks. |
57 USE(a); | 57 USE(a); |
58 #endif | 58 #endif |
59 location_ = reinterpret_cast<T**>(handle.location()); | 59 location_ = reinterpret_cast<T**>(handle.location()); |
60 } | 60 } |
61 | 61 |
62 INLINE(T* operator ->() const) { return operator*(); } | 62 INLINE(T* operator ->() const) { return operator*(); } |
63 | 63 |
64 // Check if this handle refers to the exact same object as the other handle. | 64 // Check if this handle refers to the exact same object as the other handle. |
65 bool is_identical_to(const Handle<T> other) const { | 65 bool is_identical_to(const Handle<T> other) const { |
66 return operator*() == *other; | 66 return operator*() == *other; |
67 } | 67 } |
68 | 68 |
69 // Provides the C++ dereference operator. | 69 // Provides the C++ dereference operator. |
70 INLINE(T* operator*() const); | 70 INLINE(T* operator*() const); |
71 | 71 |
72 // Returns the address to where the raw pointer is stored. | 72 // Returns the address to where the raw pointer is stored. |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 private: | 341 private: |
342 bool has_been_transformed_; // Tells whether the object has been transformed. | 342 bool has_been_transformed_; // Tells whether the object has been transformed. |
343 int unused_property_fields_; // Captures the unused number of field. | 343 int unused_property_fields_; // Captures the unused number of field. |
344 Handle<JSObject> object_; // The object being optimized. | 344 Handle<JSObject> object_; // The object being optimized. |
345 }; | 345 }; |
346 | 346 |
347 | 347 |
348 } } // namespace v8::internal | 348 } } // namespace v8::internal |
349 | 349 |
350 #endif // V8_HANDLES_H_ | 350 #endif // V8_HANDLES_H_ |
OLD | NEW |