Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"mocha": "^8.3.1",
"prebuild": "^10.0.1",
"superstring": "^2.4.2",
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#master"
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#936d976a782e75395d9b1c8c7c7bf4ba6fe0d86b"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

newer versions of tree-sitter-javascript fail with an "incompatible language version 14" error. In #127 I upgrade tree-sitter instead.

},
"scripts": {
"install": "prebuild-install || node-gyp rebuild",
Expand Down
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))
Copy link
Collaborator Author

@verhovsky verhovsky Apr 11, 2023

Choose a reason for hiding this comment

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

This change is not related to Node 19, but I couldn't resist including it. This version check is more correct and I noticed this issue because (if I recall correctly) I was prebuilding node-tree-sitter for some older Electron version which has V8 version 8.0 8.1 or 8.2 and it failed on this line.

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
5 changes: 3 additions & 2 deletions src/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <v8.h>
#include <nan.h>
#include <tree_sitter/api.h>
#include "./util.h"

namespace node_tree_sitter {

Expand Down Expand Up @@ -41,14 +42,14 @@ 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);
Nan::Call(fn, GetGlobal(fn), 3, argv);
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());
Local<Object> console = Local<Object>::Cast(Nan::Get(GetGlobal(fn), Nan::New("console").ToLocalChecked()).ToLocalChecked());
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
4 changes: 2 additions & 2 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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);
auto maybe_result_value = Nan::Call(callback, GetGlobal(callback), 2, argv);
if (try_catch.HasCaught()) return nullptr;

Local<Value> result_value;
Expand Down Expand Up @@ -364,7 +364,7 @@ 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);
Nan::Call(callback, GetGlobal(callback), 1, argv);
return;
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ bool instance_of(v8::Local<v8::Value> value, v8::Local<v8::Object> object) {
return maybe_bool.FromJust();
}

v8::Local<v8::Object> GetGlobal(v8::Local<v8::Function>& callback) {
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
return callback->GetCreationContext().ToLocalChecked()->Global();
#else
return callback->CreationContext()->Global();
#endif
}

} // namespace node_tree_sitter
2 changes: 2 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct FunctionPair {

bool instance_of(v8::Local<v8::Value> value, v8::Local<v8::Object> object);

v8::Local<v8::Object> GetGlobal(v8::Local<v8::Function>& callback);

} // namespace node_tree_sitter

#endif // NODE_TREE_SITTER_UTIL_H_