1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef SRC_BASE_OBJECT_H_
23 #define SRC_BASE_OBJECT_H_
32 BaseObject(Environment* env, v8::Local<v8::Object> handle);
35 // Returns the wrapped object. Illegal to call in your destructor.
36 inline v8::Local<v8::Object> object();
38 // Parent class is responsible to Dispose.
39 inline v8::Persistent<v8::Object>& persistent();
41 inline Environment* env() const;
43 // The handle_ must have an internal field count > 0, and the first
44 // index is reserved for a pointer to this class. This is an
45 // implicit requirement, but Node does not have a case where it's
46 // required that MakeWeak() be called and the internal field not
48 template <typename Type>
49 inline void MakeWeak(Type* ptr);
51 inline void ClearWeak();
56 template <typename Type>
57 static inline void WeakCallback(
58 const v8::WeakCallbackData<v8::Object, Type>& data);
60 v8::Persistent<v8::Object> handle_;
66 #endif // SRC_BASE_OBJECT_H_