From 3ca2302ff2dbabed690b94d51033fdbf5ec446e4 Mon Sep 17 00:00:00 2001 From: simon3000 Date: Sun, 2 Jun 2019 01:24:17 +0800 Subject: [PATCH 1/4] I don't know why but it works --- lib/index.cpp | 50 ++++++++++++++++++++-------------------- lib/nodejieba.cpp | 58 +++++++++++++++++++++++------------------------ lib/utils.h | 6 ++--- package.json | 2 +- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/lib/index.cpp b/lib/index.cpp index b989fc4..7ffe0d8 100644 --- a/lib/index.cpp +++ b/lib/index.cpp @@ -1,30 +1,30 @@ #include "nodejieba.h" -void init(Handle exports) { - exports->Set(Nan::New("load").ToLocalChecked(), - Nan::New(load)->GetFunction()); - exports->Set(Nan::New("cut").ToLocalChecked(), - Nan::New(cut)->GetFunction()); - exports->Set(Nan::New("cutAll").ToLocalChecked(), - Nan::New(cutAll)->GetFunction()); - exports->Set(Nan::New("cutHMM").ToLocalChecked(), - Nan::New(cutHMM)->GetFunction()); - exports->Set(Nan::New("cutForSearch").ToLocalChecked(), - Nan::New(cutForSearch)->GetFunction()); - exports->Set(Nan::New("cutSmall").ToLocalChecked(), - Nan::New(cutSmall)->GetFunction()); - exports->Set(Nan::New("tag").ToLocalChecked(), - Nan::New(tag)->GetFunction()); - exports->Set(Nan::New("extract").ToLocalChecked(), - Nan::New(extract)->GetFunction()); - exports->Set(Nan::New("extractWithWords").ToLocalChecked(), - Nan::New(extractWithWords)->GetFunction()); - exports->Set(Nan::New("insertWord").ToLocalChecked(), - Nan::New(insertWord)->GetFunction()); - exports->Set(Nan::New("textRankExtract").ToLocalChecked(), - Nan::New(textRankExtract)->GetFunction()); - exports->Set(Nan::New("textRankExtractWithWords").ToLocalChecked(), - Nan::New(textRankExtractWithWords)->GetFunction()); +void init(Local exports) { + Nan::Set(exports,Nan::New("load").ToLocalChecked(), + Nan::GetFunction(Nan::New(load)).ToLocalChecked()); + Nan::Set(exports,Nan::New("cut").ToLocalChecked(), + Nan::GetFunction(Nan::New(cut)).ToLocalChecked()); + Nan::Set(exports,Nan::New("cutAll").ToLocalChecked(), + Nan::GetFunction(Nan::New(cutAll)).ToLocalChecked()); + Nan::Set(exports,Nan::New("cutHMM").ToLocalChecked(), + Nan::GetFunction(Nan::New(cutHMM)).ToLocalChecked()); + Nan::Set(exports,Nan::New("cutForSearch").ToLocalChecked(), + Nan::GetFunction(Nan::New(cutForSearch)).ToLocalChecked()); + Nan::Set(exports,Nan::New("cutSmall").ToLocalChecked(), + Nan::GetFunction(Nan::New(cutSmall)).ToLocalChecked()); + Nan::Set(exports,Nan::New("tag").ToLocalChecked(), + Nan::GetFunction(Nan::New(tag)).ToLocalChecked()); + Nan::Set(exports,Nan::New("extract").ToLocalChecked(), + Nan::GetFunction(Nan::New(extract)).ToLocalChecked()); + Nan::Set(exports,Nan::New("extractWithWords").ToLocalChecked(), + Nan::GetFunction(Nan::New(extractWithWords)).ToLocalChecked()); + Nan::Set(exports,Nan::New("insertWord").ToLocalChecked(), + Nan::GetFunction(Nan::New(insertWord)).ToLocalChecked()); + Nan::Set(exports,Nan::New("textRankExtract").ToLocalChecked(), + Nan::GetFunction(Nan::New(textRankExtract)).ToLocalChecked()); + Nan::Set(exports,Nan::New("textRankExtractWithWords").ToLocalChecked(), + Nan::GetFunction(Nan::New(textRankExtractWithWords)).ToLocalChecked()); } NODE_MODULE(nodejieba, init) diff --git a/lib/nodejieba.cpp b/lib/nodejieba.cpp index 0b1c1ec..389e791 100644 --- a/lib/nodejieba.cpp +++ b/lib/nodejieba.cpp @@ -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((info[0])).ToLocalChecked()); + Nan::Utf8String modelPath(Nan::To((info[1])).ToLocalChecked()); + Nan::Utf8String userDictPath(Nan::To((info[2])).ToLocalChecked()); + Nan::Utf8String idfPath(Nan::To((info[3])).ToLocalChecked()); + Nan::Utf8String stopWordsPath(Nan::To((info[4])).ToLocalChecked()); delete global_jieba_handle; global_jieba_handle = new cppjieba::Jieba(*dictPath, @@ -49,11 +49,11 @@ NAN_METHOD(insertWord) { return; } - string word = *(String::Utf8Value(info[0]->ToString())); + string word = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); string tag = "x"; if(info.Length() > 1) { - tag = *(String::Utf8Value(info[1]->ToString())); + tag = *(Nan::Utf8String(Nan::To((info[1])).ToLocalChecked())); } assert(global_jieba_handle); @@ -71,7 +71,7 @@ NAN_METHOD(insertWord) { // info.GetReturnValue().Set(Nan::New(false)); // return; // } -// string sentence = *(String::Utf8Value(info[0]->ToString())); +// string sentence = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); // vector words; // // assert(global_jieba_handle); @@ -104,11 +104,11 @@ NAN_METHOD(cut) { info.GetReturnValue().Set(Nan::New(false)); return; } - string sentence = *(String::Utf8Value(info[0]->ToString())); + string sentence = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); vector words; bool useHMM = false; if (info.Length() > 1) { - useHMM = *info[1]->ToBoolean(); + useHMM = *Nan::To((info[1])).ToLocalChecked(); } global_jieba_handle->Cut(sentence, words, useHMM); Local outArray; @@ -121,7 +121,7 @@ NAN_METHOD(cutHMM) { info.GetReturnValue().Set(Nan::New(false)); return; } - string sentence = *(String::Utf8Value(info[0]->ToString())); + string sentence = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); vector words; global_jieba_handle->CutHMM(sentence, words); Local outArray; @@ -134,7 +134,7 @@ NAN_METHOD(cutAll) { info.GetReturnValue().Set(Nan::New(false)); return; } - string sentence = *(String::Utf8Value(info[0]->ToString())); + string sentence = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); vector words; global_jieba_handle->CutAll(sentence, words); Local outArray; @@ -147,11 +147,11 @@ NAN_METHOD(cutForSearch) { info.GetReturnValue().Set(Nan::New(false)); return; } - string sentence = *(String::Utf8Value(info[0]->ToString())); + string sentence = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); vector words; bool useHMM = false; if (info.Length() > 1) { - useHMM = *info[1]->ToBoolean(); + useHMM = *Nan::To((info[1])).ToLocalChecked(); } global_jieba_handle->CutForSearch(sentence, words, useHMM); Local outArray; @@ -164,9 +164,9 @@ NAN_METHOD(cutSmall) { info.GetReturnValue().Set(Nan::New(false)); return; } - string sentence = *(String::Utf8Value(info[0]->ToString())); + string sentence = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); vector words; - size_t word_len_limit = info[1]->IntegerValue(); + size_t word_len_limit = Nan::To((info[1])).FromJust(); global_jieba_handle->CutSmall(sentence, words, word_len_limit); Local outArray; WrapVector(words, outArray); @@ -180,7 +180,7 @@ NAN_METHOD(tag) { } vector > words; - string sentence = *(String::Utf8Value(info[0]->ToString())); + string sentence = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); assert(global_jieba_handle); global_jieba_handle->Tag(sentence, words); @@ -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((info[0])).ToLocalChecked())); + size_t topN = Nan::To((info[1])).FromJust(); vector > words; // 允许的词性 string allowedPOS; if (info.Length() >= 3) { - allowedPOS = *(String::Utf8Value(info[2]->ToString())); + allowedPOS = *(Nan::Utf8String(Nan::To((info[2])).ToLocalChecked())); } assert(global_jieba_handle); @@ -228,10 +228,10 @@ NAN_METHOD(extractWithWords) { return; } - string wordsStr = *(String::Utf8Value(info[0]->ToString())); + string wordsStr = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); - size_t topN = info[1]->Int32Value(); + size_t topN = Nan::To((info[1])).FromJust(); vector > words; @@ -239,7 +239,7 @@ NAN_METHOD(extractWithWords) { string allowedPOS; if (info.Length() >= 3) { - allowedPOS = *(String::Utf8Value(info[2]->ToString())); + allowedPOS = *(Nan::Utf8String(Nan::To((info[2])).ToLocalChecked())); } assert(global_jieba_handle); @@ -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((info[0])).ToLocalChecked())); + size_t topN = Nan::To((info[1])).FromJust(); // 允许的词性 string allowedPOS; if (info.Length() >= 3) { - allowedPOS = *(String::Utf8Value(info[2]->ToString())); + allowedPOS = *(Nan::Utf8String(Nan::To((info[2])).ToLocalChecked())); } vector > words; @@ -290,15 +290,15 @@ NAN_METHOD(textRankExtractWithWords) { return; } - string wordsStr = *(String::Utf8Value(info[0]->ToString())); + string wordsStr = *(Nan::Utf8String(Nan::To((info[0])).ToLocalChecked())); - size_t topN = info[1]->Int32Value(); + size_t topN = Nan::To((info[1])).FromJust(); // 允许的词性 string allowedPOS; if (info.Length() >= 3) { - allowedPOS = *(String::Utf8Value(info[2]->ToString())); + allowedPOS = *(Nan::Utf8String(Nan::To((info[2])).ToLocalChecked())); } vector > words; diff --git a/lib/utils.h b/lib/utils.h index 1eb74c3..ef866e1 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -23,7 +23,7 @@ inline void WrapVector(vector &ov, Local &array) { inline void WrapPairVector(vector > &ov, Local &array) { array = Nan::New(ov.size()); for(size_t i = 0; i < ov.size(); i++) { - Handle obj = Nan::New(); + Local obj = Nan::New(); Local k; Local v; k = Nan::New("word").ToLocalChecked(); @@ -39,7 +39,7 @@ inline void WrapPairVector(vector > &ov, Local &array inline void WrapPairVector(vector > &ov, Local &array) { array = Nan::New(ov.size()); for(size_t i = 0; i < ov.size(); i++) { - Handle obj = Nan::New(); + Local obj = Nan::New(); Local k; Local v; k = Nan::New("word").ToLocalChecked(); @@ -53,7 +53,7 @@ inline void WrapPairVector(vector > &ov, Local &array } inline string ValueToString(Local val) { - String::Utf8Value su(val); + String::Utf8Value su(v8::Isolate::GetCurrent(), val); return string(*su); } diff --git a/package.json b/package.json index c96dc0a..b3c4ccf 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "结巴分词" ], "dependencies": { - "nan": "~2.10.0" + "nan": "^2.14.0" }, "devDependencies": { "coveralls": "~2.11.6", From a17968f6c6f577eee47b2197c0e1f8bd2617b51b Mon Sep 17 00:00:00 2001 From: simon3000 Date: Sun, 2 Jun 2019 01:45:44 +0800 Subject: [PATCH 2/4] strike ValueToString from utils.h --- lib/utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/utils.h b/lib/utils.h index ef866e1..cc03ef6 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -52,9 +52,9 @@ inline void WrapPairVector(vector > &ov, Local &array } } -inline string ValueToString(Local val) { - String::Utf8Value su(v8::Isolate::GetCurrent(), val); - return string(*su); -} +// inline string ValueToString(Local val) { +// String::Utf8Value su(v8::Isolate::GetCurrent(), val); +// return string(*su); +// } #endif From 0201afc79024a15fdbf9575cf65448de06fbb135 Mon Sep 17 00:00:00 2001 From: simon3000 Date: Sun, 2 Jun 2019 01:46:03 +0800 Subject: [PATCH 3/4] unit test v12.0.0 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a670b7c..51e438d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ node_js: - "6.9.1" - "7.1.0" - "10.0.0" + - "12.0.0" notifications: recipients: - i@yanyiwu.com From a9ba054946aeb24904412c7eae230f32cc03cd4f Mon Sep 17 00:00:00 2001 From: simon3000 Date: Sun, 2 Jun 2019 01:53:02 +0800 Subject: [PATCH 4/4] Delete package-lock.json --- package-lock.json | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 1892673..0000000 --- a/package-lock.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "nodejieba", - "version": "2.2.6", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "typescript": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.0.1.tgz", - "integrity": "sha512-zQIMOmC+372pC/CCVLqnQ0zSBiY7HHodU7mpQdjiZddek4GMj31I3dUJ7gAs9o65X7mnRma6OokOkc6f9jjfBg==", - "dev": true - } - } -}