Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 205a55c

Browse files
porsagergaetandezeiraud
authored andcommitted
Support nodejs 13 (#13)
1 parent 412fefc commit 205a55c

3 files changed

Lines changed: 48 additions & 52 deletions

File tree

src/DiffWorkerCallback.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ DiffWorkerCallback::DiffWorkerCallback(Nan::Callback *callback, const std::strin
3434
: AsyncProgressWorkerBase(callback)
3535
{
3636
_oldfile = oldfile;
37-
_newfile = newfile;
37+
_newfile = newfile;
3838
_patchfile = patchfile;
3939
}
4040

41-
DiffWorkerCallback::~DiffWorkerCallback()
41+
DiffWorkerCallback::~DiffWorkerCallback()
4242
{ }
4343

44-
void DiffWorkerCallback::Execute(const ExecutionProgress& progress)
44+
void DiffWorkerCallback::Execute(const ExecutionProgress& progress)
4545
{
4646
char error[1024];
4747
memset(error, 0, sizeof error);
@@ -51,28 +51,28 @@ void DiffWorkerCallback::Execute(const ExecutionProgress& progress)
5151
data.progressWorker = &progress;
5252

5353
bsdiff(error, _oldfile.c_str(), _newfile.c_str(), _patchfile.c_str(), &data, &DiffWorkerCallback::CCallback);
54-
_error = error;
54+
_error = error;
5555
}
5656

57-
void DiffWorkerCallback::HandleProgressCallback(const int* data, size_t count)
57+
void DiffWorkerCallback::HandleProgressCallback(const int* data, size_t count)
5858
{
5959
if(data != nullptr)
6060
{
6161
Nan::HandleScope scope;
6262
v8::Local<v8::Value> argv[] = {
6363
v8::Number::New(v8::Isolate::GetCurrent(), *data),
64-
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), _error.c_str())
64+
Nan::New<v8::String>(_error.c_str()).ToLocalChecked()
6565
};
6666

6767
callback->Call(2, argv, this->async_resource);
6868
}
6969
}
7070

71-
void DiffWorkerCallback::HandleOKCallback()
71+
void DiffWorkerCallback::HandleOKCallback()
7272
{
73-
v8::Local<v8::Value> argv[] = {
73+
v8::Local<v8::Value> argv[] = {
7474
v8::Number::New(v8::Isolate::GetCurrent(), 100),
75-
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), _error.c_str())
75+
Nan::New<v8::String>(_error.c_str()).ToLocalChecked()
7676
};
7777
callback->Call(2, argv, this->async_resource);
7878
}

src/Main.cpp

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,46 @@
2929

3030
extern "C" {
3131
#include "c/bsdiff/bsdiff.h"
32-
#include "c/bspatch/bspatch.h"
32+
#include "c/bspatch/bspatch.h"
3333
}
3434

