diff --git a/src/i2c.cc b/src/i2c.cc index c0b00fb..4dbdcd9 100644 --- a/src/i2c.cc +++ b/src/i2c.cc @@ -159,19 +159,19 @@ void ReadBlock(const FunctionCallbackInfo& args) { int32_t len = args[1]->Int32Value(); uint8_t data[len]; Local err = Local::New(isolate, Null(isolate)); - Local buffer = node::Buffer::New(len); + MaybeLocal buffer = node::Buffer::New(isolate, len); while (fd > 0) { if (i2c_smbus_read_i2c_block_data(fd, cmd, len, data) != len) { err = Exception::Error(String::NewFromUtf8(isolate, "Error reading length of bytes")); } - memcpy(node::Buffer::Data(buffer), data, len); + memcpy(node::Buffer::Data(buffer.ToLocalChecked()), data, len); if (args[3]->IsFunction()) { const unsigned argc = 2; Local callback = Local::Cast(args[3]); - Local argv[argc] = { err, buffer }; + Local argv[argc] = { err, buffer.ToLocalChecked() }; callback->Call(isolate->GetCurrentContext()->Global(), argc, argv); } @@ -183,7 +183,7 @@ void ReadBlock(const FunctionCallbackInfo& args) { } } - args.GetReturnValue().Set(buffer); + args.GetReturnValue().Set(buffer.ToLocalChecked()); } void Write(const FunctionCallbackInfo& args) { @@ -290,4 +290,4 @@ void Init(Handle exports) { NODE_SET_METHOD(exports, "readBlock", ReadBlock); } -NODE_MODULE(i2c, Init) \ No newline at end of file +NODE_MODULE(i2c, Init)