@@ -30,8 +30,9 @@ T get_property(const v8::Local<v8::Object> &object, const char *name) {
30
30
* This saves one string copy over using v8::String::Utf8Value.
31
31
*/
32
32
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 ]);
35
36
return str;
36
37
}
37
38
@@ -51,7 +52,8 @@ std::string get_string_property(const v8::Local<v8::Object> &object,
51
52
std::string (" must be a string" );
52
53
ThrowTypeError (msg.c_str ());
53
54
}
54
- return to_std_string (propLocal->ToString ());
55
+
56
+ return to_std_string (Nan::To<v8::String>(propLocal).ToLocalChecked ());
55
57
}
56
58
return std::string (" " );
57
59
}
@@ -73,8 +75,10 @@ class Matcher : public ObjectWrap {
73
75
SetPrototypeMethod (tpl, " removeCandidates" , RemoveCandidates);
74
76
SetPrototypeMethod (tpl, " setCandidates" , SetCandidates);
75
77
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 ());
78
82
}
79
83
80
84
static void Create (const Nan::FunctionCallbackInfo<v8::Value> &info) {
@@ -92,12 +96,12 @@ class Matcher : public ObjectWrap {
92
96
}
93
97
94
98
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 ()));
96
100
97
101
MatcherOptions options;
98
102
if (info.Length () > 1 ) {
99
103
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 ();
101
105
options.case_sensitive = get_property<bool >(options_obj, " caseSensitive" );
102
106
options.smart_case = get_property<bool >(options_obj, " smartCase" );
103
107
options.num_threads = get_property<int >(options_obj, " numThreads" );
@@ -159,7 +163,7 @@ class Matcher : public ObjectWrap {
159
163
auto id_value = ids->Get (i);
160
164
CHECK (id_value->IsUint32 (), " Expected first array to only contain unsigned 32-bit integer ids" );
161
165
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 ());
163
167
matcher->impl_ .addCandidate (id, value);
164
168
}
165
169
}
0 commit comments