diff --git a/src/main.cc b/src/main.cc index 0318ac5..2ac121c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -134,9 +134,22 @@ class Spellchecker : public Nan::ObjectWrap { uint32_t start = iter->start, end = iter->end; Local misspelled_range = Nan::New(); + +#ifdef V8_USE_MAYBE + { + Isolate* isolate = misspelled_range->GetIsolate(); + Local context = isolate->GetCurrentContext(); + misspelled_range->Set(context, Nan::New("start").ToLocalChecked(), Nan::New(start)).Check(); + misspelled_range->Set(context, Nan::New("end").ToLocalChecked(), Nan::New(end)).Check(); + } + Isolate* isolate = result->GetIsolate(); + Local context = isolate->GetCurrentContext(); + result->Set(context, index, misspelled_range).Check(); +#else misspelled_range->Set(Nan::New("start").ToLocalChecked(), Nan::New(start)); misspelled_range->Set(Nan::New("end").ToLocalChecked(), Nan::New(end)); result->Set(index, misspelled_range); +#endif } } @@ -220,7 +233,13 @@ class Spellchecker : public Nan::ObjectWrap { Local result = Nan::New(dictionaries.size()); for (size_t i = 0; i < dictionaries.size(); ++i) { const std::string& dict = dictionaries[i]; +#ifdef V8_USE_MAYBE + Isolate* isolate = result->GetIsolate(); + Local context = isolate->GetCurrentContext(); + result->Set(context, i, Nan::New(dict.data(), dict.size()).ToLocalChecked()).Check(); +#else result->Set(i, Nan::New(dict.data(), dict.size()).ToLocalChecked()); +#endif } info.GetReturnValue().Set(result); @@ -246,7 +265,13 @@ class Spellchecker : public Nan::ObjectWrap { const std::string& word = corrections[i]; Nan::MaybeLocal val = Nan::New(word.data(), word.size()); +#ifdef V8_USE_MAYBE + Isolate* isolate = result->GetIsolate(); + Local context = isolate->GetCurrentContext(); + result->Set(context, i, val.ToLocalChecked()).Check(); +#else result->Set(i, val.ToLocalChecked()); +#endif } info.GetReturnValue().Set(result); @@ -286,7 +311,11 @@ class Spellchecker : public Nan::ObjectWrap { Isolate* isolate = exports->GetIsolate(); Local context = isolate->GetCurrentContext(); +#ifdef V8_USE_MAYBE + exports->Set(context, Nan::New("Spellchecker").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()).Check(); +#else exports->Set(Nan::New("Spellchecker").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()); +#endif } }; diff --git a/src/spellchecker.h b/src/spellchecker.h index d1d9b68..a26b681 100644 --- a/src/spellchecker.h +++ b/src/spellchecker.h @@ -6,6 +6,10 @@ #include #include +#if V8_MAJOR_VERSION > 6 && V8_MINOR_VERSION > 2 +#define V8_USE_MAYBE +#endif + namespace spellchecker { const int USE_SYSTEM_DEFAULTS = 0; diff --git a/src/worker.cc b/src/worker.cc index fbae5ec..ed4e2e7 100644 --- a/src/worker.cc +++ b/src/worker.cc @@ -35,9 +35,21 @@ void CheckSpellingWorker::HandleOKCallback() { uint32_t start = iter->start, end = iter->end; Local misspelled_range = Nan::New(); +#ifdef V8_USE_MAYBE + { + Isolate* isolate = misspelled_range->GetIsolate(); + Local context = isolate->GetCurrentContext(); + misspelled_range->Set(context, Nan::New("start").ToLocalChecked(), Nan::New(start)).Check(); + misspelled_range->Set(context, Nan::New("end").ToLocalChecked(), Nan::New(end)).Check(); + } + Isolate* isolate = result->GetIsolate(); + Local context = isolate->GetCurrentContext(); + result->Set(context, index, misspelled_range).Check(); +#else misspelled_range->Set(Nan::New("start").ToLocalChecked(), Nan::New(start)); misspelled_range->Set(Nan::New("end").ToLocalChecked(), Nan::New(end)); - result->Set(index, misspelled_range); + result->Set(index, misspelled_range); +#endif } Local argv[] = { Nan::Null(), result };