0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 15:06:33 +01:00

Wrap NewInstance with TryCatch. (Was still missing the error.)

This commit is contained in:
Ryan 2009-05-15 01:36:51 +02:00
parent febbf75302
commit 589d8af5d4
4 changed files with 23 additions and 5 deletions

View File

@ -334,9 +334,16 @@ HTTPServer::OnConnection (struct sockaddr *addr, socklen_t len)
return NULL;
}
TryCatch try_catch;
Local<Object> 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;

View File

@ -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 = "";

View File

@ -409,8 +409,15 @@ Acceptor::OnConnection (struct sockaddr *addr, socklen_t len)
return NULL;
}
TryCatch try_catch;
Local<Object> 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<Value> argv[1] = { connection_handle };
TryCatch try_catch;
Local<Value> ret = connection_handler->Call(handle_, 1, argv);
if (ret.IsEmpty())

View File

@ -61,13 +61,17 @@ void*
ObjectWrap::Unwrap (Handle<Object> 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> 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<External> field = Handle<External>::Cast(value);