@@ -303,15 +303,14 @@ MaybeLocal<Object> New(Environment* env, size_t length) {
303
303
data,
304
304
length,
305
305
ArrayBufferCreationMode::kInternalized );
306
- Local<Uint8Array> ui = Uint8Array::New (ab, 0 , length);
307
- Maybe<bool > mb =
308
- ui->SetPrototype (env->context (), env->buffer_prototype_object ());
309
- if (mb.FromMaybe (false ))
310
- return scope.Escape (ui);
306
+ MaybeLocal<Uint8Array> ui = Buffer::New (env, ab, 0 , length);
311
307
312
- // Object failed to be created. Clean up resources.
313
- free (data);
314
- return Local<Object>();
308
+ if (ui.IsEmpty ()) {
309
+ // Object failed to be created. Clean up resources.
310
+ free (data);
311
+ }
312
+
313
+ return scope.Escape (ui.FromMaybe (Local<Uint8Array>()));
315
314
}
316
315
317
316
@@ -349,15 +348,14 @@ MaybeLocal<Object> Copy(Environment* env, const char* data, size_t length) {
349
348
new_data,
350
349
length,
351
350
ArrayBufferCreationMode::kInternalized );
352
- Local<Uint8Array> ui = Uint8Array::New (ab, 0 , length);
353
- Maybe<bool > mb =
354
- ui->SetPrototype (env->context (), env->buffer_prototype_object ());
355
- if (mb.FromMaybe (false ))
356
- return scope.Escape (ui);
351
+ MaybeLocal<Uint8Array> ui = Buffer::New (env, ab, 0 , length);
357
352
358
- // Object failed to be created. Clean up resources.
359
- free (new_data);
360
- return Local<Object>();
353
+ if (ui.IsEmpty ()) {
354
+ // Object failed to be created. Clean up resources.
355
+ free (new_data);
356
+ }
357
+
358
+ return scope.Escape (ui.FromMaybe (Local<Uint8Array>()));
361
359
}
362
360
363
361
@@ -392,15 +390,14 @@ MaybeLocal<Object> New(Environment* env,
392
390
// correct.
393
391
if (data == nullptr )
394
392
ab->Neuter ();
395
- Local<Uint8Array> ui = Uint8Array::New (ab, 0 , length);
396
- Maybe<bool > mb =
397
- ui->SetPrototype (env->context (), env->buffer_prototype_object ());
393
+ MaybeLocal<Uint8Array> ui = Buffer::New (env, ab, 0 , length);
398
394
399
- if (!mb. FromMaybe ( false ))
395
+ if (ui. IsEmpty ()) {
400
396
return Local<Object>();
397
+ }
401
398
402
399
CallbackInfo::New (env->isolate (), ab, callback, data, hint);
403
- return scope.Escape (ui);
400
+ return scope.Escape (ui. ToLocalChecked () );
404
401
}
405
402
406
403
@@ -415,8 +412,6 @@ MaybeLocal<Object> New(Isolate* isolate, char* data, size_t length) {
415
412
416
413
417
414
MaybeLocal<Object> New (Environment* env, char * data, size_t length) {
418
- EscapableHandleScope scope (env->isolate ());
419
-
420
415
if (length > 0 ) {
421
416
CHECK_NE (data, nullptr );
422
417
CHECK (length <= kMaxLength );
@@ -427,12 +422,7 @@ MaybeLocal<Object> New(Environment* env, char* data, size_t length) {
427
422
data,
428
423
length,
429
424
ArrayBufferCreationMode::kInternalized );
430
- Local<Uint8Array> ui = Uint8Array::New (ab, 0 , length);
431
- Maybe<bool > mb =
432
- ui->SetPrototype (env->context (), env->buffer_prototype_object ());
433
- if (mb.FromMaybe (false ))
434
- return scope.Escape (ui);
435
- return Local<Object>();
425
+ return Buffer::New (env, ab, 0 , length).FromMaybe (Local<Object>());
436
426
}
437
427
438
428
namespace {
0 commit comments