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

Commit 96b6292

Browse files
authored
Merge pull request #1 from bendemboski/fix-pre-node-12
Build for older and newer version of v8
2 parents 613ff91 + d696b7c commit 96b6292

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
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.

src/main.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class Spellchecker : public Nan::ObjectWrap {
134134
uint32_t start = iter->start, end = iter->end;
135135

136136
Local<Object> misspelled_range = Nan::New<Object>();
137+
138+
#ifdef V8_USE_MAYBE
137139
{
138140
Isolate* isolate = misspelled_range->GetIsolate();
139141
Local<Context> context = isolate->GetCurrentContext();
@@ -143,6 +145,11 @@ class Spellchecker : public Nan::ObjectWrap {
143145
Isolate* isolate = result->GetIsolate();
144146
Local<Context> context = isolate->GetCurrentContext();
145147
result->Set(context, index, misspelled_range).Check();
148+
#else
149+
misspelled_range->Set(Nan::New("start").ToLocalChecked(), Nan::New<Integer>(start));
150+
misspelled_range->Set(Nan::New("end").ToLocalChecked(), Nan::New<Integer>(end));
151+
result->Set(index, misspelled_range);
152+
#endif
146153
}
147154
}
148155

@@ -226,9 +233,13 @@ class Spellchecker : public Nan::ObjectWrap {
226233
Local<Array> result = Nan::New<Array>(dictionaries.size());
227234
for (size_t i = 0; i < dictionaries.size(); ++i) {
228235
const std::string& dict = dictionaries[i];
236+
#ifdef V8_USE_MAYBE
229237
Isolate* isolate = result->GetIsolate();
230238
Local<Context> context = isolate->GetCurrentContext();
231239
result->Set(context, i, Nan::New(dict.data(), dict.size()).ToLocalChecked()).Check();
240+
#else
241+
result->Set(i, Nan::New(dict.data(), dict.size()).ToLocalChecked());
242+
#endif
232243
}
233244

234245
info.GetReturnValue().Set(result);
@@ -254,9 +265,13 @@ class Spellchecker : public Nan::ObjectWrap {
254265
const std::string& word = corrections[i];
255266

256267
Nan::MaybeLocal<String> val = Nan::New<String>(word.data(), word.size());
268+
#ifdef V8_USE_MAYBE
257269
Isolate* isolate = result->GetIsolate();
258270
Local<Context> context = isolate->GetCurrentContext();
259271
result->Set(context, i, val.ToLocalChecked()).Check();
272+
#else
273+
result->Set(i, val.ToLocalChecked());
274+
#endif
260275
}
261276

262277
info.GetReturnValue().Set(result);
@@ -296,7 +311,11 @@ class Spellchecker : public Nan::ObjectWrap {
296311

297312
Isolate* isolate = exports->GetIsolate();
298313
Local<Context> context = isolate->GetCurrentContext();
314+
#ifdef V8_USE_MAYBE
299315
exports->Set(context, Nan::New("Spellchecker").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked()).Check();
316+
#else
317+
exports->Set(Nan::New("Spellchecker").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked());
318+
#endif
300319
}
301320
};
302321

src/spellchecker.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include <memory>
77
#include <stdint.h>
88

9+
#if V8_MAJOR_VERSION > 6 && V8_MINOR_VERSION > 2
10+
#define V8_USE_MAYBE
11+
#endif
12+
913
namespace spellchecker {
1014

1115
const int USE_SYSTEM_DEFAULTS = 0;

src/worker.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void CheckSpellingWorker::HandleOKCallback() {
3535
uint32_t start = iter->start, end = iter->end;
3636

3737
Local<Object> misspelled_range = Nan::New<Object>();
38+
#ifdef V8_USE_MAYBE
3839
{
3940
Isolate* isolate = misspelled_range->GetIsolate();
4041
Local<Context> context = isolate->GetCurrentContext();
@@ -44,6 +45,11 @@ void CheckSpellingWorker::HandleOKCallback() {
4445
Isolate* isolate = result->GetIsolate();
4546
Local<Context> context = isolate->GetCurrentContext();
4647
result->Set(context, index, misspelled_range).Check();
48+
#else
49+
misspelled_range->Set(Nan::New("start").ToLocalChecked(), Nan::New<Integer>(start));
50+
misspelled_range->Set(Nan::New("end").ToLocalChecked(), Nan::New<Integer>(end));
51+
result->Set(index, misspelled_range);
52+
#endif
4753
}
4854

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

0 commit comments

Comments
 (0)