From d696b7c47afc21d5fbbcf1516ac92bcdfee021b1 Mon Sep 17 00:00:00 2001 From: Ben Demboski Date: Thu, 19 Dec 2019 11:21:57 -0800 Subject: [PATCH] Build for older and newer version of v8 --- package-lock.json | 2 +- src/main.cc | 19 +++++++++++++++++++ src/spellchecker.h | 4 ++++ src/worker.cc | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 5b3ab17..3bd3e17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -202,7 +202,7 @@ "integrity": "sha1-uDx1fIAOaOHW78GjoaE/85/23NI=", "dev": true, "requires": { - "jasmine-node": "jasmine-node@git+https://github.com/kevinsawicki/jasmine-node.git#81af4f953a2b7dfb5bde8331c05362a4b464c5ef", + "jasmine-node": "git+https://github.com/kevinsawicki/jasmine-node.git#81af4f953a2b7dfb5bde8331c05362a4b464c5ef", "underscore-plus": "1.x", "walkdir": "0.0.7" } diff --git a/src/main.cc b/src/main.cc index b834148..2ac121c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -134,6 +134,8 @@ 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(); @@ -143,6 +145,11 @@ class Spellchecker : public Nan::ObjectWrap { 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 } } @@ -226,9 +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); @@ -254,9 +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); @@ -296,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 0314e91..ed4e2e7 100644 --- a/src/worker.cc +++ b/src/worker.cc @@ -35,6 +35,7 @@ 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(); @@ -44,6 +45,11 @@ void CheckSpellingWorker::HandleOKCallback() { 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 } Local argv[] = { Nan::Null(), result };