Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2928672

Browse filesBrowse files
addaleaxtargos
authored andcommitted
src: pass along errors from stream obj instantiation
PR-URL: #25734 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
1 parent 8032969 commit 2928672
Copy full SHA for 2928672

File tree

Expand file treeCollapse file tree

8 files changed

+40
-44
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+40
-44
lines changed
Open diff view settings
Collapse file

‎src/connection_wrap.cc‎

Copy file name to clipboardExpand all lines: src/connection_wrap.cc
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
4848

4949
if (status == 0) {
5050
// Instantiate the client javascript object and handle.
51-
Local<Object> client_obj = WrapType::Instantiate(env,
52-
wrap_data,
53-
WrapType::SOCKET);
51+
Local<Object> client_obj;
52+
if (!WrapType::Instantiate(env, wrap_data, WrapType::SOCKET)
53+
.ToLocal(&client_obj))
54+
return;
5455

5556
// Unwrap the client javascript object.
5657
WrapType* wrap;
Collapse file

‎src/pipe_wrap.cc‎

Copy file name to clipboardExpand all lines: src/pipe_wrap.cc
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ using v8::FunctionTemplate;
4242
using v8::HandleScope;
4343
using v8::Int32;
4444
using v8::Local;
45+
using v8::MaybeLocal;
4546
using v8::Object;
4647
using v8::String;
4748
using v8::Value;
4849

4950
using AsyncHooks = Environment::AsyncHooks;
5051

51-
52-
Local<Object> PipeWrap::Instantiate(Environment* env,
53-
AsyncWrap* parent,
54-
PipeWrap::SocketType type) {
52+
MaybeLocal<Object> PipeWrap::Instantiate(Environment* env,
53+
AsyncWrap* parent,
54+
PipeWrap::SocketType type) {
5555
EscapableHandleScope handle_scope(env->isolate());
5656
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
5757
CHECK_EQ(false, env->pipe_constructor_template().IsEmpty());
@@ -60,9 +60,8 @@ Local<Object> PipeWrap::Instantiate(Environment* env,
6060
.ToLocalChecked();
6161
CHECK_EQ(false, constructor.IsEmpty());
6262
Local<Value> type_value = Int32::New(env->isolate(), type);
63-
Local<Object> instance =
64-
constructor->NewInstance(env->context(), 1, &type_value).ToLocalChecked();
65-
return handle_scope.Escape(instance);
63+
return handle_scope.EscapeMaybe(
64+
constructor->NewInstance(env->context(), 1, &type_value));
6665
}
6766

6867

Collapse file

‎src/pipe_wrap.h‎

Copy file name to clipboardExpand all lines: src/pipe_wrap.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ class PipeWrap : public ConnectionWrap<PipeWrap, uv_pipe_t> {
3838
IPC
3939
};
4040

41-
static v8::Local<v8::Object> Instantiate(Environment* env,
42-
AsyncWrap* parent,
43-
SocketType type);
41+
static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
42+
AsyncWrap* parent,
43+
SocketType type);
4444
static void Initialize(v8::Local<v8::Object> target,
4545
v8::Local<v8::Value> unused,
4646
v8::Local<v8::Context> context,
Collapse file

‎src/stream_wrap.cc‎

Copy file name to clipboardExpand all lines: src/stream_wrap.cc
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ using v8::FunctionCallbackInfo;
4444
using v8::FunctionTemplate;
4545
using v8::HandleScope;
4646
using v8::Local;
47+
using v8::MaybeLocal;
4748
using v8::Object;
4849
using v8::ReadOnly;
4950
using v8::Signature;
@@ -195,19 +196,17 @@ void LibuvStreamWrap::OnUvAlloc(size_t suggested_size, uv_buf_t* buf) {
195196
*buf = EmitAlloc(suggested_size);
196197
}
197198

198-
199-
200199
template <class WrapType>
201-
static Local<Object> AcceptHandle(Environment* env, LibuvStreamWrap* parent) {
200+
static MaybeLocal<Object> AcceptHandle(Environment* env,
201+
LibuvStreamWrap* parent) {
202202
static_assert(std::is_base_of<LibuvStreamWrap, WrapType>::value ||
203203
std::is_base_of<UDPWrap, WrapType>::value,
204204
"Can only accept stream handles");
205205

206206
EscapableHandleScope scope(env->isolate());
207207
Local<Object> wrap_obj;
208208

209-
wrap_obj = WrapType::Instantiate(env, parent, WrapType::SOCKET);
210-
if (wrap_obj.IsEmpty())
209+
if (!WrapType::Instantiate(env, parent, WrapType::SOCKET).ToLocal(&wrap_obj))
211210
return Local<Object>();
212211

213212
HandleWrap* wrap = Unwrap<HandleWrap>(wrap_obj);
@@ -237,7 +236,7 @@ void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
237236
CHECK_EQ(persistent().IsEmpty(), false);
238237

239238
if (nread > 0) {
240-
Local<Object> pending_obj;
239+
MaybeLocal<Object> pending_obj;
241240

242241
if (type == UV_TCP) {
243242
pending_obj = AcceptHandle<TCPWrap>(env(), this);
@@ -250,9 +249,11 @@ void LibuvStreamWrap::OnUvRead(ssize_t nread, const uv_buf_t* buf) {
250249
}
251250

252251
if (!pending_obj.IsEmpty()) {
253-
object()->Set(env()->context(),
254-
env()->pending_handle_string(),
255-
pending_obj).FromJust();
252+
object()
253+
->Set(env()->context(),
254+
env()->pending_handle_string(),
255+
pending_obj.ToLocalChecked())
256+
.FromJust();
256257
}
257258
}
258259

Collapse file

‎src/tcp_wrap.cc‎

Copy file name to clipboardExpand all lines: src/tcp_wrap.cc
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ using v8::HandleScope;
4646
using v8::Int32;
4747
using v8::Integer;
4848
using v8::Local;
49+
using v8::MaybeLocal;
4950
using v8::Object;
5051
using v8::String;
5152
using v8::Uint32;
5253
using v8::Value;
5354

5455
using AsyncHooks = Environment::AsyncHooks;
5556

56-
57-
Local<Object> TCPWrap::Instantiate(Environment* env,
58-
AsyncWrap* parent,
59-
TCPWrap::SocketType type) {
57+
MaybeLocal<Object> TCPWrap::Instantiate(Environment* env,
58+
AsyncWrap* parent,
59+
TCPWrap::SocketType type) {
6060
EscapableHandleScope handle_scope(env->isolate());
6161
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
6262
CHECK_EQ(env->tcp_constructor_template().IsEmpty(), false);
@@ -65,9 +65,8 @@ Local<Object> TCPWrap::Instantiate(Environment* env,
6565
.ToLocalChecked();
6666
CHECK_EQ(constructor.IsEmpty(), false);
6767
Local<Value> type_value = Int32::New(env->isolate(), type);
68-
Local<Object> instance =
69-
constructor->NewInstance(env->context(), 1, &type_value).ToLocalChecked();
70-
return handle_scope.Escape(instance);
68+
return handle_scope.EscapeMaybe(
69+
constructor->NewInstance(env->context(), 1, &type_value));
7170
}
7271

7372

Collapse file

‎src/tcp_wrap.h‎

Copy file name to clipboardExpand all lines: src/tcp_wrap.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> {
3737
SERVER
3838
};
3939

40-
static v8::Local<v8::Object> Instantiate(Environment* env,
41-
AsyncWrap* parent,
42-
SocketType type);
40+
static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
41+
AsyncWrap* parent,
42+
SocketType type);
4343
static void Initialize(v8::Local<v8::Object> target,
4444
v8::Local<v8::Value> unused,
4545
v8::Local<v8::Context> context,
Collapse file

‎src/udp_wrap.cc‎

Copy file name to clipboardExpand all lines: src/udp_wrap.cc
+5-9Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ namespace node {
3030

3131
using v8::Array;
3232
using v8::Context;
33-
using v8::EscapableHandleScope;
3433
using v8::FunctionCallbackInfo;
3534
using v8::FunctionTemplate;
3635
using v8::HandleScope;
3736
using v8::Integer;
3837
using v8::Local;
38+
using v8::MaybeLocal;
3939
using v8::Object;
4040
using v8::PropertyAttribute;
4141
using v8::Signature;
@@ -518,18 +518,14 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
518518
wrap->MakeCallback(env->onmessage_string(), arraysize(argv), argv);
519519
}
520520

521-
522-
Local<Object> UDPWrap::Instantiate(Environment* env,
523-
AsyncWrap* parent,
524-
UDPWrap::SocketType type) {
525-
EscapableHandleScope scope(env->isolate());
521+
MaybeLocal<Object> UDPWrap::Instantiate(Environment* env,
522+
AsyncWrap* parent,
523+
UDPWrap::SocketType type) {
526524
AsyncHooks::DefaultTriggerAsyncIdScope trigger_scope(parent);
527525

528526
// If this assert fires then Initialize hasn't been called yet.
529527
CHECK_EQ(env->udp_constructor_function().IsEmpty(), false);
530-
Local<Object> instance = env->udp_constructor_function()
531-
->NewInstance(env->context()).ToLocalChecked();
532-
return scope.Escape(instance);
528+
return env->udp_constructor_function()->NewInstance(env->context());
533529
}
534530

535531

Collapse file

‎src/udp_wrap.h‎

Copy file name to clipboardExpand all lines: src/udp_wrap.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class UDPWrap: public HandleWrap {
6161
static void SetTTL(const v8::FunctionCallbackInfo<v8::Value>& args);
6262
static void BufferSize(const v8::FunctionCallbackInfo<v8::Value>& args);
6363

64-
static v8::Local<v8::Object> Instantiate(Environment* env,
65-
AsyncWrap* parent,
66-
SocketType type);
64+
static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
65+
AsyncWrap* parent,
66+
SocketType type);
6767
SET_NO_MEMORY_INFO()
6868
SET_MEMORY_INFO_NAME(UDPWrap)
6969
SET_SELF_SIZE(UDPWrap)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.