From 589d8af5d4dbb64b75473c736ac7da8effde8870 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 15 May 2009 01:36:51 +0200 Subject: [PATCH] Wrap NewInstance with TryCatch. (Was still missing the error.) --- src/http.cc | 7 +++++++ src/http.js | 3 ++- src/net.cc | 8 +++++++- src/node.cc | 10 +++++++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/http.cc b/src/http.cc index fda19fe4cb7..2eb9ab412c9 100644 --- a/src/http.cc +++ b/src/http.cc @@ -334,9 +334,16 @@ HTTPServer::OnConnection (struct sockaddr *addr, socklen_t len) return NULL; } + TryCatch try_catch; + Local connection_handle = HTTPConnection::server_constructor_template->GetFunction()->NewInstance(0, NULL); + if (connection_handle.IsEmpty()) { + fatal_exception(try_catch); + return NULL; + } + HTTPConnection *connection = NODE_UNWRAP(HTTPConnection, connection_handle); if (!connection) return NULL; diff --git a/src/http.js b/src/http.js index c1f0aa7a5f4..ad091d6a90e 100644 --- a/src/http.js +++ b/src/http.js @@ -210,7 +210,8 @@ node.http.Server = function (RequestHandler, options) { this.onBodyComplete = function () { return true; } } - this.onMessage = function ( ) { + connection.onMessage = function ( ) { + puts("got onMessage"); var msg = new Message(); msg.path = ""; diff --git a/src/net.cc b/src/net.cc index 40bafad0dd8..515bb646a7d 100644 --- a/src/net.cc +++ b/src/net.cc @@ -409,8 +409,15 @@ Acceptor::OnConnection (struct sockaddr *addr, socklen_t len) return NULL; } + TryCatch try_catch; + Local connection_handle = Connection::constructor_template->GetFunction()->NewInstance(0, NULL); + + if (connection_handle.IsEmpty()) { + fatal_exception(try_catch); + return NULL; + } Connection *connection = NODE_UNWRAP(Connection, connection_handle); if (!connection) return NULL; @@ -419,7 +426,6 @@ Acceptor::OnConnection (struct sockaddr *addr, socklen_t len) Handle argv[1] = { connection_handle }; - TryCatch try_catch; Local ret = connection_handler->Call(handle_, 1, argv); if (ret.IsEmpty()) diff --git a/src/node.cc b/src/node.cc index 277717b54f4..e9254ed8866 100644 --- a/src/node.cc +++ b/src/node.cc @@ -61,13 +61,17 @@ void* ObjectWrap::Unwrap (Handle handle) { HandleScope scope; - if(handle.IsEmpty() || handle->InternalFieldCount() == 0) { - ThrowException(String::New("Tried to unwrap object without internal field.")); + if (handle.IsEmpty()) { + fprintf(stderr, "Node: Tried to unwrap empty object.\n"); + return NULL; + } + if ( handle->InternalFieldCount() == 0) { + fprintf(stderr, "Node: Tried to unwrap object without internal fields.\n"); return NULL; } Local value = handle->GetInternalField(0); if (value.IsEmpty()) { - ThrowException(String::New("Tried to unwrap object with empty internal field.")); + fprintf(stderr, "Tried to unwrap object with empty internal field.\n"); return NULL; } Handle field = Handle::Cast(value);