Node.js  v8.x
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine
base-object.h
Go to the documentation of this file.
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 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26 
27 #include "v8.h"
28 
29 namespace node {
30 
31 class Environment;
32 
33 class BaseObject {
34  public:
35  inline BaseObject(Environment* env, v8::Local<v8::Object> handle);
36  inline virtual ~BaseObject();
37 
38  // Returns the wrapped object. Returns an empty handle when
39  // persistent.IsEmpty() is true.
40  inline v8::Local<v8::Object> object();
41 
42  // The parent class is responsible for calling .Reset() on destruction
43  // when the persistent handle is strong because there is no way for
44  // BaseObject to know when the handle goes out of scope.
45  // Weak handles have been reset by the time the destructor runs but
46  // calling .Reset() again is harmless.
47  inline v8::Persistent<v8::Object>& persistent();
48 
49  inline Environment* env() const;
50 
51  // The handle_ must have an internal field count > 0, and the first
52  // index is reserved for a pointer to this class. This is an
53  // implicit requirement, but Node does not have a case where it's
54  // required that MakeWeak() be called and the internal field not
55  // be set.
56  template <typename Type>
57  inline void MakeWeak(Type* ptr);
58 
59  inline void ClearWeak();
60 
61  private:
62  BaseObject();
63 
64  template <typename Type>
65  static inline void WeakCallback(
66  const v8::WeakCallbackInfo<Type>& data);
67 
68  v8::Persistent<v8::Object> persistent_handle_;
69  Environment* env_;
70 };
71 
72 } // namespace node
73 
74 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
75 
76 #endif // SRC_BASE_OBJECT_H_
Environment *const env_
union node::cares_wrap::@8::CaresAsyncData::@0 data