From b0c06bccb4254221053bd2ce8a3270ffcfb58100 Mon Sep 17 00:00:00 2001 From: Jan Deinhard Date: Fri, 23 Oct 2015 12:54:12 +0200 Subject: [PATCH] Make node-i2c compile with Node 4. * v8::Buffer::New returns an instance of v8::MaybeLocal<> * an instance of v8::MaybeLocal needs to be asked for the actual local by calling v8::MaybeLocal::ToLocalChecked() --- src/i2c.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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)