@@ -73,6 +73,7 @@ using v8::Handle;
7373using v8::HandleScope;
7474using v8::Isolate;
7575using v8::Local;
76+ using v8::Maybe;
7677using v8::Number;
7778using v8::Object;
7879using v8::Persistent;
@@ -298,7 +299,13 @@ Local<Object> New(Environment* env, size_t length) {
298299 length,
299300 ArrayBufferCreationMode::kInternalized );
300301 Local<Uint8Array> ui = Uint8Array::New (ab, 0 , length);
301- ui->SetPrototype (env->buffer_prototype_object ());
302+ Maybe<bool > mb =
303+ ui->SetPrototype (env->context (), env->buffer_prototype_object ());
304+ if (!mb.FromMaybe (false )) {
305+ FatalError (" node::Buffer::New(Environment*, size_t)" ,
306+ " Could not set Object prototype" );
307+ UNREACHABLE ();
308+ }
302309 return scope.Escape (ui);
303310}
304311
@@ -361,7 +368,13 @@ Local<Object> New(Environment* env, const char* data, size_t length) {
361368 length,
362369 ArrayBufferCreationMode::kInternalized );
363370 Local<Uint8Array> ui = Uint8Array::New (ab, 0 , length);
364- ui->SetPrototype (env->buffer_prototype_object ());
371+ Maybe<bool > mb =
372+ ui->SetPrototype (env->context (), env->buffer_prototype_object ());
373+ if (!mb.FromMaybe (false )) {
374+ FatalError (" node::Buffer::New(Environment*, char*, size_t)" ,
375+ " Could not set Object prototype" );
376+ UNREACHABLE ();
377+ }
365378
366379 return scope.Escape (ui);
367380}
@@ -401,7 +414,14 @@ Local<Object> New(Environment* env,
401414
402415 Local<ArrayBuffer> ab = ArrayBuffer::New (env->isolate (), data, length);
403416 Local<Uint8Array> ui = Uint8Array::New (ab, 0 , length);
404- ui->SetPrototype (env->buffer_prototype_object ());
417+ Maybe<bool > mb =
418+ ui->SetPrototype (env->context (), env->buffer_prototype_object ());
419+ if (!mb.FromMaybe (false )) {
420+ FatalError (" node::Buffer::New(Environment*, char*, size_t,"
421+ " FreeCallback, void*)" ,
422+ " Could not set Object prototype" );
423+ UNREACHABLE ();
424+ }
405425 CallbackInfo::New (env->isolate (), ui, callback, hint);
406426 return scope.Escape (ui);
407427}
@@ -441,7 +461,13 @@ Local<Object> Use(Environment* env, char* data, size_t length) {
441461 length,
442462 ArrayBufferCreationMode::kInternalized );
443463 Local<Uint8Array> ui = Uint8Array::New (ab, 0 , length);
444- ui->SetPrototype (env->buffer_prototype_object ());
464+ Maybe<bool > mb =
465+ ui->SetPrototype (env->context (), env->buffer_prototype_object ());
466+ if (!mb.FromMaybe (false )) {
467+ FatalError (" node::Buffer::Use(Environment*, char*, size_t)" ,
468+ " Could not set Object prototype" );
469+ UNREACHABLE ();
470+ }
445471 return scope.Escape (ui);
446472}
447473
@@ -473,8 +499,10 @@ void Create(const FunctionCallbackInfo<Value>& args) {
473499 length,
474500 ArrayBufferCreationMode::kInternalized );
475501 Local<Uint8Array> ui = Uint8Array::New (ab, 0 , length);
476- ui->SetPrototype (env->buffer_prototype_object ());
477- args.GetReturnValue ().Set (ui);
502+ Maybe<bool > mb =
503+ ui->SetPrototype (env->context (), env->buffer_prototype_object ());
504+ if (mb.FromMaybe (false ))
505+ args.GetReturnValue ().Set (ui);
478506}
479507
480508
@@ -505,8 +533,10 @@ void Slice(const FunctionCallbackInfo<Value>& args) {
505533 size_t size = end - start;
506534 CHECK_GE (ab_c.ByteLength (), start + size);
507535 Local<Uint8Array> ui = Uint8Array::New (ab, start, size);
508- ui->SetPrototype (env->buffer_prototype_object ());
509- args.GetReturnValue ().Set (ui);
536+ Maybe<bool > mb =
537+ ui->SetPrototype (env->context (), env->buffer_prototype_object ());
538+ if (mb.FromMaybe (false ))
539+ args.GetReturnValue ().Set (ui);
510540}
511541
512542
0 commit comments