Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix compilation errors on node 12 #8

Merged
merged 2 commits into from
Nov 29, 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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atom/fuzzy-native",
"version": "1.1.1",
"version": "1.1.2",
"description": "Native C++ implementation of a fuzzy string matcher.",
"main": "lib/main.js",
"scripts": {
Expand All @@ -21,7 +21,7 @@
"repository": "https://github.com/atom/fuzzy-native",
"license": "MIT",
"dependencies": {
"nan": "^2.0.0"
"nan": "^2.14.0"
},
"devDependencies": {
"jasmine-node": "^1.14.5",
Expand Down
20 changes: 12 additions & 8 deletions src/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ T get_property(const v8::Local<v8::Object> &object, const char *name) {
* This saves one string copy over using v8::String::Utf8Value.
*/
std::string to_std_string(const v8::Local<v8::String> &v8str) {
std::string str(v8str->Utf8Length(), ' ');
v8str->WriteUtf8(&str[0]);
v8::Isolate *isolate = v8::Isolate::GetCurrent();
std::string str(v8str->Utf8Length(isolate), ' ');
v8str->WriteUtf8(isolate, &str[0]);
return str;
}

Expand All @@ -51,7 +52,8 @@ std::string get_string_property(const v8::Local<v8::Object> &object,
std::string(" must be a string");
ThrowTypeError(msg.c_str());
}
return to_std_string(propLocal->ToString());

return to_std_string(Nan::To<v8::String>(propLocal).ToLocalChecked());
}
return std::string("");
}
Expand All @@ -73,8 +75,10 @@ class Matcher : public ObjectWrap {
SetPrototypeMethod(tpl, "removeCandidates", RemoveCandidates);
SetPrototypeMethod(tpl, "setCandidates", SetCandidates);

MatcherConstructor.Reset(tpl->GetFunction());
exports->Set(Nan::New("Matcher").ToLocalChecked(), tpl->GetFunction());
v8::Local<v8::Context> context = Nan::GetCurrentContext();

MatcherConstructor.Reset(tpl->GetFunction(context).ToLocalChecked());
Set(exports, Nan::New("Matcher").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked());
}

static void Create(const Nan::FunctionCallbackInfo<v8::Value> &info) {
Expand All @@ -92,12 +96,12 @@ class Matcher : public ObjectWrap {
}

CHECK(info[0]->IsString(), "First argument should be a query string");
std::string query(to_std_string(info[0]->ToString()));
std::string query(to_std_string(Nan::To<v8::String>(info[0]).ToLocalChecked()));

MatcherOptions options;
if (info.Length() > 1) {
CHECK(info[1]->IsObject(), "Second argument should be an options object");
auto options_obj = info[1]->ToObject();
auto options_obj = Nan::To<v8::Object>(info[1]).ToLocalChecked();
options.case_sensitive = get_property<bool>(options_obj, "caseSensitive");
options.smart_case = get_property<bool>(options_obj, "smartCase");
options.num_threads = get_property<int>(options_obj, "numThreads");
Expand Down Expand Up @@ -159,7 +163,7 @@ class Matcher : public ObjectWrap {
auto id_value = ids->Get(i);
CHECK(id_value->IsUint32(), "Expected first array to only contain unsigned 32-bit integer ids");
auto id = v8::Local<v8::Uint32>::Cast(id_value)->Value();
auto value = to_std_string(values->Get(i)->ToString());
auto value = to_std_string(Nan::To<v8::String>(values->Get(i)).ToLocalChecked());
matcher->impl_.addCandidate(id, value);
}
}
Expand Down