Skip to content

Commit

Permalink
Make compilable with Node 19
Browse files Browse the repository at this point in the history
  • Loading branch information
verhovsky committed Apr 11, 2023
1 parent 16f7319 commit 6ab828e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void InitConversions(Local<Object> exports) {
v8::Local<v8::Object> bufferView;
bufferView = node::Buffer::New(Isolate::GetCurrent(), point_transfer_buffer, 0, 2 * sizeof(uint32_t)).ToLocalChecked();
auto js_point_transfer_buffer = node::Buffer::Data(bufferView);
#elif V8_MAJOR_VERSION >= 8
#elif (V8_MAJOR_VERSION > 8 || (V8_MAJOR_VERSION == 8 && V8_MINOR_VERION > 3))
auto backing_store = ArrayBuffer::NewBackingStore(point_transfer_buffer, 2 * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
#else
Expand Down
14 changes: 12 additions & 2 deletions src/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,24 @@ void Logger::Log(void *payload, TSLogType type, const char *message_str) {

Local<Value> argv[3] = { name, params, type_name };
TryCatch try_catch(Isolate::GetCurrent());
Nan::Call(fn, fn->CreationContext()->Global(), 3, argv);

#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
Nan::Call(fn, fn->GetCreationContext().ToLocalChecked()->Global(), 3, argv);
#else
Nan::Call(fn, fn->CreationContext()->Global(), 3, argv);
#endif
if (try_catch.HasCaught()) {
Local<Value> log_argv[2] = {
Nan::New("Error in debug callback:").ToLocalChecked(),
try_catch.Exception()
};

Local<Object> console = Local<Object>::Cast(Nan::Get(fn->CreationContext()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());

#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
Local<Object> console = Local<Object>::Cast(Nan::Get(fn->GetCreationContext().ToLocalChecked()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());
#else
Local<Object> console = Local<Object>::Cast(Nan::Get(fn->CreationContext()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());
#endif
Local<Function> error_fn = Local<Function>::Cast(Nan::Get(console, Nan::New("error").ToLocalChecked()).ToLocalChecked());
Nan::Call(error_fn, console, 2, log_argv);
}
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static inline void setup_transfer_buffer(uint32_t node_count) {
v8::Local<v8::Object> bufferView;
bufferView = node::Buffer::New(Isolate::GetCurrent(), transfer_buffer, 0, transfer_buffer_length * sizeof(uint32_t)).ToLocalChecked();
auto js_point_transfer_buffer = node::Buffer::Data(bufferView);
#elif V8_MAJOR_VERSION >= 8
#elif (V8_MAJOR_VERSION > 8 || (V8_MAJOR_VERSION == 8 && V8_MINOR_VERION > 3))
auto backing_store = ArrayBuffer::NewBackingStore(transfer_buffer, transfer_buffer_length * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
auto js_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
#else
Expand Down
12 changes: 10 additions & 2 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ class CallbackInput {
uint32_t utf16_unit = byte / 2;
Local<Value> argv[2] = { Nan::New<Number>(utf16_unit), PointToJS(position) };
TryCatch try_catch(Isolate::GetCurrent());
auto maybe_result_value = Nan::Call(callback, callback->CreationContext()->Global(), 2, argv);
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
auto maybe_result_value = Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 2, argv);
#else
auto maybe_result_value = Nan::Call(callback, callback->CreationContext()->Global(), 2, argv);
#endif
if (try_catch.HasCaught()) return nullptr;

Local<Value> result_value;
Expand Down Expand Up @@ -364,7 +368,11 @@ void Parser::ParseTextBuffer(const Nan::FunctionCallbackInfo<Value> &info) {
delete input;
Local<Value> argv[] = {Tree::NewInstance(result)};
auto callback = info[0].As<Function>();
Nan::Call(callback, callback->CreationContext()->Global(), 1, argv);
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
Nan::Call(callback, callback->GetCreationContext().ToLocalChecked()->Global(), 1, argv);
#else
Nan::Call(callback, callback->CreationContext()->Global(), 1, argv);
#endif
return;
}
}
Expand Down

0 comments on commit 6ab828e

Please sign in to comment.