Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build error at Node.js v12 #132

Merged
merged 4 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_js:
- "6.9.1"
- "7.1.0"
- "10.0.0"
- "12.0.0"
notifications:
recipients:
- i@yanyiwu.com
Expand Down
50 changes: 25 additions & 25 deletions lib/index.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#include "nodejieba.h"

void init(Handle<Object> exports) {
exports->Set(Nan::New<v8::String>("load").ToLocalChecked(),
Nan::New<FunctionTemplate>(load)->GetFunction());
exports->Set(Nan::New<v8::String>("cut").ToLocalChecked(),
Nan::New<FunctionTemplate>(cut)->GetFunction());
exports->Set(Nan::New<v8::String>("cutAll").ToLocalChecked(),
Nan::New<FunctionTemplate>(cutAll)->GetFunction());
exports->Set(Nan::New<v8::String>("cutHMM").ToLocalChecked(),
Nan::New<FunctionTemplate>(cutHMM)->GetFunction());
exports->Set(Nan::New<v8::String>("cutForSearch").ToLocalChecked(),
Nan::New<FunctionTemplate>(cutForSearch)->GetFunction());
exports->Set(Nan::New<v8::String>("cutSmall").ToLocalChecked(),
Nan::New<FunctionTemplate>(cutSmall)->GetFunction());
exports->Set(Nan::New<v8::String>("tag").ToLocalChecked(),
Nan::New<FunctionTemplate>(tag)->GetFunction());
exports->Set(Nan::New<v8::String>("extract").ToLocalChecked(),
Nan::New<FunctionTemplate>(extract)->GetFunction());
exports->Set(Nan::New<v8::String>("extractWithWords").ToLocalChecked(),
Nan::New<FunctionTemplate>(extractWithWords)->GetFunction());
exports->Set(Nan::New<v8::String>("insertWord").ToLocalChecked(),
Nan::New<FunctionTemplate>(insertWord)->GetFunction());
exports->Set(Nan::New<v8::String>("textRankExtract").ToLocalChecked(),
Nan::New<FunctionTemplate>(textRankExtract)->GetFunction());
exports->Set(Nan::New<v8::String>("textRankExtractWithWords").ToLocalChecked(),
Nan::New<FunctionTemplate>(textRankExtractWithWords)->GetFunction());
void init(Local<Object> exports) {
Nan::Set(exports,Nan::New<v8::String>("load").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(load)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("cut").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(cut)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("cutAll").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(cutAll)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("cutHMM").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(cutHMM)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("cutForSearch").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(cutForSearch)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("cutSmall").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(cutSmall)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("tag").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(tag)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("extract").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(extract)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("extractWithWords").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(extractWithWords)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("insertWord").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(insertWord)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("textRankExtract").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(textRankExtract)).ToLocalChecked());
Nan::Set(exports,Nan::New<v8::String>("textRankExtractWithWords").ToLocalChecked(),
Nan::GetFunction(Nan::New<FunctionTemplate>(textRankExtractWithWords)).ToLocalChecked());
}

NODE_MODULE(nodejieba, init)
58 changes: 29 additions & 29 deletions lib/nodejieba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ NAN_METHOD(load) {
return;
}

String::Utf8Value dictPath(info[0]->ToString());
String::Utf8Value modelPath(info[1]->ToString());
String::Utf8Value userDictPath(info[2]->ToString());
String::Utf8Value idfPath(info[3]->ToString());
String::Utf8Value stopWordsPath(info[4]->ToString());
Nan::Utf8String dictPath(Nan::To<v8::String>((info[0])).ToLocalChecked());
Nan::Utf8String modelPath(Nan::To<v8::String>((info[1])).ToLocalChecked());
Nan::Utf8String userDictPath(Nan::To<v8::String>((info[2])).ToLocalChecked());
Nan::Utf8String idfPath(Nan::To<v8::String>((info[3])).ToLocalChecked());
Nan::Utf8String stopWordsPath(Nan::To<v8::String>((info[4])).ToLocalChecked());

