Skip to content

Commit

Permalink
src: use TryCatch.SetVerbose(true)
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen committed Feb 26, 2022
1 parent dfe4189 commit d90e99c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/dgram.js
Expand Up @@ -159,7 +159,7 @@ function startListening(socket) {
const state = socket[kStateSymbol];

state.handle.onmessage = onMessage;
// Todo: handle errors
state.handle.onerror = onError;
state.handle.recvStart();
state.receiving = true;
state.bindState = BIND_STATE_BOUND;
Expand Down Expand Up @@ -923,6 +923,12 @@ function onMessage(nread, handle, buf, rinfo) {
}


function onError(nread, handle, error) {
const self = handle[owner_symbol];
return self.emit('error', error);
}


Socket.prototype.ref = function() {
const handle = this[kStateSymbol].handle;

Expand Down
28 changes: 26 additions & 2 deletions src/udp_wrap.cc
Expand Up @@ -22,13 +22,15 @@
#include "udp_wrap.h"
#include "env-inl.h"
#include "node_buffer.h"
#include "node_errors.h"
#include "node_sockaddr-inl.h"
#include "handle_wrap.h"
#include "req_wrap-inl.h"
#include "util-inl.h"

namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::ArrayBuffer;
using v8::BackingStore;
Expand Down Expand Up @@ -729,10 +731,32 @@ void UDPWrap::OnRecv(ssize_t nread,
}

Local<Object> address;
if (!AddressToJS(env, addr).ToLocal(&address)) return;
{
TryCatchScope try_catch(env);
try_catch.SetVerbose(true);
DCHECK(try_catch.IsVerbose());
if (!AddressToJS(env, addr).ToLocal(&address)) {
DCHECK(try_catch.HasCaught() && !try_catch.HasTerminated());
argv[2] = try_catch.Exception();
DCHECK(!argv[2].IsEmpty());
MakeCallback(env->onerror_string(), arraysize(argv), argv);
return;
}
}

Local<ArrayBuffer> ab = ArrayBuffer::New(isolate, std::move(bs));
argv[2] = Buffer::New(env, ab, 0, ab->ByteLength()).ToLocalChecked();
{
TryCatchScope try_catch(env);
try_catch.SetVerbose(true);
DCHECK(try_catch.IsVerbose());
if (!Buffer::New(env, ab, 0, ab->ByteLength()).ToLocal(&argv[2])) {
DCHECK(try_catch.HasCaught() && !try_catch.HasTerminated());
argv[2] = try_catch.Exception();
DCHECK(!argv[2].IsEmpty());
MakeCallback(env->onerror_string(), arraysize(argv), argv);
return;
}
}
argv[3] = address;
MakeCallback(env->onmessage_string(), arraysize(argv), argv);
}
Expand Down

0 comments on commit d90e99c

Please sign in to comment.