| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Check if this handle refers to the exact same object as the other handle. | 66 // Check if this handle refers to the exact same object as the other handle. |
| 67 INLINE(bool is_identical_to(const Handle<T> other) const); | 67 INLINE(bool is_identical_to(const Handle<T> other) const); |
| 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. |
| 73 INLINE(T** location() const); | 73 INLINE(T** location() const); |
| 74 | 74 |
| 75 template <class S> static Handle<T> cast(Handle<S> that) { | 75 template <class S> static Handle<T> cast(Handle<S> that) { |
| 76 T::cast(*that); | 76 T::cast(*reinterpret_cast<T**>(that.location_)); |
| 77 return Handle<T>(reinterpret_cast<T**>(that.location())); | 77 return Handle<T>(reinterpret_cast<T**>(that.location_)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 static Handle<T> null() { return Handle<T>(); } | 80 static Handle<T> null() { return Handle<T>(); } |
| 81 bool is_null() const { return location_ == NULL; } | 81 bool is_null() const { return location_ == NULL; } |
| 82 | 82 |
| 83 // Closes the given scope, but lets this handle escape. See | 83 // Closes the given scope, but lets this handle escape. See |
| 84 // implementation in api.h. | 84 // implementation in api.h. |
| 85 inline Handle<T> EscapeFrom(v8::HandleScope* scope); | 85 inline Handle<T> EscapeFrom(v8::HandleScope* scope); |
| 86 | 86 |
| 87 #ifdef DEBUG |
| 88 bool IsDereferenceAllowed(bool allow_deferred) const; |
| 89 #endif // DEBUG |
| 90 |
| 87 private: | 91 private: |
| 88 T** location_; | 92 T** location_; |
| 89 | 93 |
| 90 // Handles of different classes are allowed to access each other's location_. | 94 // Handles of different classes are allowed to access each other's location_. |
| 91 template<class S> friend class Handle; | 95 template<class S> friend class Handle; |
| 92 }; | 96 }; |
| 93 | 97 |
| 94 | 98 |
| 95 // Convenience wrapper. | 99 // Convenience wrapper. |
| 96 template<class T> | 100 template<class T> |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 private: | 338 private: |
| 335 Isolate* isolate_; | 339 Isolate* isolate_; |
| 336 int level_; | 340 int level_; |
| 337 bool active_; | 341 bool active_; |
| 338 #endif | 342 #endif |
| 339 }; | 343 }; |
| 340 | 344 |
| 341 | 345 |
| 342 class HandleDereferenceGuard BASE_EMBEDDED { | 346 class HandleDereferenceGuard BASE_EMBEDDED { |
| 343 public: | 347 public: |
| 344 enum State { ALLOW, DISALLOW }; | 348 enum State { ALLOW, DISALLOW, DISALLOW_DEFERRED }; |
| 345 #ifndef DEBUG | 349 #ifndef DEBUG |
| 346 HandleDereferenceGuard(Isolate* isolate, State state) { } | 350 HandleDereferenceGuard(Isolate* isolate, State state) { } |
| 347 ~HandleDereferenceGuard() { } | 351 ~HandleDereferenceGuard() { } |
| 348 #else | 352 #else |
| 349 inline HandleDereferenceGuard(Isolate* isolate, State state); | 353 inline HandleDereferenceGuard(Isolate* isolate, State state); |
| 350 inline ~HandleDereferenceGuard(); | 354 inline ~HandleDereferenceGuard(); |
| 351 private: | 355 private: |
| 352 Isolate* isolate_; | 356 Isolate* isolate_; |
| 353 bool old_state_; | 357 State old_state_; |
| 354 #endif | 358 #endif |
| 355 }; | 359 }; |
| 356 | 360 |
| 361 #ifdef DEBUG |
| 362 #define ALLOW_HANDLE_DEREF(isolate, why_this_is_safe) \ |
| 363 HandleDereferenceGuard allow_deref(isolate, \ |
| 364 HandleDereferenceGuard::ALLOW); |
| 365 #else |
| 366 #define ALLOW_HANDLE_DEREF(isolate, why_this_is_safe) |
| 367 #endif // DEBUG |
| 368 |
| 357 } } // namespace v8::internal | 369 } } // namespace v8::internal |
| 358 | 370 |
| 359 #endif // V8_HANDLES_H_ | 371 #endif // V8_HANDLES_H_ |
| OLD | NEW |