delete global_jieba_handle;
global_jieba_handle = new cppjieba::Jieba(*dictPath,
Expand Down Expand Up @@ -49,11 +49,11 @@ NAN_METHOD(insertWord) {
return;
}

string word = *(String::Utf8Value(info[0]->ToString()));
string word = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
string tag = "x";

if(info.Length() > 1) {
tag = *(String::Utf8Value(info[1]->ToString()));
tag = *(Nan::Utf8String(Nan::To<v8::String>((info[1])).ToLocalChecked()));
}

assert(global_jieba_handle);
Expand All @@ -71,7 +71,7 @@ NAN_METHOD(insertWord) {
// info.GetReturnValue().Set(Nan::New<v8::Boolean>(false));
// return;
// }
// string sentence = *(String::Utf8Value(info[0]->ToString()));
// string sentence = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
// vector<string> words;
//
// assert(global_jieba_handle);
Expand Down Expand Up @@ -104,11 +104,11 @@ NAN_METHOD(cut) {
info.GetReturnValue().Set(Nan::New<v8::Boolean>(false));
return;
}
string sentence = *(String::Utf8Value(info[0]->ToString()));
string sentence = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
vector<string> words;
bool useHMM = false;
if (info.Length() > 1) {
useHMM = *info[1]->ToBoolean();
useHMM = *Nan::To<v8::Boolean>((info[1])).ToLocalChecked();
}
global_jieba_handle->Cut(sentence, words, useHMM);
Local<Array> outArray;
Expand All @@ -121,7 +121,7 @@ NAN_METHOD(cutHMM) {
info.GetReturnValue().Set(Nan::New<v8::Boolean>(false));
return;
}
string sentence = *(String::Utf8Value(info[0]->ToString()));
string sentence = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
vector<string> words;
global_jieba_handle->CutHMM(sentence, words);
Local<Array> outArray;
Expand All @@ -134,7 +134,7 @@ NAN_METHOD(cutAll) {
info.GetReturnValue().Set(Nan::New<v8::Boolean>(false));
return;
}
string sentence = *(String::Utf8Value(info[0]->ToString()));
string sentence = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
vector<string> words;
global_jieba_handle->CutAll(sentence, words);
Local<Array> outArray;
Expand All @@ -147,11 +147,11 @@ NAN_METHOD(cutForSearch) {
info.GetReturnValue().Set(Nan::New<v8::Boolean>(false));
return;
}
string sentence = *(String::Utf8Value(info[0]->ToString()));
string sentence = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
vector<string> words;
bool useHMM = false;
if (info.Length() > 1) {
useHMM = *info[1]->ToBoolean();
useHMM = *Nan::To<v8::Boolean>((info[1])).ToLocalChecked();
}
global_jieba_handle->CutForSearch(sentence, words, useHMM);
Local<Array> outArray;
Expand All @@ -164,9 +164,9 @@ NAN_METHOD(cutSmall) {
info.GetReturnValue().Set(Nan::New<v8::Boolean>(false));
return;
}
string sentence = *(String::Utf8Value(info[0]->ToString()));
string sentence = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
vector<string> words;
size_t word_len_limit = info[1]->IntegerValue();
size_t word_len_limit = Nan::To<int32_t>((info[1])).FromJust();
global_jieba_handle->CutSmall(sentence, words, word_len_limit);
Local<Array> outArray;
WrapVector(words, outArray);
Expand All @@ -180,7 +180,7 @@ NAN_METHOD(tag) {
}

vector<pair<string, string> > words;
string sentence = *(String::Utf8Value(info[0]->ToString()));
string sentence = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
assert(global_jieba_handle);
global_jieba_handle->Tag(sentence, words);

Expand All @@ -199,15 +199,15 @@ NAN_METHOD(extract) {
return;
}

string sentence = *(String::Utf8Value(info[0]->ToString()));
size_t topN = info[1]->Int32Value();
string sentence = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
size_t topN = Nan::To<int32_t>((info[1])).FromJust();
vector<pair<string, double> > words;

// 允许的词性

string allowedPOS;
if (info.Length() >= 3) {
allowedPOS = *(String::Utf8Value(info[2]->ToString()));
allowedPOS = *(Nan::Utf8String(Nan::To<v8::String>((info[2])).ToLocalChecked()));
}

assert(global_jieba_handle);
Expand All @@ -228,18 +228,18 @@ NAN_METHOD(extractWithWords) {
return;
}

string wordsStr = *(String::Utf8Value(info[0]->ToString()));
string wordsStr = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));