3535
namespace bsdpNode {
3636
using namespace v8;
3737

38-
void diff(const FunctionCallbackInfo<Value>& args)
38+
void diff(const FunctionCallbackInfo<Value>& args)
3939
{
40-
Isolate* isolate = args.GetIsolate();
41-
42-
if(args.Length() < 4 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
40+
if(args.Length() < 4 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
4341
{
44-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Invalid arguments.")));
42+
Nan::ThrowError("Invalid arguments.");
4543
return;
4644
}
47-
45+
4846
Nan::Callback *callback = new Nan::Callback(args[3].As<v8::Function>());
4947

5048
Nan::Utf8String param0(args[0]);
51-
std::string oldfile = std::string(*param0);
49+
std::string oldfile = std::string(*param0);
5250

5351
Nan::Utf8String param1(args[1]);
54-
std::string newfile = std::string(*param1);
52+
std::string newfile = std::string(*param1);
5553

5654
Nan::Utf8String param2(args[2]);
57-
std::string patchfile = std::string(*param2);
55+
std::string patchfile = std::string(*param2);
5856

5957
DiffWorkerCallback* wc = new DiffWorkerCallback(callback, oldfile, newfile, patchfile);
6058
Nan::AsyncQueueWorker(wc);
6159
}
6260

63-
void diffSync(const FunctionCallbackInfo<Value>& args)
61+
void diffSync(const FunctionCallbackInfo<Value>& args)
6462
{
6563
Isolate* isolate = args.GetIsolate();
6664
HandleScope scope(isolate);
67-
68-
if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
65+
66+
if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
6967
{
70-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Invalid arguments.")));
68+
Nan::ThrowError("Invalid arguments.");
7169
return;
7270
}
73-
71+
7472
Nan::Utf8String oldfile(args[0]);
7573
Nan::Utf8String newfile(args[1]);
7674
Nan::Utf8String patchfile(args[2]);
@@ -79,59 +77,57 @@ namespace bsdpNode {
7977
char error[1024];
8078
memset(error, 0, sizeof error);
8179

82-
int ret = bsdiff(error, *oldfile, *newfile, *patchfile, nullptr, nullptr);
80+
int ret = bsdiff(error, *oldfile, *newfile, *patchfile, nullptr, nullptr);
8381

84-
if(ret != 0)
85-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, error)));
82+
if(ret != 0)
83+
Nan::ThrowError(error);
8684
}
8785

88-
void patch(const FunctionCallbackInfo<Value>& args)
86+
void patch(const FunctionCallbackInfo<Value>& args)
8987
{
90-
Isolate* isolate = args.GetIsolate();
91-
92-
if(args.Length() < 4 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
88+
if(args.Length() < 4 || !args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
9389
{
94-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Invalid arguments.")));
90+
Nan::ThrowError("Invalid arguments.");
9591
return;
9692
}
97-
93+
9894
Nan::Callback *callback = new Nan::Callback(args[3].As<v8::Function>());
9995

10096
Nan::Utf8String param0(args[0]);
101-
std::string oldfile = std::string(*param0);
97+
std::string oldfile = std::string(*param0);
10298

10399
Nan::Utf8String param1(args[1]);
104-
std::string newfile = std::string(*param1);
100+
std::string newfile = std::string(*param1);
105101

106102
Nan::Utf8String param2(args[2]);
107-
std::string patchfile = std::string(*param2);
103+
std::string patchfile = std::string(*param2);
108104

109105
PatchWorkerCallback* wc = new PatchWorkerCallback(callback, oldfile, newfile, patchfile);
110106
Nan::AsyncQueueWorker(wc);
111107
}
112108

113-
void patchSync(const FunctionCallbackInfo<Value>& args)
109+
void patchSync(const FunctionCallbackInfo<Value>& args)
114110
{
115111
Isolate* isolate = args.GetIsolate();
116112
HandleScope scope(isolate);
117113

118-
if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
114+
if (!args[0]->IsString() || !args[1]->IsString() || !args[2]->IsString())
119115
{
120-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "Invalid arguments.")));
116+
Nan::ThrowError("Invalid arguments.");
121117
return;
122118
}
123-
119+
124120
Nan::Utf8String oldfile(args[0]);
125121
Nan::Utf8String newfile(args[1]);
126122
Nan::Utf8String patchfile(args[2]);
127123

128124
char error[1024];
129125
memset(error, 0, sizeof error);
130126

131-
int ret = bspatch(error, *oldfile, *newfile, *patchfile, nullptr, nullptr);
127+
int ret = bspatch(error, *oldfile, *newfile, *patchfile, nullptr, nullptr);
132128

133129
if(ret != 0)
134-
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, error)));
130+
Nan::ThrowError(error);
135131
}
136132

137133
void init(Local<Object> exports, Local<Object> module) {
@@ -143,4 +139,4 @@ namespace bsdpNode {
143139
}
144140

145141
NODE_MODULE(bsdp, init)
146-
}
142+
}

src/PatchWorkerCallback.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ PatchWorkerCallback::PatchWorkerCallback(Nan::Callback *callback, const std::str
3434
: AsyncProgressWorkerBase(callback)
3535
{
3636
_oldfile = oldfile;
37-
_newfile = newfile;
37+
_newfile = newfile;
3838
_patchfile = patchfile;
3939
}
4040

41-
PatchWorkerCallback::~PatchWorkerCallback()
41+
PatchWorkerCallback::~PatchWorkerCallback()
4242
{ }
4343

44-
void PatchWorkerCallback::Execute(const ExecutionProgress& progress)
44+
void PatchWorkerCallback::Execute(const ExecutionProgress& progress)
4545
{
4646
char error[1024];
4747
memset(error, 0, sizeof error);
@@ -51,28 +51,28 @@ void PatchWorkerCallback::Execute(const ExecutionProgress& progress)
5151
data.progressWorker = &progress;
5252

5353
bspatch(error, _oldfile.c_str(), _newfile.c_str(), _patchfile.c_str(), &data, &PatchWorkerCallback::CCallback);
54-
_error = error;
54+
_error = error;
5555
}
5656

57-
void PatchWorkerCallback::HandleProgressCallback(const int* data, size_t count)
57+
void PatchWorkerCallback::HandleProgressCallback(const int* data, size_t count)
5858
{
5959
if(data != nullptr)
6060
{
6161
Nan::HandleScope scope;
6262
v8::Local<v8::Value> argv[] = {
6363
v8::Number::New(v8::Isolate::GetCurrent(), *data),
64-
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), _error.c_str())
64+
Nan::New<v8::String>(_error.c_str()).ToLocalChecked()
6565
};
6666

6767
callback->Call(2, argv, this->async_resource);
6868
}
6969
}
7070

71-
void PatchWorkerCallback::HandleOKCallback()
71+
void PatchWorkerCallback::HandleOKCallback()
7272
{
73-
v8::Local<v8::Value> argv[] = {
73+
v8::Local<v8::Value> argv[] = {
7474
v8::Number::New(v8::Isolate::GetCurrent(), 100),
75-
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), _error.c_str())
75+
Nan::New<v8::String>(_error.c_str()).ToLocalChecked()
7676
};
7777
callback->Call(2, argv, this->async_resource);
7878
}

0 commit comments

Comments
 (0)