Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ notifications:
node_js:
- "8"
- "10"
- "12"

before_install:
- export CXX="g++-4.9" CC="gcc-4.9"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"homepage": "https://github.com/atom/superstring",
"dependencies": {
"nan": "^2.10.0"
"nan": "^2.13.2"
},
"devDependencies": {
"chai": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/marker-index-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void MarkerIndexWrapper::init(Local<Object> exports) {
ending_string.Reset(Nan::Persistent<String>(Nan::New("ending").ToLocalChecked()));

marker_index_constructor_template.Reset(constructor_template);
exports->Set(Nan::New("MarkerIndex").ToLocalChecked(), constructor_template->GetFunction());
Nan::Set(exports, Nan::New("MarkerIndex").ToLocalChecked(), Nan::GetFunction(constructor_template).ToLocalChecked());
}

MarkerIndex *MarkerIndexWrapper::from_js(Local<Value> value) {
Expand Down Expand Up @@ -347,7 +347,7 @@ void MarkerIndexWrapper::find_boundaries_after(const Nan::FunctionCallbackInfo<V
optional<size_t> max_count;
Local<Integer> js_max_count;
if (Nan::To<Integer>(info[1]).ToLocal(&js_max_count)) {
max_count = js_max_count->NumberValue();
max_count = Nan::To<uint32_t>(js_max_count).FromMaybe(0);
}

if (start && max_count) {
Expand Down
8 changes: 5 additions & 3 deletions src/bindings/number-conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ namespace number_conversion {
optional<T> number_from_js(v8::Local<v8::Value> js_value) {
v8::Local<v8::Number> js_number;
if (Nan::To<v8::Number>(js_value).ToLocal(&js_number)) {
return js_number->NumberValue();
} else {
return optional<T>{};
auto maybe_number = Nan::To<T>(js_number);
if (maybe_number.IsJust()) {
return maybe_number.FromJust();
}
}
return optional<T>{};
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/bindings/patch-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ChangeWrapper : public Nan::ObjectWrap {

const auto &prototype_template = constructor_template->PrototypeTemplate();
prototype_template->Set(Nan::New<String>("toString").ToLocalChecked(), Nan::New<FunctionTemplate>(to_string));
change_wrapper_constructor.Reset(constructor_template->GetFunction());
change_wrapper_constructor.Reset(Nan::GetFunction(constructor_template).ToLocalChecked());
}

static Local<Value> FromChange(Patch::Change change) {
Expand Down Expand Up @@ -137,7 +137,7 @@ void PatchWrapper::init(Local<Object> exports) {
prototype_template->Set(Nan::New("getChangeCount").ToLocalChecked(), Nan::New<FunctionTemplate>(get_change_count));
prototype_template->Set(Nan::New("getBounds").ToLocalChecked(), Nan::New<FunctionTemplate>(get_bounds));
patch_wrapper_constructor_template.Reset(constructor_template_local);
patch_wrapper_constructor.Reset(constructor_template_local->GetFunction());
patch_wrapper_constructor.Reset(Nan::GetFunction(constructor_template_local).ToLocalChecked());
exports->Set(Nan::New("Patch").ToLocalChecked(), Nan::New(patch_wrapper_constructor));
}

Expand All @@ -158,10 +158,9 @@ void PatchWrapper::construct(const Nan::FunctionCallbackInfo<Value> &info) {
Local<Object> options;

if (info.Length() > 0 && Nan::To<Object>(info[0]).ToLocal(&options)) {
Local<Boolean> js_merge_adjacent_changes;
if (Nan::To<Boolean>(options->Get(Nan::New("mergeAdjacentChanges").ToLocalChecked()))
.ToLocal(&js_merge_adjacent_changes)) {
merges_adjacent_changes = js_merge_adjacent_changes->BooleanValue();
Local<Value> js_merge_adjacent_changes;
if (Nan::Get(options, Nan::New("mergeAdjacentChanges").ToLocalChecked()).ToLocal(&js_merge_adjacent_changes)) {
merges_adjacent_changes = Nan::To<bool>(js_merge_adjacent_changes).FromMaybe(false);
}
}
PatchWrapper *patch = new PatchWrapper(Patch{merges_adjacent_changes});
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/point-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static Nan::Persistent<String> column_string;
static Nan::Persistent<v8::Function> constructor;

static uint32_t number_from_js(Local<Integer> js_number) {
double number = js_number->NumberValue();
double number = Nan::To<double>(js_number).FromMaybe(0);
if (number > 0 && !std::isfinite(number)) {
return UINT32_MAX;
} else {
Expand Down Expand Up @@ -51,7 +51,7 @@ void PointWrapper::init() {
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
Nan::SetAccessor(constructor_template->InstanceTemplate(), Nan::New(row_string), get_row);
Nan::SetAccessor(constructor_template->InstanceTemplate(), Nan::New(column_string), get_column);
constructor.Reset(constructor_template->GetFunction());
constructor.Reset(Nan::GetFunction(constructor_template).ToLocalChecked());
}

Local<Value> PointWrapper::from_point(Point point) {
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/range-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void RangeWrapper::init() {
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
Nan::SetAccessor(constructor_template->InstanceTemplate(), Nan::New(start_string), get_start);
Nan::SetAccessor(constructor_template->InstanceTemplate(), Nan::New(end_string), get_end);
constructor.Reset(constructor_template->GetFunction());
constructor.Reset(Nan::GetFunction(constructor_template).ToLocalChecked());
}

Local<Value> RangeWrapper::from_range(Range range) {
Expand Down
6 changes: 6 additions & 0 deletions src/bindings/string-conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ optional<u16string> string_conversion::string_from_js(Local<Value> value) {
u16string result;
result.resize(string->Length());
string->Write(

// Nan doesn't wrap this functionality
#if NODE_MAJOR_VERSION >= 12
Isolate::GetCurrent(),
#endif

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In node 12, the v8::String::Write method changed to take a v8::Isolate as its first parameter. Usually we don't have to manually deal with different Node/V8 versions in our code, because Nan wraps these APIs for us. But Nan does not provide a wrapper for String::Write.


reinterpret_cast<uint16_t *>(&result[0]),
0,
-1,
Expand Down
4 changes: 2 additions & 2 deletions src/bindings/text-buffer-snapshot-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void TextBufferSnapshotWrapper::init() {
const auto &prototype_template = constructor_template->PrototypeTemplate();
prototype_template->Set(Nan::New("destroy").ToLocalChecked(), Nan::New<FunctionTemplate>(destroy));

snapshot_wrapper_constructor.Reset(constructor_template->GetFunction());
snapshot_wrapper_constructor.Reset(Nan::GetFunction(constructor_template).ToLocalChecked());
}

TextBufferSnapshotWrapper::TextBufferSnapshotWrapper(Local<Object> js_buffer, void *snapshot) :
Expand Down Expand Up @@ -46,7 +46,7 @@ void TextBufferSnapshotWrapper::construct(const Nan::FunctionCallbackInfo<Value>
}

void TextBufferSnapshotWrapper::destroy(const Nan::FunctionCallbackInfo<Value> &info) {
auto reader = Nan::ObjectWrap::Unwrap<TextBufferSnapshotWrapper>(info.This()->ToObject());
auto reader = Nan::ObjectWrap::Unwrap<TextBufferSnapshotWrapper>(Nan::To<Object>(info.This()).ToLocalChecked());
if (reader->snapshot) {
delete reinterpret_cast<TextBuffer::Snapshot *>(reader->snapshot);
reader->snapshot = nullptr;
Expand Down
22 changes: 12 additions & 10 deletions src/bindings/text-buffer-wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class RegexWrapper : public Nan::ObjectWrap {
js_regex = Local<RegExp>::Cast(value);
Local<Value> stored_regex = js_regex->Get(cache_key);
if (!stored_regex->IsUndefined()) {
return &Nan::ObjectWrap::Unwrap<RegexWrapper>(stored_regex->ToObject())->regex;
return &Nan::ObjectWrap::Unwrap<RegexWrapper>(Nan::To<Object>(stored_regex).ToLocalChecked())->regex;
}
js_pattern = js_regex->GetSource();
if (js_regex->GetFlags() & RegExp::kIgnoreCase) ignore_case = true;
Expand Down Expand Up @@ -127,7 +127,7 @@ class RegexWrapper : public Nan::ObjectWrap {
Local<FunctionTemplate> constructor_template = Nan::New<FunctionTemplate>(construct);
constructor_template->SetClassName(Nan::New<String>("TextBufferRegex").ToLocalChecked());
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor.Reset(constructor_template->GetFunction());
constructor.Reset(Nan::GetFunction(constructor_template).ToLocalChecked());
}
};

Expand All @@ -150,7 +150,7 @@ class SubsequenceMatchWrapper : public Nan::ObjectWrap {
Nan::SetAccessor(instance_template, Nan::New("matchIndices").ToLocalChecked(), get_match_indices);
Nan::SetAccessor(instance_template, Nan::New("score").ToLocalChecked(), get_score);

constructor.Reset(constructor_template->GetFunction());
constructor.Reset(Nan::GetFunction(constructor_template).ToLocalChecked());
}

static Local<Value> from_subsequence_match(SubsequenceMatch match) {
Expand Down Expand Up @@ -227,7 +227,7 @@ void TextBufferWrapper::init(Local<Object> exports) {
prototype_template->Set(Nan::New("getSnapshot").ToLocalChecked(), Nan::New<FunctionTemplate>(get_snapshot));
RegexWrapper::init();
SubsequenceMatchWrapper::init();
exports->Set(Nan::New("TextBuffer").ToLocalChecked(), constructor_template->GetFunction());
exports->Set(Nan::New("TextBuffer").ToLocalChecked(), Nan::GetFunction(constructor_template).ToLocalChecked());
}

void TextBufferWrapper::construct(const Nan::FunctionCallbackInfo<Value> &info) {
Expand Down Expand Up @@ -470,7 +470,7 @@ void TextBufferWrapper::find_and_mark_all_sync(const Nan::FunctionCallbackInfo<V
auto next_id = Nan::To<unsigned>(info[1]);
if (!next_id.IsJust()) return;
if (!info[2]->IsBoolean()) return;
bool exclusive = info[2]->BooleanValue();
bool exclusive = Nan::To<bool>(info[2]).FromMaybe(false);

const Regex *regex = RegexWrapper::regex_from_js(info[3]);
if (regex) {
Expand Down Expand Up @@ -628,7 +628,7 @@ void TextBufferWrapper::find_words_with_subsequence_in_range(const Nan::Function

auto query = string_conversion::string_from_js(info[0]);
auto extra_word_characters = string_conversion::string_from_js(info[1]);
auto max_count = number_conversion::number_from_js<size_t>(info[2]);
auto max_count = number_conversion::number_from_js<uint32_t>(info[2]);
auto range = RangeWrapper::range_from_js(info[3]);
auto callback = new Nan::Callback(info[4].As<Function>());

Expand Down Expand Up @@ -926,7 +926,8 @@ void TextBufferWrapper::load(const Nan::FunctionCallbackInfo<Value> &info) {

if (!force && text_buffer.is_modified()) {
Local<Value> argv[] = {Nan::Null(), Nan::Null()};
info[0].As<Function>()->Call(Nan::Null(), 2, argv);
auto callback = info[0].As<Function>();
Nan::Call(callback, callback->CreationContext()->Global(), 2, argv);
return;
}

Expand Down Expand Up @@ -958,7 +959,7 @@ void TextBufferWrapper::load(const Nan::FunctionCallbackInfo<Value> &info) {
compute_patch
);
} else {
auto text_writer = Nan::ObjectWrap::Unwrap<TextWriter>(info[4]->ToObject());
auto text_writer = Nan::ObjectWrap::Unwrap<TextWriter>(Nan::To<Object>(info[4]).ToLocalChecked());
worker = new LoadWorker(
completion_callback,
progress_callback,
Expand Down Expand Up @@ -1026,10 +1027,11 @@ void TextBufferWrapper::base_text_matches_file(const Nan::FunctionCallbackInfo<V
move(encoding_name)
));
} else {
auto file_contents = Nan::ObjectWrap::Unwrap<TextWriter>(info[1]->ToObject())->get_text();
auto file_contents = Nan::ObjectWrap::Unwrap<TextWriter>(Nan::To<Object>(info[1]).ToLocalChecked())->get_text();
bool result = std::equal(file_contents.begin(), file_contents.end(), text_buffer.base_text().begin());
Local<Value> argv[] = {Nan::Null(), Nan::New<Boolean>(result)};
info[0].As<Function>()->Call(Nan::Null(), 2, argv);
auto callback = info[0].As<Function>();
Nan::Call(callback, callback->CreationContext()->Global(), 2, argv);
}
}

Expand Down
15 changes: 8 additions & 7 deletions src/bindings/text-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void TextReader::init(Local<Object> exports) {
prototype_template->Set(Nan::New("read").ToLocalChecked(), Nan::New<FunctionTemplate>(read));
prototype_template->Set(Nan::New("end").ToLocalChecked(), Nan::New<FunctionTemplate>(end));
prototype_template->Set(Nan::New("destroy").ToLocalChecked(), Nan::New<FunctionTemplate>(destroy));
exports->Set(Nan::New("TextReader").ToLocalChecked(), constructor_template->GetFunction());
exports->Set(Nan::New("TextReader").ToLocalChecked(), Nan::GetFunction(constructor_template).ToLocalChecked());
}

TextReader::TextReader(Local<Object> js_buffer,
Expand All @@ -34,13 +34,14 @@ TextReader::~TextReader() {
}

void TextReader::construct(const Nan::FunctionCallbackInfo<Value> &info) {
auto js_text_buffer = info[0]->ToObject();
Local<Object> js_text_buffer;
if (!Nan::To<Object>(info[0]).ToLocal(&js_text_buffer)) return;
auto &text_buffer = Nan::ObjectWrap::Unwrap<TextBufferWrapper>(js_text_buffer)->text_buffer;
auto snapshot = text_buffer.create_snapshot();

Local<String> js_encoding_name;
if (!Nan::To<String>(info[1]).ToLocal(&js_encoding_name)) return;
String::Utf8Value encoding_name(js_encoding_name);
Nan::Utf8String encoding_name(js_encoding_name);
auto conversion = transcoding_to(*encoding_name);
if (!conversion) {
Nan::ThrowError((string("Invalid encoding name: ") + *encoding_name).c_str());
Expand All @@ -52,7 +53,7 @@ void TextReader::construct(const Nan::FunctionCallbackInfo<Value> &info) {
}

void TextReader::read(const Nan::FunctionCallbackInfo<Value> &info) {
TextReader *reader = Nan::ObjectWrap::Unwrap<TextReader>(info.This()->ToObject());
TextReader *reader = Nan::ObjectWrap::Unwrap<TextReader>(Nan::To<Object>(info.This()).ToLocalChecked());

if (!info[0]->IsUint8Array()) {
Nan::ThrowError("Expected a buffer");
Expand Down Expand Up @@ -87,7 +88,7 @@ void TextReader::read(const Nan::FunctionCallbackInfo<Value> &info) {
}

void TextReader::end(const Nan::FunctionCallbackInfo<Value> &info) {
TextReader *reader = Nan::ObjectWrap::Unwrap<TextReader>(info.This()->ToObject());
TextReader *reader = Nan::ObjectWrap::Unwrap<TextReader>(Nan::To<Object>(info.This()).ToLocalChecked());
if (reader->snapshot) {
reader->snapshot->flush_preceding_changes();
delete reader->snapshot;
Expand All @@ -96,9 +97,9 @@ void TextReader::end(const Nan::FunctionCallbackInfo<Value> &info) {
}

void TextReader::destroy(const Nan::FunctionCallbackInfo<Value> &info) {
TextReader *reader = Nan::ObjectWrap::Unwrap<TextReader>(info.This()->ToObject());
TextReader *reader = Nan::ObjectWrap::Unwrap<TextReader>(Nan::To<Object>(info.This()).ToLocalChecked());
if (reader->snapshot) {
delete reader->snapshot;
reader->snapshot = nullptr;
}
}
}
14 changes: 10 additions & 4 deletions src/bindings/text-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ void TextWriter::init(Local<Object> exports) {
const auto &prototype_template = constructor_template->PrototypeTemplate();
prototype_template->Set(Nan::New("write").ToLocalChecked(), Nan::New<FunctionTemplate>(write));
prototype_template->Set(Nan::New("end").ToLocalChecked(), Nan::New<FunctionTemplate>(end));
exports->Set(Nan::New("TextWriter").ToLocalChecked(), constructor_template->GetFunction());
exports->Set(Nan::New("TextWriter").ToLocalChecked(), Nan::GetFunction(constructor_template).ToLocalChecked());
}

TextWriter::TextWriter(EncodingConversion &&conversion) : conversion{move(conversion)} {}

void TextWriter::construct(const Nan::FunctionCallbackInfo<Value> &info) {
Local<String> js_encoding_name;
if (!Nan::To<String>(info[0]).ToLocal(&js_encoding_name)) return;
String::Utf8Value encoding_name(js_encoding_name);
Nan::Utf8String encoding_name(js_encoding_name);
auto conversion = transcoding_from(*encoding_name);
if (!conversion) {
Nan::ThrowError((string("Invalid encoding name: ") + *encoding_name).c_str());
Expand All @@ -34,11 +34,17 @@ void TextWriter::construct(const Nan::FunctionCallbackInfo<Value> &info) {
void TextWriter::write(const Nan::FunctionCallbackInfo<Value> &info) {
auto writer = Nan::ObjectWrap::Unwrap<TextWriter>(info.This());

if (info[0]->IsString()) {
Local<String> js_chunk = info[0]->ToString();
Local<String> js_chunk;
if (Nan::To<String>(info[0]).ToLocal(&js_chunk)) {
size_t size = writer->content.size();
writer->content.resize(size + js_chunk->Length());
js_chunk->Write(

// Nan doesn't wrap this functionality
#if NODE_MAJOR_VERSION >= 12
Isolate::GetCurrent(),
#endif

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another case where we really want to use String::Write for performance, because it allows us to reuse the std::string that we've already allocated.


reinterpret_cast<uint16_t *>(&writer->content[0]) + size,
0,
-1,
Expand Down