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

Commit e8a53b7

Browse files
authored
Merge pull request #8 from atom/build-error-node-12
Fix compilation errors on node 12
2 parents db2472e + 75f06ba commit e8a53b7

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@atom/fuzzy-native",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "Native C++ implementation of a fuzzy string matcher.",
55
"main": "lib/main.js",
66
"scripts": {
@@ -21,7 +21,7 @@
2121
"repository": "https://github.com/atom/fuzzy-native",
2222
"license": "MIT",
2323
"dependencies": {
24-
"nan": "^2.0.0"
24+
"nan": "^2.14.0"
2525
},
2626
"devDependencies": {
2727
"jasmine-node": "^1.14.5",

src/binding.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ T get_property(const v8::Local<v8::Object> &object, const char *name) {
3030
* This saves one string copy over using v8::String::Utf8Value.
3131
*/
3232
std::string to_std_string(const v8::Local<v8::String> &v8str) {
33-
std::string str(v8str->Utf8Length(), ' ');
34-
v8str->WriteUtf8(&str[0]);
33+
v8::Isolate *isolate = v8::Isolate::GetCurrent();
34+
std::string str(v8str->Utf8Length(isolate), ' ');
35+
v8str->WriteUtf8(isolate, &str[0]);
3536
return str;
3637
}
3738

@@ -51,7 +52,8 @@ std::string get_string_property(const v8::Local<v8::Object> &object,
5152
std::string(" must be a string");
5253
ThrowTypeError(msg.c_str());
5354
}
54-
return to_std_string(propLocal->ToString());
55+
56+
return to_std_string(Nan::To<v8::String>(propLocal).ToLocalChecked());
5557
}
5658
return std::string("");
5759
}
@@ -73,8 +75,10 @@ class Matcher : public ObjectWrap {
7375
SetPrototypeMethod(tpl, "removeCandidates", RemoveCandidates);
7476
SetPrototypeMethod(tpl, "setCandidates", SetCandidates);
7577

76-
MatcherConstructor.Reset(tpl->GetFunction());
77-
exports->Set(Nan::New("Matcher").ToLocalChecked(), tpl->GetFunction());
78+
v8::Local<v8::Context> context = Nan::GetCurrentContext();
79+
80+
MatcherConstructor.Reset(tpl->GetFunction(context).ToLocalChecked());
81+
Set(exports, Nan::New("Matcher").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked());
7882
}
7983

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

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

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

0 commit comments

Comments
 (0)