From 84c904c1d4a506ba6873773b712aa1dab63247ac Mon Sep 17 00:00:00 2001 From: Jatin Desai Date: Fri, 14 Feb 2020 14:41:20 -0500 Subject: [PATCH] Update for Node v12/v13 - for v8 changes --- src/Concater.cc | 2 +- src/Decoder.cc | 2 +- src/Encoder.cc | 2 +- src/Flipper.cc | 3 +-- src/Packer.cc | 2 +- src/Params.h | 2 +- src/ScaleConverter.cc | 6 +++--- src/Stamper.cc | 24 ++++++++++++------------ 8 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Concater.cc b/src/Concater.cc index 4318055..99b2790 100644 --- a/src/Concater.cc +++ b/src/Concater.cc @@ -34,7 +34,7 @@ class ConcatProcessData : public iProcessData { : mPersistentSrcBuf(new Persist(srcBufArray)), mPersistentDstBuf(new Persist(dstBuf)), mDstBuf(Memory::makeNew((uint8_t *)node::Buffer::Data(dstBuf), (uint32_t)node::Buffer::Length(dstBuf))), mSrcBytes(0) { for (uint32_t i = 0; i < srcBufArray->Length(); ++i) { - Local bufferObj = Local::Cast(srcBufArray->Get(i)); + Local bufferObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), i).ToLocalChecked()); uint32_t bufLen = (uint32_t)node::Buffer::Length(bufferObj); mSrcBufVec.push_back(std::make_pair((uint8_t *)node::Buffer::Data(bufferObj), bufLen)); mSrcBytes += bufLen; diff --git a/src/Decoder.cc b/src/Decoder.cc index 1763245..6a110dc 100644 --- a/src/Decoder.cc +++ b/src/Decoder.cc @@ -147,7 +147,7 @@ NAN_METHOD(Decoder::Decode) { std::string err = std::string("Decoder requires single source buffer - received ") + std::to_string(srcBufArray->Length()); return Nan::ThrowError(err.c_str()); } - Local srcBuf = Local::Cast(srcBufArray->Get(0)); + Local srcBuf = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()); std::shared_ptr epd = std::make_shared(srcBuf, dstBuf); obj->mWorker->doFrame(epd, obj, new Nan::Callback(callback)); diff --git a/src/Encoder.cc b/src/Encoder.cc index cb819fc..93101c3 100644 --- a/src/Encoder.cc +++ b/src/Encoder.cc @@ -198,7 +198,7 @@ NAN_METHOD(Encoder::Encode) { std::string err = std::string("Encoder requires single source buffer - received ") + std::to_string(srcBufArray->Length()); return Nan::ThrowError(err.c_str()); } - Local srcBufObj = Local::Cast(srcBufArray->Get(0)); + Local srcBufObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()); std::shared_ptr convertDstBuf; if (obj->mPacker) convertDstBuf = Memory::makeNew(getFormatBytes(obj->mEncoderDriver->packingRequired(), obj->mSrcInfo->width(), obj->mSrcInfo->height())); diff --git a/src/Flipper.cc b/src/Flipper.cc index 05b741b..66716c6 100644 --- a/src/Flipper.cc +++ b/src/Flipper.cc @@ -1,5 +1,4 @@ /* Copyright 2017 Streampunk Media Ltd. - Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -150,7 +149,7 @@ NAN_METHOD(Flipper::Flip) { Local dstBufObj = Local::Cast(info[1]); Local callback = Local::Cast(info[2]); - Local srcBufObj = Local::Cast(srcBufArray->Get(0)); + Local srcBufObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()); Flipper* obj = Nan::ObjectWrap::Unwrap(info.Holder()); diff --git a/src/Packer.cc b/src/Packer.cc index 7743424..2cab27e 100644 --- a/src/Packer.cc +++ b/src/Packer.cc @@ -138,7 +138,7 @@ NAN_METHOD(Packer::Pack) { Local dstBufObj = Local::Cast(info[1]); Local callback = Local::Cast(info[2]); - Local srcBufObj = Local::Cast(srcBufArray->Get(0)); + Local srcBufObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()); Packer* obj = Nan::ObjectWrap::Unwrap(info.Holder()); diff --git a/src/Params.h b/src/Params.h index e1f1288..d3c9a27 100644 --- a/src/Params.h +++ b/src/Params.h @@ -37,7 +37,7 @@ class Params { std::string unpackValue(Local val) { Local valueArray = Local::Cast(val); - return *Nan::Utf8String(valueArray->Get(0)); + return *Nan::Utf8String(valueArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()); } bool unpackBool(Local tags, const std::string& key, bool dflt) { diff --git a/src/ScaleConverter.cc b/src/ScaleConverter.cc index bd320f0..e38ec0c 100644 --- a/src/ScaleConverter.cc +++ b/src/ScaleConverter.cc @@ -111,7 +111,7 @@ void ScaleConverter::doSetInfo(Local srcTags, Local dstTags, v8: if (!(!scaleXY->IsNull() && scaleXY->IsArray() && (scaleXY->Length() == 2))) return Nan::ThrowError("Scale parameter invalid"); - fXY scale(Nan::To(scaleXY->Get(0)).FromJust(), Nan::To(scaleXY->Get(1)).FromJust()); + fXY scale(Nan::To(scaleXY->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()).FromJust(), Nan::To(scaleXY->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 1).ToLocalChecked()).FromJust()); if ((scale.x > 10.0f) || (scale.y > 10.0f)) { std::string err = std::string("Unsupported Scale values X:") + std::to_string(scale.x).c_str() + ", Y:" + std::to_string(scale.y).c_str(); return Nan::ThrowError(err.c_str()); @@ -122,7 +122,7 @@ void ScaleConverter::doSetInfo(Local srcTags, Local dstTags, v8: if (!(!dstOffsetXY->IsNull() && dstOffsetXY->IsArray() && (dstOffsetXY->Length() == 2))) return Nan::ThrowError("DstOffset parameter invalid"); - fXY dstOffset(Nan::To(dstOffsetXY->Get(0)).FromJust(), Nan::To(dstOffsetXY->Get(1)).FromJust()); + fXY dstOffset(Nan::To(dstOffsetXY->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()).FromJust(), Nan::To(dstOffsetXY->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 1).ToLocalChecked()).FromJust()); if ((dstOffset.x > mDstVidInfo->width() / 2) || (dstOffset.y > mDstVidInfo->height() / 2)) { std::string err = std::string("Unsupported DstOffset values X:") + std::to_string(dstOffset.x).c_str() + ", Y:" + std::to_string(dstOffset.y).c_str(); return Nan::ThrowError(err.c_str()); @@ -186,7 +186,7 @@ NAN_METHOD(ScaleConverter::ScaleConvert) { Local dstBufObj = Local::Cast(info[1]); Local callback = Local::Cast(info[2]); - Local srcBufObj = Local::Cast(srcBufArray->Get(0)); + Local srcBufObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()); ScaleConverter* obj = Nan::ObjectWrap::Unwrap(info.Holder()); diff --git a/src/Stamper.cc b/src/Stamper.cc index ae413e5..362d49b 100644 --- a/src/Stamper.cc +++ b/src/Stamper.cc @@ -80,7 +80,7 @@ class MixProcessData : public iProcessData { mPressure(pressure) { for (uint32_t i=0; iLength(); ++i) { - Local srcBufObj = Local::Cast(srcBufArray->Get(i)); + Local srcBufObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), i).ToLocalChecked()); mPersistentSrcBufs.push_back(std::shared_ptr(new Persist(srcBufObj))); mSrcBufs.push_back(Memory::makeNew((uint8_t *)node::Buffer::Data(srcBufObj), (uint32_t)node::Buffer::Length(srcBufObj))); } @@ -106,7 +106,7 @@ class StampProcessData : public iProcessData { mDstBuf(Memory::makeNew((uint8_t *)node::Buffer::Data(dstBufObj), (uint32_t)node::Buffer::Length(dstBufObj))) { for (uint32_t i=0; iLength(); ++i) { - Local srcBufObj = Local::Cast(srcBufArray->Get(i)); + Local srcBufObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), i).ToLocalChecked()); mPersistentSrcBufs.push_back(std::shared_ptr(new Persist(srcBufObj))); mSrcBufs.push_back(Memory::makeNew((uint8_t *)node::Buffer::Data(srcBufObj), (uint32_t)node::Buffer::Length(srcBufObj))); } @@ -163,7 +163,7 @@ uint32_t Stamper::processFrame (std::shared_ptr processData) { } void Stamper::doSetInfo(Local srcTagsArray, Local dstTags) { - Local srcTags = Local::Cast(srcTagsArray->Get(0)); + Local srcTags = Local::Cast(srcTagsArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()); mSrcVidInfo = std::make_shared(srcTags); printDebug(eInfo, "Stamper SrcVidInfo: %s\n", mSrcVidInfo->toString().c_str()); mDstVidInfo = std::make_shared(dstTags); @@ -519,17 +519,17 @@ NAN_METHOD(Stamper::Wipe) { Local wipeRectArr = Local::Cast(Nan::Get(paramTags, wipeRectStr).ToLocalChecked()); if (!(!wipeRectArr->IsNull() && wipeRectArr->IsArray() && (wipeRectArr->Length() == 4))) return Nan::ThrowError("wipeRect parameter invalid"); - iRect wipeRect(iXY(Nan::To(wipeRectArr->Get(0)).FromJust(), Nan::To(wipeRectArr->Get(1)).FromJust()), - iXY(Nan::To(wipeRectArr->Get(2)).FromJust(), Nan::To(wipeRectArr->Get(3)).FromJust())); + iRect wipeRect(iXY(Nan::To(wipeRectArr->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()).FromJust(), Nan::To(wipeRectArr->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 1).ToLocalChecked()).FromJust()), + iXY(Nan::To(wipeRectArr->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 2).ToLocalChecked()).FromJust(), Nan::To(wipeRectArr->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 3).ToLocalChecked()).FromJust())); Local wipeColStr = Nan::New("wipeCol").ToLocalChecked(); Local wipeColArr = Local::Cast(Nan::Get(paramTags, wipeColStr).ToLocalChecked()); if (!(!wipeColArr->IsNull() && wipeColArr->IsArray() && (wipeColArr->Length() == 3))) return Nan::ThrowError("wipeCol parameter invalid"); - fCol wipeCol(Nan::To(wipeColArr->Get(0)).FromJust(), - Nan::To(wipeColArr->Get(1)).FromJust(), - Nan::To(wipeColArr->Get(2)).FromJust()); + fCol wipeCol(Nan::To(wipeColArr->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()).FromJust(), + Nan::To(wipeColArr->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 1).ToLocalChecked()).FromJust(), + Nan::To(wipeColArr->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 2).ToLocalChecked()).FromJust()); std::shared_ptr wpd = std::make_shared(dstBufObj, wipeRect, wipeCol); @@ -555,7 +555,7 @@ NAN_METHOD(Stamper::Copy) { Local paramTags = Local::Cast(info[2]); Local callback = Local::Cast(info[3]); - Local srcBufObj = Local::Cast(srcBufArray->Get(0)); + Local srcBufObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()); Stamper* obj = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -573,7 +573,7 @@ NAN_METHOD(Stamper::Copy) { Local dstOrgXY = Local::Cast(Nan::Get(paramTags, dstOrgStr).ToLocalChecked()); if (!(!dstOrgXY->IsNull() && dstOrgXY->IsArray() && (dstOrgXY->Length() == 2))) return Nan::ThrowError("dstOrg parameter invalid"); - iXY dstOrg(Nan::To(dstOrgXY->Get(0)).FromJust(), Nan::To(dstOrgXY->Get(1)).FromJust()); + iXY dstOrg(Nan::To(dstOrgXY->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 0).ToLocalChecked()).FromJust(), Nan::To(dstOrgXY->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), 1).ToLocalChecked()).FromJust()); std::shared_ptr cpd = std::make_shared(srcBufObj, dstBufObj, dstOrg); @@ -606,7 +606,7 @@ NAN_METHOD(Stamper::Mix) { uint32_t srcFormatBytes = getFormatBytes(obj->mSrcVidInfo->packing(), obj->mSrcVidInfo->width(), obj->mSrcVidInfo->height()); for (uint32_t i=0; iLength(); ++i) { - Local srcBufObj = Local::Cast(srcBufArray->Get(i)); + Local srcBufObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), i).ToLocalChecked()); if (srcFormatBytes > (uint32_t)node::Buffer::Length(srcBufObj)) Nan::ThrowError("Insufficient source buffer for Mix\n"); } @@ -654,7 +654,7 @@ NAN_METHOD(Stamper::Stamp) { for (uint32_t i=0; iLength(); ++i) { uint32_t srcFormatBytes = getFormatBytes(obj->mSrcVidInfo->packing(), obj->mSrcVidInfo->width(), obj->mSrcVidInfo->height(), 0==i); - Local srcBufObj = Local::Cast(srcBufArray->Get(i)); + Local srcBufObj = Local::Cast(srcBufArray->Get(v8::Isolate::GetCurrent()->GetCurrentContext(), i).ToLocalChecked()); if (srcFormatBytes > (uint32_t)node::Buffer::Length(srcBufObj)) Nan::ThrowError("Insufficient source buffer for Stamp\n"); }