Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Node CI

on: [push]

jobs:
build:
strategy:
fail-fast: false
matrix:
node-version: [8.x, 10.x, 12.x]
platform:
- { os: windows-latest, force-hunspell: true }
- { os: windows-latest }
- { os: macos-latest, force-hunspell: true }
- { os: macos-latest }
- { os: ubuntu-latest, use-clang: true }

runs-on: ${{ matrix.platform.os }}
env:
SPELLCHECKER_PREFER_HUNSPELL: ${{ matrix.platform.hunspell }}

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test (clang)
if: matrix.platform.use-clang == true
run: |
export CC="$(which clang)"
export CPP="$(which clang++)"
npm install
npm test
- name: npm install, build, and test
run: |
npm install
npm test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ build/
node_modules/
npm-debug.log

package-lock.json
.idea/
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

18 changes: 0 additions & 18 deletions appveyor.yml

This file was deleted.

15 changes: 6 additions & 9 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
{
'variables': {
'conditions': [
['OS=="mac"', {
'spellchecker_use_hunspell%': 'true',
}],
['OS=="linux"', {
'spellchecker_use_hunspell': 'true',
}],
['OS=="win"', {
'spellchecker_use_hunspell': 'true',
}],
['OS=="mac"', { 'spellchecker_use_hunspell%': 'true' },
'OS=="linux"', { 'spellchecker_use_hunspell': 'true'},
'OS=="win"', { 'spellchecker_use_hunspell': 'true' },
'OS=="freebsd"', { 'spellchecker_use_hunspell': 'true' },
{ 'spellchecker_use_hunspell': 'false' }
],
],
},
'target_defaults': {
Expand Down
90 changes: 41 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 36 additions & 3 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,14 +311,22 @@ 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
}
};

void Init(Local<Object> exports, Local<Object> module) {
Spellchecker::Init(exports);
NAN_MODULE_INIT(Init) {
Spellchecker::Init(target);
}

} // namespace

NODE_MODULE(spellchecker, Init)
#if NODE_MAJOR_VERSION >= 10
NAN_MODULE_WORKER_ENABLED(spellchecker, Init)
#else
NODE_MODULE(spellchecker, Init)
#endif
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 == 7 && V8_MINOR_VERSION > 2) || V8_MAJOR_VERSION > 7
#define V8_USE_MAYBE
#endif

namespace spellchecker {

const int USE_SYSTEM_DEFAULTS = 0;
Expand Down
Loading