summaryrefslogtreecommitdiff
path: root/src/udp_wrap.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/udp_wrap.cc')
-rw-r--r--src/udp_wrap.cc17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc
index d4761493cb..6d01ebd6f3 100644
--- a/src/udp_wrap.cc
+++ b/src/udp_wrap.cc
@@ -40,6 +40,7 @@ typedef ReqWrap<uv_udp_send_t> SendWrap;
// see tcp_wrap.cc
Local<Object> AddressToJS(const sockaddr* addr);
+static Persistent<Function> constructor;
static Persistent<String> buffer_sym;
static Persistent<String> oncomplete_sym;
static Persistent<String> onmessage_sym;
@@ -98,8 +99,9 @@ void UDPWrap::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "ref", HandleWrap::Ref);
NODE_SET_PROTOTYPE_METHOD(t, "unref", HandleWrap::Unref);
- target->Set(String::NewSymbol("UDP"),
- Persistent<FunctionTemplate>::New(t)->GetFunction());
+ constructor = Persistent<Function>::New(
+ Persistent<FunctionTemplate>::New(t)->GetFunction());
+ target->Set(String::NewSymbol("UDP"), constructor);
}
@@ -392,6 +394,17 @@ UDPWrap* UDPWrap::Unwrap(Local<Object> obj) {
}
+Local<Object> UDPWrap::Instantiate() {
+ // If this assert fires then Initialize hasn't been called yet.
+ assert(constructor.IsEmpty() == false);
+
+ HandleScope scope;
+ Local<Object> obj = constructor->NewInstance();
+
+ return scope.Close(obj);
+}
+
+
uv_udp_t* UDPWrap::UVHandle() {
return &handle_;
}