src: deduplicate CHECK_EQ/CHECK_NE macros
[platform/upstream/nodejs.git] / src / base-object.h
1 // Copyright Joyent, Inc. and other Node contributors.
2 //
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:
10 //
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
13 //
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.
21
22 #ifndef SRC_BASE_OBJECT_H_
23 #define SRC_BASE_OBJECT_H_
24
25 #include "env.h"
26 #include "v8.h"
27
28 namespace node {
29
30 class BaseObject {
31  public:
32   BaseObject(Environment* env, v8::Local<v8::Object> handle);
33   ~BaseObject();
34
35   // Returns the wrapped object.  Illegal to call in your destructor.
36   inline v8::Local<v8::Object> object();
37
38   // Parent class is responsible to Dispose.
39   inline v8::Persistent<v8::Object>& persistent();
40
41   inline Environment* env() const;
42
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
47   // be set.
48   template <typename Type>
49   inline void MakeWeak(Type* ptr);
50
51   inline void ClearWeak();
52
53  private:
54   BaseObject();
55
56   template <typename Type>
57   static inline void WeakCallback(
58       const v8::WeakCallbackData<v8::Object, Type>& data);
59
60   v8::Persistent<v8::Object> handle_;
61   Environment* env_;
62 };
63
64 }  // namespace node
65
66 #endif  // SRC_BASE_OBJECT_H_