Skip to content

Commit

Permalink
Merge pull request #3 from goddessfreya/fixees_gentz
Browse files Browse the repository at this point in the history
Fixees gentz
  • Loading branch information
goddessfreya authored Dec 20, 2019
2 parents fbb8bba + 96b6292 commit 2c0d135
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,22 @@ class Spellchecker : public Nan::ObjectWrap {
uint32_t start = iter->start, end = iter->end;

Local<Object> misspelled_range = Nan::New<Object>();

#ifdef V8_USE_MAYBE
{
Isolate* isolate = misspelled_range->GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
misspelled_range->Set(context, Nan::New("start").ToLocalChecked(), Nan::New<Integer>(start)).Check();
misspelled_range->Set(context, Nan::New("end").ToLocalChecked(), Nan::New<Integer>(end)).Check();
}
Isolate* isolate = result->GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
result->Set(context, index, misspelled_range).Check();
#else
misspelled_range->Set(Nan::New("start").ToLocalChecked(), Nan::New<Integer>(start));
misspelled_range->Set(Nan::New("end").ToLocalChecked(), Nan::New<Integer>(end));
result->Set(index, misspelled_range);
#endif
}
}

Expand Down Expand Up @@ -220,7 +233,13 @@ class Spellchecker : public Nan::ObjectWrap {
Local<Array> result = Nan::New<Array>(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> 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);
Expand All @@ -246,7 +265,13 @@ class Spellchecker : public Nan::ObjectWrap {
const std::string& word = corrections[i];

Nan::MaybeLocal<String> val = Nan::New<String>(word.data(), word.size());
#ifdef V8_USE_MAYBE
Isolate* isolate = result->GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
result->Set(context, i, val.ToLocalChecked()).Check();
#else
result->Set(i, val.ToLocalChecked());
#endif
}

info.GetReturnValue().Set(result);
Expand Down Expand Up @@ -286,7 +311,11 @@ class Spellchecker : public Nan::ObjectWrap {

Isolate* isolate = exports->GetIsolate();
Local<Context> 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
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/spellchecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <memory>
#include <stdint.h>

#if V8_MAJOR_VERSION > 6 && V8_MINOR_VERSION > 2
#define V8_USE_MAYBE
#endif

namespace spellchecker {

const int USE_SYSTEM_DEFAULTS = 0;
Expand Down
14 changes: 13 additions & 1 deletion src/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,21 @@ void CheckSpellingWorker::HandleOKCallback() {
uint32_t start = iter->start, end = iter->end;

Local<Object> misspelled_range = Nan::New<Object>();
#ifdef V8_USE_MAYBE
{
Isolate* isolate = misspelled_range->GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
misspelled_range->Set(context, Nan::New("start").ToLocalChecked(), Nan::New<Integer>(start)).Check();
misspelled_range->Set(context, Nan::New("end").ToLocalChecked(), Nan::New<Integer>(end)).Check();
}
Isolate* isolate = result->GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
result->Set(context, index, misspelled_range).Check();
#else
misspelled_range->Set(Nan::New("start").ToLocalChecked(), Nan::New<Integer>(start));
misspelled_range->Set(Nan::New("end").ToLocalChecked(), Nan::New<Integer>(end));
result->Set(index, misspelled_range);
result->Set(index, misspelled_range);
#endif
}

Local<Value> argv[] = { Nan::Null(), result };
Expand Down

0 comments on commit 2c0d135

Please sign in to comment.