@@ -106,31 +106,40 @@ 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 -1 ;
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 -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);
119
125
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
+ }
126
133
storage_size += chunk_size;
127
134
}
128
135
129
136
if (storage_size > INT_MAX)
130
137
return UV_ENOBUFS;
131
138
} else {
132
139
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 ;
134
143
bufs[i].base = Buffer::Data (chunk);
135
144
bufs[i].len = Buffer::Length (chunk);
136
145
}
@@ -145,7 +154,9 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
145
154
offset = 0 ;
146
155
if (!all_buffers) {
147
156
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 ;
149
160
150
161
// Write buffer
151
162
if (Buffer::HasInstance (chunk)) {
@@ -160,9 +171,13 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
160
171
static_cast <char *>(bs ? bs->Data () : nullptr ) + offset;
161
172
size_t str_size = (bs ? bs->ByteLength () : 0 ) - offset;
162
173
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);
166
181
str_size = StringBytes::Write (isolate,
167
182
str_storage,
168
183
str_size,
@@ -207,9 +222,11 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) {
207
222
send_handle = reinterpret_cast <uv_stream_t *>(wrap->GetHandle ());
208
223
// Reference LibuvStreamWrap instance to prevent it from being garbage
209
224
// 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
+ }
213
230
}
214
231
215
232
StreamWriteResult res = Write (&buf, 1 , send_handle, req_wrap_obj);
@@ -236,12 +253,12 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
236
253
// For UTF8 strings that are very long, go ahead and take the hit for
237
254
// computing their actual size, rather than tripling the storage.
238
255
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
+ }
245
262
246
263
if (storage_size > INT_MAX)
247
264
return UV_ENOBUFS;
@@ -312,9 +329,11 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
312
329
send_handle = reinterpret_cast <uv_stream_t *>(wrap->GetHandle ());
313
330
// Reference LibuvStreamWrap instance to prevent it from being garbage
314
331
// 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
+ }
318
337
}
319
338
320
339
StreamWriteResult res = Write (&buf, 1 , send_handle, req_wrap_obj);
0 commit comments