size_t topN = info[1]->Int32Value();
size_t topN = Nan::To<int32_t>((info[1])).FromJust();
vector<pair<string, double> > words;


// 允许的词性

string allowedPOS;
if (info.Length() >= 3) {
allowedPOS = *(String::Utf8Value(info[2]->ToString()));
allowedPOS = *(Nan::Utf8String(Nan::To<v8::String>((info[2])).ToLocalChecked()));
}

assert(global_jieba_handle);
Expand All @@ -260,14 +260,14 @@ NAN_METHOD(textRankExtract) {
return;
}

string sentence = *(String::Utf8Value(info[0]->ToString()));
size_t topN = info[1]->Int32Value();
string sentence = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));
size_t topN = Nan::To<int32_t>((info[1])).FromJust();

// 允许的词性

string allowedPOS;
if (info.Length() >= 3) {
allowedPOS = *(String::Utf8Value(info[2]->ToString()));
allowedPOS = *(Nan::Utf8String(Nan::To<v8::String>((info[2])).ToLocalChecked()));
}
vector<pair<string, double> > words;

Expand All @@ -290,15 +290,15 @@ NAN_METHOD(textRankExtractWithWords) {
return;
}

string wordsStr = *(String::Utf8Value(info[0]->ToString()));
string wordsStr = *(Nan::Utf8String(Nan::To<v8::String>((info[0])).ToLocalChecked()));

size_t topN = info[1]->Int32Value();
size_t topN = Nan::To<int32_t>((info[1])).FromJust();

// 允许的词性

string allowedPOS;
if (info.Length() >= 3) {
allowedPOS = *(String::Utf8Value(info[2]->ToString()));
allowedPOS = *(Nan::Utf8String(Nan::To<v8::String>((info[2])).ToLocalChecked()));
}
vector<pair<string, double> > words;

Expand Down
12 changes: 6 additions & 6 deletions lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ inline void WrapVector(vector<string> &ov, Local<Array> &array) {
inline void WrapPairVector(vector<pair<string,double> > &ov, Local<Array> &array) {
array = Nan::New<v8::Array>(ov.size());
for(size_t i = 0; i < ov.size(); i++) {
Handle<v8::Object> obj = Nan::New<v8::Object>();
Local<v8::Object> obj = Nan::New<v8::Object>();
Local<Value> k;
Local<Value> v;
k = Nan::New<v8::String>("word").ToLocalChecked();
Expand All @@ -39,7 +39,7 @@ inline void WrapPairVector(vector<pair<string,double> > &ov, Local<Array> &array
inline void WrapPairVector(vector<pair<string,string> > &ov, Local<Array> &array) {
array = Nan::New<v8::Array>(ov.size());
for(size_t i = 0; i < ov.size(); i++) {
Handle<v8::Object> obj = Nan::New<v8::Object>();
Local<v8::Object> obj = Nan::New<v8::Object>();
Local<Value> k;
Local<Value> v;
k = Nan::New<v8::String>("word").ToLocalChecked();
Expand All @@ -52,9 +52,9 @@ inline void WrapPairVector(vector<pair<string,string> > &ov, Local<Array> &array
}
}

inline string ValueToString(Local<Value> val) {
String::Utf8Value su(val);
return string(*su);
}
// inline string ValueToString(Local<Value> val) {
// String::Utf8Value su(v8::Isolate::GetCurrent(), val);
// return string(*su);
// }

#endif
14 changes: 0 additions & 14 deletions package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"结巴分词"
],
"dependencies": {
"nan": "~2.10.0"
"nan": "^2.14.0"
},
"devDependencies": {
"coveralls": "~2.11.6",
Expand Down