@@ -106,31 +106,40 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
106106 if (!all_buffers) {
107107 // Determine storage size first
108108 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 -1 ;
110112
111113 if (Buffer::HasInstance (chunk))
112114 continue ;
113115 // Buffer chunk, no additional storage required
114116
115117 // 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 -1 ;
121+ Local<Value> next_chunk;
122+ if (!chunks->Get (context, i * 2 + 1 ).ToLocal (&next_chunk))
123+ return -1 ;
124+ enum encoding encoding = ParseEncoding (isolate, next_chunk);
119125 size_t chunk_size;
120- if (encoding == UTF8 && string->Length () > 65535 &&
121- !StringBytes::Size (isolate, string, encoding).To (&chunk_size))
122- return 0 ;
123- else if (!StringBytes::StorageSize (isolate, string, encoding)
124- .To (&chunk_size))
125- return 0 ;
126+ if ((encoding == UTF8 &&
127+ string->Length () > 65535 &&
128+ !StringBytes::Size (isolate, string, encoding).To (&chunk_size)) ||
129+ !StringBytes::StorageSize (isolate, string, encoding)
130+ .To (&chunk_size)) {
131+ return -1 ;
132+ }
126133 storage_size += chunk_size;
127134 }
128135
129136 if (storage_size > INT_MAX)
130137 return UV_ENOBUFS;
131138 } else {
132139 for (size_t i = 0 ; i < count; i++) {
133- Local<Value> chunk = chunks->Get (context, i).ToLocalChecked ();
140+ Local<Value> chunk;
141+ if (!chunks->Get (context, i).ToLocal (&chunk))
142+ return -1 ;
134143 bufs[i].base = Buffer::Data (chunk);
135144 bufs[i].len = Buffer::Length (chunk);
136145 }
@@ -145,7 +154,9 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
145154 offset = 0 ;
146155 if (!all_buffers) {
147156 for (size_t i = 0 ; i < count; i++) {
148- Local<Value> chunk = chunks->Get (context, i * 2 ).ToLocalChecked ();
157+ Local<Value> chunk;
158+ if (!chunks->Get (context, i * 2 ).ToLocal (&chunk))
159+ return -1 ;
149160
150161 // Write buffer
151162 if (Buffer::HasInstance (chunk)) {
@@ -160,9 +171,13 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
160171 static_cast <char *>(bs ? bs->Data () : nullptr ) + offset;
161172 size_t str_size = (bs ? bs->ByteLength () : 0 ) - offset;
162173
163- Local<String> string = chunk->ToString (context).ToLocalChecked ();
164- enum encoding encoding = ParseEncoding (isolate,
165- chunks->Get (context, i * 2 + 1 ).ToLocalChecked ());
174+ Local<String> string;
175+ if (!chunk->ToString (context).ToLocal (&string))
176+ return -1 ;
177+ Local<Value> next_chunk;
178+ if (!chunks->Get (context, i * 2 + 1 ).ToLocal (&next_chunk))
179+ return -1 ;
180+ enum encoding encoding = ParseEncoding (isolate, next_chunk);
166181 str_size = StringBytes::Write (isolate,
167182 str_storage,
168183 str_size,
@@ -207,9 +222,11 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
207222 send_handle = reinterpret_cast <uv_stream_t *>(wrap->GetHandle ());
208223 // Reference LibuvStreamWrap instance to prevent it from being garbage
209224 // collected before `AfterWrite` is called.
210- req_wrap_obj->Set (env->context (),
211- env->handle_string (),
212- send_handle_obj).Check ();
225+ if (req_wrap_obj->Set (env->context (),
226+ env->handle_string (),
227+ send_handle_obj).IsNothing ()) {
228+ return -1 ;
229+ }
213230 }
214231
215232 StreamWriteResult res = Write (&buf, 1 , send_handle, req_wrap_obj);
@@ -236,12 +253,12 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
236253 // For UTF8 strings that are very long, go ahead and take the hit for
237254 // computing their actual size, rather than tripling the storage.
238255 size_t storage_size;
239- if (enc == UTF8 && string-> Length () > 65535 &&
240- ! StringBytes::Size (isolate, string, enc). To (&storage_size))
241- return 0 ;
242- else if ( !StringBytes::StorageSize (isolate, string, enc)
243- . To (&storage_size))
244- return 0 ;
256+ if (( enc == UTF8 &&
257+ string-> Length () > 65535 &&
258+ ! StringBytes::Size (isolate, string, enc). To (&storage_size)) ||
259+ !StringBytes::StorageSize (isolate, string, enc). To (&storage_size)) {
260+ return - 1 ;
261+ }
245262
246263 if (storage_size > INT_MAX)
247264 return UV_ENOBUFS;
@@ -312,9 +329,11 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
312329 send_handle = reinterpret_cast <uv_stream_t *>(wrap->GetHandle ());
313330 // Reference LibuvStreamWrap instance to prevent it from being garbage
314331 // collected before `AfterWrite` is called.
315- req_wrap_obj->Set (env->context (),
316- env->handle_string (),
317- send_handle_obj).Check ();
332+ if (req_wrap_obj->Set (env->context (),
333+ env->handle_string (),
334+ send_handle_obj).IsNothing ()) {
335+ return -1 ;
336+ }
318337 }
319338
320339 StreamWriteResult res = Write (&buf, 1 , send_handle, req_wrap_obj);
0 commit comments