Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from indutny/fix-prototype-not-handles

luv: fix prototype initialization/usage
  • Loading branch information...
commit b2934003f77f83ebbbe18c263d37284edd76bd14 2 parents 188de0c + ff3fa87
@creationix creationix authored
View
2  Makefile
@@ -40,7 +40,7 @@ build/%.o: src/%.cc build src/%.h ${DEPS}
g++ -g -Wall -Werror -c $< -o $@ -I${HTTPDIR} -I${UVDIR}/include -I${CANDIR}/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
build/canio: ${DEPS} ${LIBS}
- g++ -g -o build/canio ${LIBS} ${DEPS} -pthread -lrt
+ g++ -g -o build/canio ${LIBS} ${DEPS} -pthread
clean:
rm -rf build
2  deps/candor
@@ -1 +1 @@
-Subproject commit de95e65de8a39acf1b727775648dc09447c18418
+Subproject commit 0744cbbfd52a3733aa537c4fcb2cc4987b3f2660
View
10 src/luv_handle.cc
@@ -24,12 +24,12 @@ static Value* luv_close(uint32_t argc, Arguments& argv) {
return Nil::New();
}
-static Object* prototype;
+static Handle<Object> prototype;
Object* uv_handle_prototype() {
- if (prototype) return prototype;
- prototype = Object::New();
- new Handle<Object>(prototype);
+ if (!prototype.IsEmpty()) return *prototype;
+
+ prototype.Wrap(Object::New());
prototype->Set("close", Function::New(luv_close));
- return prototype;
+ return *prototype;
}
View
23 src/luv_stream.cc
@@ -8,18 +8,6 @@
using namespace candor;
-// TODO: remove when candor API has this.
-static Object* CloneObject(Object* original) {
- Object* clone = Object::New();
- Array* keys = original->Keys();
- int64_t i = keys->Length();
- while (i--) {
- Value* key = keys->Get(i);
- clone->Set(key, original->Get(key));
- }
- return clone;
-}
-
static void luv_on_shutdown(uv_shutdown_t* req, int status) {
Object* obj = (Object*)req->data;
Value* callback = obj->Get("onShutdown");
@@ -164,11 +152,11 @@ static Value* luv_is_writable(uint32_t argc, Arguments& argv) {
Boolean::False();
}
-static Object* prototype;
+static Handle<Object> prototype;
Object* uv_stream_prototype() {
- if (prototype) return prototype;
- prototype = CloneObject(uv_handle_prototype());
- new Handle<Object>(prototype);
+ if (!prototype.IsEmpty()) return *prototype;
+
+ prototype.Wrap(uv_handle_prototype()->Clone());
prototype->Set("shutdown", Function::New(luv_shutdown));
prototype->Set("listen", Function::New(luv_listen));
prototype->Set("accept", Function::New(luv_accept));
@@ -177,6 +165,7 @@ Object* uv_stream_prototype() {
prototype->Set("write", Function::New(luv_write));
prototype->Set("isReadable", Function::New(luv_is_readable));
prototype->Set("isWritable", Function::New(luv_is_writable));
- return prototype;
+
+ return *prototype;
}
View
22 src/luv_tcp.cc
@@ -10,18 +10,6 @@
using namespace candor;
-// TODO: remove when candor API has this.
-static Object* CloneObject(Object* original) {
- Object* clone = Object::New();
- Array* keys = original->Keys();
- int64_t i = keys->Length();
- while (i--) {
- Value* key = keys->Get(i);
- clone->Set(key, original->Get(key));
- }
- return clone;
-}
-
/* Temporary hack: libuv should provide uv_inet_pton and uv_inet_ntop. */
#if defined(__MINGW32__) || defined(_MSC_VER)
# include <inet_net_pton.h>
@@ -40,7 +28,7 @@ using namespace candor;
static Value* luv_create_tcp(uint32_t argc, Arguments& argv) {
assert(argc == 0);
- Object* obj = CloneObject(uv_tcp_prototype());
+ Object* obj = uv_tcp_prototype()->Clone();
CData* cdata = CData::New(sizeof(uv_tcp_t));
uv_tcp_t* handle = (uv_tcp_t*)cdata->GetContents();
handle->data = obj;
@@ -168,17 +156,17 @@ Object* uv_tcp_module() {
return module;
}
-static Object* prototype;
+static Handle<Object> prototype;
Object* uv_tcp_prototype() {
- if (prototype) return prototype;
- prototype = CloneObject(uv_stream_prototype());
+ if (!prototype.IsEmpty()) return *prototype;
+ prototype.Wrap(uv_stream_prototype()->Clone());
prototype->Set("nodelay", Function::New(luv_tcp_nodelay));
prototype->Set("keepalive", Function::New(luv_tcp_keepalive));
prototype->Set("bind", Function::New(luv_tcp_bind));
prototype->Set("getsockname", Function::New(luv_tcp_getsockname));
prototype->Set("getpeername", Function::New(luv_tcp_getpeername));
prototype->Set("connect", Function::New(luv_tcp_connect));
- return prototype;
+ return *prototype;
}
View
26 src/luv_timer.cc
@@ -7,21 +7,9 @@
using namespace candor;
-// TODO: remove when candor API has this.
-static Object* CloneObject(Object* original) {
- Object* clone = Object::New();
- Array* keys = original->Keys();
- int64_t i = keys->Length();
- while (i--) {
- Value* key = keys->Get(i);
- clone->Set(key, original->Get(key));
- }
- return clone;
-}
-
static Value* luv_create_timer(uint32_t argc, Arguments& argv) {
assert(argc == 0);
- Object* obj = CloneObject(uv_timer_prototype());
+ Object* obj = uv_timer_prototype()->Clone();
CData* cdata = CData::New(sizeof(uv_timer_t));
uv_timer_t* handle = (uv_timer_t*)cdata->GetContents();
handle->data = obj;
@@ -95,16 +83,18 @@ Object* uv_timer_module() {
return module;
}
-static Object* prototype;
+static Handle<Object> prototype;
Object* uv_timer_prototype() {
- if (prototype) return prototype;
- prototype = CloneObject(uv_handle_prototype());
- new Handle<Object>(prototype);
+ if (!prototype.IsEmpty()) return *prototype;
+
+ prototype.Wrap(uv_handle_prototype()->Clone());
+
prototype->Set("start", Function::New(luv_timer_start));
prototype->Set("stop", Function::New(luv_timer_stop));
prototype->Set("again", Function::New(luv_timer_again));
prototype->Set("getRepeat", Function::New(luv_timer_get_repeat));
prototype->Set("setRepeat", Function::New(luv_timer_set_repeat));
- return prototype;
+
+ return *prototype;
}
Please sign in to comment.
Something went wrong with that request. Please try again.