Skip to content

Commit d22e5c8

Browse files
author
guangming wan
committed
fix nodejs 12+
1 parent ef18dd1 commit d22e5c8

21 files changed

+550
-549
lines changed

inc/Matrix.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
native code:
55
66
NAN_METHOD(UnwrapMatrix) {
7-
cv::Mat mat = Nan::ObjectWrap::Unwrap<node_opencv::Matrix>(info[0]->ToObject())->mat;
7+
cv::Mat mat = Nan::ObjectWrap::Unwrap<node_opencv::Matrix>(Nan::To<v8::Object>(info[0]).ToLocalChecked())->mat;
88
// ...
99
}
1010

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Peter Braden <[email protected]>",
66
"dependencies": {
77
"buffers": "^0.1.1",
8-
"nan": "^2.13.1"
8+
"nan": "^2.14.0"
99
},
1010
"devDependencies": {
1111
"tape": "^3.0.0",

src/BackgroundSubtractor.cc

+17-17
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void BackgroundSubtractorWrap::Init(Local<Object> target) {
6666
Nan::SetPrototypeMethod(ctor, "noiseSigma", NoiseSigma);
6767
Nan::SetPrototypeMethod(ctor, "backgroundRatio", BackgroundRatio);
6868

69-
target->Set(Nan::New("BackgroundSubtractor").ToLocalChecked(), ctor->GetFunction());
69+
target->Set(Nan::New("BackgroundSubtractor").ToLocalChecked(), ctor->GetFunction( Nan::GetCurrentContext() ).ToLocalChecked());
7070
}
7171

7272
NAN_METHOD(BackgroundSubtractorWrap::New) {
@@ -242,28 +242,28 @@ NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {
242242
if (info.Length() == 0) {
243243
argv[0] = Nan::New("Input image missing").ToLocalChecked();
244244
argv[1] = Nan::Null();
245-
cb->Call(Nan::GetCurrentContext()->Global(), 2, argv);
245+
cb->Call( Nan::GetCurrentContext(), Nan::GetCurrentContext()->Global(), 2, argv);
246246
return;
247247
}
248248

249249
if (NULL == self->subtractor){
250250
argv[0] = Nan::New("BackgroundSubtractor not created").ToLocalChecked();
251251
argv[1] = Nan::Null();
252-
cb->Call(Nan::GetCurrentContext()->Global(), 2, argv);
252+
cb->Call( Nan::GetCurrentContext(), Nan::GetCurrentContext()->Global(), 2, argv);
253253
return;
254254
}
255255

256256

257257
try {
258258
cv::Mat mat;
259259
if (Buffer::HasInstance(info[0])) {
260-
uint8_t *buf = (uint8_t *) Buffer::Data(info[0]->ToObject());
261-
unsigned len = Buffer::Length(info[0]->ToObject());
260+
uint8_t *buf = (uint8_t *) Buffer::Data(Nan::To<v8::Object>(info[0]).ToLocalChecked());
261+
unsigned len = Buffer::Length(Nan::To<v8::Object>(info[0]).ToLocalChecked());
262262
cv::Mat *mbuf = new cv::Mat(len, 1, CV_64FC1, buf);
263263
mat = cv::imdecode(*mbuf, -1);
264264
//mbuf->release();
265265
} else {
266-
Matrix *_img = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
266+
Matrix *_img = Nan::ObjectWrap::Unwrap<Matrix>(Nan::To<v8::Object>(info[0]).ToLocalChecked());
267267
mat = (_img->mat).clone();
268268
}
269269

@@ -290,7 +290,7 @@ NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {
290290
argv[1] = fgMask;
291291

292292
Nan::TryCatch try_catch;
293-
cb->Call(Nan::GetCurrentContext()->Global(), 2, argv);
293+
cb->Call( Nan::GetCurrentContext(), Nan::GetCurrentContext()->Global(), 2, argv);
294294

295295
if (try_catch.HasCaught()) {
296296
Nan::FatalException(try_catch);
@@ -386,18 +386,18 @@ NAN_METHOD(BackgroundSubtractorWrap::Apply) {
386386
if (info.Length() == 0) {
387387
argv[0] = Nan::New("Input image missing").ToLocalChecked();
388388
argv[1] = Nan::Null();
389-
cb->Call(Nan::GetCurrentContext()->Global(), 2, argv);
389+
cb->Call( Nan::GetCurrentContext(), Nan::GetCurrentContext()->Global(), 2, argv);
390390
return;
391391
}
392392
if (NULL == self->subtractor){
393393
argv[0] = Nan::New("BackgroundSubtractor not created").ToLocalChecked();
394394
argv[1] = Nan::Null();
395-
cb->Call(Nan::GetCurrentContext()->Global(), 2, argv);
395+
cb->Call( Nan::GetCurrentContext(), Nan::GetCurrentContext()->Global(), 2, argv);
396396
return;
397397
}
398398

399399
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
400-
Matrix *_img = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
400+
Matrix *_img = Nan::ObjectWrap::Unwrap<Matrix>(Nan::To<v8::Object>(info[0]).ToLocalChecked());
401401
Nan::AsyncQueueWorker(new AsyncBackgroundSubtractorWorker( callback, self, _img));
402402
return;
403403
} else { //synchronous - return the image
@@ -406,13 +406,13 @@ NAN_METHOD(BackgroundSubtractorWrap::Apply) {
406406
Local<Object> fgMask;
407407
cv::Mat mat;
408408
if (Buffer::HasInstance(info[0])) {
409-
uint8_t *buf = (uint8_t *) Buffer::Data(info[0]->ToObject());
410-
unsigned len = Buffer::Length(info[0]->ToObject());
409+
uint8_t *buf = (uint8_t *) Buffer::Data(Nan::To<v8::Object>(info[0]).ToLocalChecked());
410+
unsigned len = Buffer::Length(Nan::To<v8::Object>(info[0]).ToLocalChecked());
411411
cv::Mat *mbuf = new cv::Mat(len, 1, CV_64FC1, buf);
412412
mat = cv::imdecode(*mbuf, -1);
413413
//mbuf->release();
414414
} else {
415-
Matrix *_img = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
415+
Matrix *_img = Nan::ObjectWrap::Unwrap<Matrix>(Nan::To<v8::Object>(info[0]).ToLocalChecked());
416416
mat = (_img->mat).clone();
417417
}
418418

@@ -456,7 +456,7 @@ NAN_METHOD(BackgroundSubtractorWrap::History) {
456456
// only support for V3+ with opencv-contrib
457457
#ifdef HAVE_OPENCV_BGSEGM
458458
if (info.Length() > 0) {
459-
mog->setHistory(info[0]->NumberValue());
459+
mog->setHistory(info[0].As<Number>()->Value());
460460
}
461461
info.GetReturnValue().Set(mog->getHistory());
462462
#else
@@ -473,7 +473,7 @@ NAN_METHOD(BackgroundSubtractorWrap::BackgroundRatio) {
473473
// only support for V3+ with opencv-contrib
474474
#ifdef HAVE_OPENCV_BGSEGM
475475
if (info.Length() > 0) {
476-
mog->setBackgroundRatio(info[0]->NumberValue());
476+
mog->setBackgroundRatio(info[0].As<Number>()->Value());
477477
}
478478
info.GetReturnValue().Set(mog->getBackgroundRatio());
479479
#else
@@ -490,7 +490,7 @@ NAN_METHOD(BackgroundSubtractorWrap::NoiseSigma) {
490490
// only support for V3+ with opencv-contrib
491491
#ifdef HAVE_OPENCV_BGSEGM
492492
if (info.Length() > 0) {
493-
mog->setNoiseSigma(info[0]->NumberValue());
493+
mog->setNoiseSigma(info[0].As<Number>()->Value());
494494
}
495495
info.GetReturnValue().Set(mog->getNoiseSigma());
496496
#else
@@ -507,7 +507,7 @@ NAN_METHOD(BackgroundSubtractorWrap::Mixtures) {
507507
// only support for V3+ with opencv-contrib
508508
#ifdef HAVE_OPENCV_BGSEGM
509509
if (info.Length() > 0) {
510-
mog->setNMixtures(info[0]->NumberValue());
510+
mog->setNMixtures(info[0].As<Number>()->Value());
511511
}
512512
info.GetReturnValue().Set(mog->getNMixtures());
513513
#else

src/Calib3D.cc

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
#ifdef HAVE_OPENCV_CALIB3D
55

66
inline cv::Mat matFromMatrix(Local<Value> matrix) {
7-
Matrix* m = Nan::ObjectWrap::Unwrap<Matrix>(matrix->ToObject());
7+
Matrix* m = Nan::ObjectWrap::Unwrap<Matrix>(matrix->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
88
return m->mat;
99
}
1010

1111
inline cv::Size sizeFromArray(Local<Value> jsArray) {
1212
cv::Size patternSize;
1313

1414
if (jsArray->IsArray()) {
15-
Local<Object> v8sz = jsArray->ToObject();
15+
Local<Object> v8sz = jsArray->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
1616

17-
patternSize = cv::Size(v8sz->Get(0)->IntegerValue(),
18-
v8sz->Get(1)->IntegerValue());
17+
patternSize = cv::Size(v8sz->Get(0)->IntegerValue( Nan::GetCurrentContext() ).ToChecked(),
18+
v8sz->Get(1)->IntegerValue( Nan::GetCurrentContext() ).ToChecked());
1919
} else {
2020
JSTHROW_TYPE("Size is not a valid array");
2121
}
@@ -26,10 +26,10 @@ inline cv::Size sizeFromArray(Local<Value> jsArray) {
2626
inline std::vector<cv::Point2f> points2fFromArray(Local<Value> array) {
2727
std::vector<cv::Point2f> points;
2828
if (array->IsArray()) {
29-
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
29+
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
3030

3131
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
32-
Local<Object> pt = Nan::Get(pointsArray, i).ToLocalChecked()->ToObject();
32+
Local<Object> pt = Nan::Get(pointsArray, i).ToLocalChecked()->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
3333
points.push_back(
3434
cv::Point2f(
3535
Nan::To<double>(Nan::Get(pt, Nan::New<String>("x").ToLocalChecked()).ToLocalChecked()).FromJust(),
@@ -47,10 +47,10 @@ inline std::vector<cv::Point2f> points2fFromArray(Local<Value> array) {
4747
inline std::vector<cv::Point3f> points3fFromArray(Local<Value> array) {
4848
std::vector<cv::Point3f> points;
4949
if (array->IsArray()) {
50-
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
50+
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
5151

5252
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
53-
Local<Object> pt = pointsArray->Get(i)->ToObject();
53+
Local<Object> pt = pointsArray->Get(i)->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
5454
points.push_back(
5555
cv::Point3f(
5656
Nan::To<double>(Nan::Get(pt, Nan::New<String>("x").ToLocalChecked()).ToLocalChecked()).FromJust(),
@@ -70,7 +70,7 @@ inline std::vector<std::vector<cv::Point2f> > points2fFromArrayOfArrays(
7070
Local<Value> array) {
7171
std::vector<std::vector<cv::Point2f> > points;
7272
if (array->IsArray()) {
73-
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
73+
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
7474

7575
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
7676
points.push_back(points2fFromArray(pointsArray->Get(i)));
@@ -86,7 +86,7 @@ inline std::vector<std::vector<cv::Point3f> > points3fFromArrayOfArrays(
8686
Local<Value> array) {
8787
std::vector<std::vector<cv::Point3f> > points;
8888
if (array->IsArray()) {
89-
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject());
89+
Local<Array> pointsArray = Local<Array>::Cast(array->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
9090

9191
for (unsigned int i = 0; i < pointsArray->Length(); i++) {
9292
points.push_back(points3fFromArray(pointsArray->Get(i)));
@@ -176,7 +176,7 @@ NAN_METHOD(Calib3D::DrawChessboardCorners) {
176176
std::vector<cv::Point2f> corners = points2fFromArray(info[2]);
177177

178178
// Arg 3, pattern found boolean
179-
bool patternWasFound = info[3]->ToBoolean()->Value();
179+
bool patternWasFound = info[3]->ToBoolean( v8::Isolate::GetCurrent() )->Value();
180180

181181
// Draw the corners
182182
cv::drawChessboardCorners(mat, patternSize, corners, patternWasFound);

src/CamShift.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void TrackedObject::Init(Local<Object> target) {
3333

3434
Nan::SetPrototypeMethod(ctor, "track", Track);
3535

36-
target->Set(Nan::New("TrackedObject").ToLocalChecked(), ctor->GetFunction());
36+
target->Set(Nan::New("TrackedObject").ToLocalChecked(), ctor->GetFunction( Nan::GetCurrentContext() ).ToLocalChecked());
3737
}
3838

3939
NAN_METHOD(TrackedObject::New) {
@@ -43,26 +43,26 @@ NAN_METHOD(TrackedObject::New) {
4343
JSTHROW_TYPE("Cannot Instantiate without new")
4444
}
4545

46-
Matrix* m = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
46+
Matrix* m = Nan::ObjectWrap::Unwrap<Matrix>(Nan::To<v8::Object>(info[0]).ToLocalChecked());
4747
cv::Rect r;
4848
int channel = CHANNEL_HUE;
4949

5050
if (info[1]->IsArray()) {
51-
Local<Object> v8rec = info[1]->ToObject();
51+
Local<Object> v8rec = info[1]->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
5252
r = cv::Rect(
53-
v8rec->Get(0)->IntegerValue(),
54-
v8rec->Get(1)->IntegerValue(),
55-
v8rec->Get(2)->IntegerValue() - v8rec->Get(0)->IntegerValue(),
56-
v8rec->Get(3)->IntegerValue() - v8rec->Get(1)->IntegerValue());
53+
v8rec->Get(0)->IntegerValue( Nan::GetCurrentContext() ).ToChecked(),
54+
v8rec->Get(1)->IntegerValue( Nan::GetCurrentContext() ).ToChecked(),
55+
v8rec->Get(2)->IntegerValue( Nan::GetCurrentContext() ).ToChecked() - v8rec->Get(0)->IntegerValue( Nan::GetCurrentContext() ).ToChecked(),
56+
v8rec->Get(3)->IntegerValue( Nan::GetCurrentContext() ).ToChecked() - v8rec->Get(1)->IntegerValue( Nan::GetCurrentContext() ).ToChecked());
5757
} else {
5858
JSTHROW_TYPE("Must pass rectangle to track")
5959
}
6060

6161
if (info[2]->IsObject()) {
62-
Local<Object> opts = info[2]->ToObject();
62+
Local<Object> opts = info[2]->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
6363

6464
if (opts->Get(Nan::New("channel").ToLocalChecked())->IsString()) {
65-
v8::String::Utf8Value c(opts->Get(Nan::New("channel").ToLocalChecked())->ToString());
65+
v8::String::Utf8Value c(v8::Isolate::GetCurrent(),opts->Get(Nan::New("channel").ToLocalChecked())->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local<v8::String>()));
6666
std::string cc = std::string(*c);
6767

6868
if (cc == "hue" || cc == "h") {
@@ -131,7 +131,7 @@ NAN_METHOD(TrackedObject::Track) {
131131
return;
132132
}
133133

134-
Matrix *im = Nan::ObjectWrap::Unwrap<Matrix>(info[0]->ToObject());
134+
Matrix *im = Nan::ObjectWrap::Unwrap<Matrix>(Nan::To<v8::Object>(info[0]).ToLocalChecked());
135135
cv::RotatedRect r;
136136

137137
if ((self->prev_rect.x < 0) || (self->prev_rect.y < 0)

src/CascadeClassifierWrap.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void CascadeClassifierWrap::Init(Local<Object> target) {
2424

2525
Nan::SetPrototypeMethod(ctor, "detectMultiScale", DetectMultiScale);
2626

27-
target->Set(Nan::New("CascadeClassifier").ToLocalChecked(), ctor->GetFunction());
27+
target->Set(Nan::New("CascadeClassifier").ToLocalChecked(), ctor->GetFunction( Nan::GetCurrentContext() ).ToLocalChecked());
2828
}
2929

3030
NAN_METHOD(CascadeClassifierWrap::New) {
@@ -41,7 +41,7 @@ NAN_METHOD(CascadeClassifierWrap::New) {
4141

4242
CascadeClassifierWrap::CascadeClassifierWrap(v8::Value* fileName) {
4343
std::string filename;
44-
filename = std::string(*Nan::Utf8String(fileName->ToString()));
44+
filename = std::string(*Nan::Utf8String(fileName->ToString(Nan::GetCurrentContext()).FromMaybe(v8::Local<v8::String>())));
4545

4646
if (!cc.load(filename.c_str())) {
4747
Nan::ThrowTypeError("Error loading file");
@@ -131,24 +131,24 @@ NAN_METHOD(CascadeClassifierWrap::DetectMultiScale) {
131131
Nan::ThrowTypeError("detectMultiScale takes at least 2 info");
132132
}
133133

134-
Matrix *im = Nan::ObjectWrap::Unwrap < Matrix > (info[0]->ToObject());
134+
Matrix *im = Nan::ObjectWrap::Unwrap < Matrix > (Nan::To<v8::Object>(info[0]).ToLocalChecked());
135135
REQ_FUN_ARG(1, cb);
136136

137137
double scale = 1.1;
138138
if (info.Length() > 2 && info[2]->IsNumber()) {
139-
scale = info[2]->NumberValue();
139+
scale = info[2].As<Number>()->Value();
140140
}
141141

142142
int neighbors = 2;
143143
if (info.Length() > 3 && info[3]->IsInt32()) {
144-
neighbors = info[3]->IntegerValue();
144+
neighbors = info[3]->IntegerValue( Nan::GetCurrentContext() ).ToChecked();
145145
}
146146

147147
int minw = 30;
148148
int minh = 30;
149149
if (info.Length() > 5 && info[4]->IsInt32() && info[5]->IsInt32()) {
150-
minw = info[4]->IntegerValue();
151-
minh = info[5]->IntegerValue();
150+
minw = info[4]->IntegerValue( Nan::GetCurrentContext() ).ToChecked();
151+
minh = info[5]->IntegerValue( Nan::GetCurrentContext() ).ToChecked();
152152
}
153153

154154
Nan::Callback *callback = new Nan::Callback(cb.As<Function>());

0 commit comments

Comments
 (0)