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_HANDLE_WRAP_H_
23 #define SRC_HANDLE_WRAP_H_
35 // - Do not throw from handle methods. Set errno.
37 // - MakeCallback may only be made directly off the event loop.
38 // That is there can be no JavaScript stack frames underneith it.
39 // (Is there anyway to assert that?)
41 // - No use of v8::WeakReferenceCallback. The close callback signifies that
42 // we're done with a handle - external resources can be freed.
46 // - The uv_close_cb is used to free the c++ object. The close callback
47 // is not made into javascript land.
49 // - uv_ref, uv_unref counts are managed at this layer to avoid needless
50 // js/c++ boundary crossing. At the javascript layer that should all be
55 static void Close(const v8::FunctionCallbackInfo<v8::Value>& args);
56 static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args);
57 static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args);
59 inline uv_handle_t* GetHandle() { return handle__; }
62 HandleWrap(Environment* env,
63 v8::Handle<v8::Object> object,
65 virtual ~HandleWrap();
67 inline Environment* env() const {
71 inline v8::Local<v8::Object> object() {
72 return PersistentToLocal(env()->isolate(), persistent());
75 inline v8::Persistent<v8::Object>& persistent() {
80 friend void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>&);
81 static void OnClose(uv_handle_t* handle);
82 v8::Persistent<v8::Object> object_;
83 QUEUE handle_wrap_queue_;
84 Environment* const env_;
86 // Using double underscore due to handle_ member in tcp_wrap. Probably
87 // tcp_wrap should rename it's member to 'handle'.
88 uv_handle_t* handle__;
90 static const unsigned int kUnref = 1;
91 static const unsigned int kCloseCallback = 2;
98 #endif // SRC_HANDLE_WRAP_H_