@@ -106,16 +106,22 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
106
106
if (!all_buffers) {
107
107
// Determine storage size first
108
108
for (size_t i = 0 ; i < count; i++) {
109
- Local<Value> chunk = chunks->Get (context, i * 2 ).ToLocalChecked ();
109
+ Local<Value> chunk;
110
+ if (!chunks->Get (context, i * 2 ).ToLocal (&chunk))
111
+ return 0 ;
110
112
111
113
if (Buffer::HasInstance (chunk))
112
114
continue ;
113
115
// Buffer chunk, no additional storage required
114
116
115
117
// String chunk
116
- Local<String> string = chunk->ToString (context).ToLocalChecked ();
117
- enum encoding encoding = ParseEncoding (isolate,
118
- chunks->Get (context, i * 2 + 1 ).ToLocalChecked ());
118
+ Local<String> string;
119
+ if (!chunk->ToString (context).ToLocal (&string))
120
+ return 0 ;
121
+ Local<Value> next_chunk;
122
+ if (!chunks->Get (context, i * 2 + 1 ).ToLocal (&next_chunk))
123
+ return 0 ;
124
+ enum encoding encoding = ParseEncoding (isolate, next_chunk);
119
125
size_t chunk_size;
120
126
if (encoding == UTF8 && string->Length () > 65535 &&
121
127
!StringBytes::Size (isolate, string, encoding).To (&chunk_size))
@@ -130,7 +136,9 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
130
136
return UV_ENOBUFS;
131
137
} else {
132
138
for (size_t i = 0 ; i < count; i++) {
133
- Local<Value> chunk = chunks->Get (context, i).ToLocalChecked ();
139
+ Local<Value> chunk;
140
+ if (!chunks->Get (context, i).ToLocal (&chunk))
141
+ return 0 ;
134
142
bufs[i].base = Buffer::Data (chunk);
135
143
bufs[i].len = Buffer::Length (chunk);
136
144
}
@@ -145,7 +153,9 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
145
153
offset = 0 ;
146
154
if (!all_buffers) {
147
155
for (size_t i = 0 ; i < count; i++) {
148
- Local<Value> chunk = chunks->Get (context, i * 2 ).ToLocalChecked ();
156
+ Local<Value> chunk;
157
+ if (!chunks->Get (context, i * 2 ).ToLocal (&chunk))
158
+ return 0 ;
149
159
150
160
// Write buffer
151
161
if (Buffer::HasInstance (chunk)) {
@@ -160,9 +170,13 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
160
170
static_cast <char *>(bs ? bs->Data () : nullptr ) + offset;
161
171
size_t str_size = (bs ? bs->ByteLength () : 0 ) - offset;
162
172
163
- Local<String> string = chunk->ToString (context).ToLocalChecked ();
164
- enum encoding encoding = ParseEncoding (isolate,
165
- chunks->Get (context, i * 2 + 1 ).ToLocalChecked ());
173
+ Local<String> string;
174
+ if (!chunk->ToString (context).ToLocal (&string))
175
+ return 0 ;
176
+ Local<Value> next_chunk;
177
+ if (!chunks->Get (context, i * 2 + 1 ).ToLocal (&next_chunk))
178
+ return 0 ;
179
+ enum encoding encoding = ParseEncoding (isolate, next_chunk);
166
180
str_size = StringBytes::Write (isolate,
167
181
str_storage,
168
182
str_size,
@@ -207,9 +221,11 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
207
221
send_handle = reinterpret_cast <uv_stream_t *>(wrap->GetHandle ());
208
222
// Reference LibuvStreamWrap instance to prevent it from being garbage
209
223
// collected before `AfterWrite` is called.
210
- req_wrap_obj->Set (env->context (),
211
- env->handle_string (),
212
- send_handle_obj).Check ();
224
+ if (req_wrap_obj->Set (env->context (),
225
+ env->handle_string (),
226
+ send_handle_obj).IsNothing ()) {
227
+ return 0 ;
228
+ }
213
229
}
214
230
215
231
StreamWriteResult res = Write (&buf, 1 , send_handle, req_wrap_obj);
@@ -312,9 +328,11 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
312
328
send_handle = reinterpret_cast <uv_stream_t *>(wrap->GetHandle ());
313
329
// Reference LibuvStreamWrap instance to prevent it from being garbage
314
330
// collected before `AfterWrite` is called.
315
- req_wrap_obj->Set (env->context (),
316
- env->handle_string (),
317
- send_handle_obj).Check ();
331
+ if (req_wrap_obj->Set (env->context (),
332
+ env->handle_string (),
333
+ send_handle_obj).IsNothing ()) {
334
+ return 0 ;
335
+ }
318
336
}
319
337
320
338
StreamWriteResult res = Write (&buf, 1 , send_handle, req_wrap_obj);
0 commit comments