Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 137 lines (102 sloc) 3.419 kB
60818b9 @ry Add missing copyright headers
ry authored
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
0c7bf81 @ry Abstract out HandleWrap class
ry authored
22 #include <node.h>
23 #include <handle_wrap.h>
24
25 namespace node {
26
27 using v8::Object;
28 using v8::Handle;
29 using v8::Local;
30 using v8::Persistent;
31 using v8::Value;
32 using v8::HandleScope;
33 using v8::FunctionTemplate;
34 using v8::String;
35 using v8::Function;
36 using v8::TryCatch;
37 using v8::Context;
38 using v8::Arguments;
39 using v8::Integer;
40
41
42 #define UNWRAP \
43 assert(!args.Holder().IsEmpty()); \
44 assert(args.Holder()->InternalFieldCount() > 0); \
45 HandleWrap* wrap = \
46 static_cast<HandleWrap*>(args.Holder()->GetPointerFromInternalField(0)); \
47 if (!wrap) { \
6cc4292 @ry Display sys_errno when UV_UNKNOWN is returned
ry authored
48 uv_err_t err; \
49 err.code = UV_EBADF; \
50 SetErrno(err); \
0c7bf81 @ry Abstract out HandleWrap class
ry authored
51 return scope.Close(Integer::New(-1)); \
52 }
53
54
55 void HandleWrap::Initialize(Handle<Object> target) {
56 /* Doesn't do anything at the moment. */
57 }
58
59
7e62bc9 @ry Move process.stdout unref hack to handle_wrap.cc
ry authored
60 // This function is used only for process.stdout. It's put here instead of
61 // in TTYWrap because here we have access to the Close binding.
62 Handle<Value> HandleWrap::Unref(const Arguments& args) {
63 HandleScope scope;
64
65 UNWRAP
66
67 // Calling this function twice should never happen.
68 assert(wrap->unref == false);
69
70 wrap->unref = true;
71 uv_unref(uv_default_loop());
72
73 return v8::Undefined();
74 }
75
76
0c7bf81 @ry Abstract out HandleWrap class
ry authored
77 Handle<Value> HandleWrap::Close(const Arguments& args) {
78 HandleScope scope;
79
80 UNWRAP
81
82 assert(!wrap->object_.IsEmpty());
133036f @ry upgrade libuv to 6e50576
ry authored
83 uv_close(wrap->handle__, OnClose);
0c7bf81 @ry Abstract out HandleWrap class
ry authored
84
7e62bc9 @ry Move process.stdout unref hack to handle_wrap.cc
ry authored
85 if (wrap->unref) {
86 uv_ref(uv_default_loop());
87 wrap->unref = false;
88 }
89
0c7bf81 @ry Abstract out HandleWrap class
ry authored
90 wrap->StateChange();
91
133036f @ry upgrade libuv to 6e50576
ry authored
92 return v8::Null();
0c7bf81 @ry Abstract out HandleWrap class
ry authored
93 }
94
95
96 HandleWrap::HandleWrap(Handle<Object> object, uv_handle_t* h) {
7e62bc9 @ry Move process.stdout unref hack to handle_wrap.cc
ry authored
97 unref = false;
0c7bf81 @ry Abstract out HandleWrap class
ry authored
98 handle__ = h;
187fe27 stdio binding + javascript to enable process.stdin.listen()
Igor Zinkovsky authored
99 if (h) {
100 h->data = this;
101 }
0c7bf81 @ry Abstract out HandleWrap class
ry authored
102
103 HandleScope scope;
104 assert(object_.IsEmpty());
105 assert(object->InternalFieldCount() > 0);
106 object_ = v8::Persistent<v8::Object>::New(object);
107 object_->SetPointerInInternalField(0, this);
108 }
109
110
187fe27 stdio binding + javascript to enable process.stdin.listen()
Igor Zinkovsky authored
111 void HandleWrap::SetHandle(uv_handle_t* h) {
112 handle__ = h;
113 h->data = this;
114 }
115
116
0c7bf81 @ry Abstract out HandleWrap class
ry authored
117 HandleWrap::~HandleWrap() {
118 assert(object_.IsEmpty());
119 }
120
121
122 void HandleWrap::OnClose(uv_handle_t* handle) {
123 HandleWrap* wrap = static_cast<HandleWrap*>(handle->data);
124
125 // The wrap object should still be there.
126 assert(wrap->object_.IsEmpty() == false);
127
128 wrap->object_->SetPointerInInternalField(0, NULL);
129 wrap->object_.Dispose();
130 wrap->object_.Clear();
131
132 delete wrap;
133 }
134
135
136 } // namespace node
Something went wrong with that request. Please try again.