Skip to content

Commit 7f4f49b

Browse files
authored
Merge pull request #134 from verhovsky/node-19-smaller
Make code compilable on Node 19
2 parents 16f7319 + 6fc5bb7 commit 7f4f49b

File tree

7 files changed

+18
-7
lines changed

7 files changed

+18
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"mocha": "^8.3.1",
2525
"prebuild": "^10.0.1",
2626
"superstring": "^2.4.2",
27-
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#master"
27+
"tree-sitter-javascript": "https://github.com/tree-sitter/tree-sitter-javascript.git#936d976a782e75395d9b1c8c7c7bf4ba6fe0d86b"
2828
},
2929
"scripts": {
3030
"install": "prebuild-install || node-gyp rebuild",

src/conversions.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void InitConversions(Local<Object> exports) {
3434
v8::Local<v8::Object> bufferView;
3535
bufferView = node::Buffer::New(Isolate::GetCurrent(), point_transfer_buffer, 0, 2 * sizeof(uint32_t)).ToLocalChecked();
3636
auto js_point_transfer_buffer = node::Buffer::Data(bufferView);
37-
#elif V8_MAJOR_VERSION >= 8
37+
#elif (V8_MAJOR_VERSION > 8 || (V8_MAJOR_VERSION == 8 && V8_MINOR_VERION > 3))
3838
auto backing_store = ArrayBuffer::NewBackingStore(point_transfer_buffer, 2 * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
3939
auto js_point_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
4040
#else

src/logger.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <v8.h>
44
#include <nan.h>
55
#include <tree_sitter/api.h>
6+
#include "./util.h"
67

78
namespace node_tree_sitter {
89

@@ -41,14 +42,14 @@ void Logger::Log(void *payload, TSLogType type, const char *message_str) {
4142

4243
Local<Value> argv[3] = { name, params, type_name };
4344
TryCatch try_catch(Isolate::GetCurrent());
44-
Nan::Call(fn, fn->CreationContext()->Global(), 3, argv);
45+
Nan::Call(fn, GetGlobal(fn), 3, argv);
4546
if (try_catch.HasCaught()) {
4647
Local<Value> log_argv[2] = {
4748
Nan::New("Error in debug callback:").ToLocalChecked(),
4849
try_catch.Exception()
4950
};
5051

51-
Local<Object> console = Local<Object>::Cast(Nan::Get(fn->CreationContext()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked());
52+
Local<Object> console = Local<Object>::Cast(Nan::Get(GetGlobal(fn), Nan::New("console").ToLocalChecked()).ToLocalChecked());
5253
Local<Function> error_fn = Local<Function>::Cast(Nan::Get(console, Nan::New("error").ToLocalChecked()).ToLocalChecked());
5354
Nan::Call(error_fn, console, 2, log_argv);
5455
}

src/node.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static inline void setup_transfer_buffer(uint32_t node_count) {
3535
v8::Local<v8::Object> bufferView;
3636
bufferView = node::Buffer::New(Isolate::GetCurrent(), transfer_buffer, 0, transfer_buffer_length * sizeof(uint32_t)).ToLocalChecked();
3737
auto js_point_transfer_buffer = node::Buffer::Data(bufferView);
38-
#elif V8_MAJOR_VERSION >= 8
38+
#elif (V8_MAJOR_VERSION > 8 || (V8_MAJOR_VERSION == 8 && V8_MINOR_VERION > 3))
3939
auto backing_store = ArrayBuffer::NewBackingStore(transfer_buffer, transfer_buffer_length * sizeof(uint32_t), BackingStore::EmptyDeleter, nullptr);
4040
auto js_transfer_buffer = ArrayBuffer::New(Isolate::GetCurrent(), std::move(backing_store));
4141
#else

src/parser.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CallbackInput {
6060
uint32_t utf16_unit = byte / 2;
6161
Local<Value> argv[2] = { Nan::New<Number>(utf16_unit), PointToJS(position) };
6262
TryCatch try_catch(Isolate::GetCurrent());
63-
auto maybe_result_value = Nan::Call(callback, callback->CreationContext()->Global(), 2, argv);
63+
auto maybe_result_value = Nan::Call(callback, GetGlobal(callback), 2, argv);
6464
if (try_catch.HasCaught()) return nullptr;
6565

6666
Local<Value> result_value;
@@ -364,7 +364,7 @@ void Parser::ParseTextBuffer(const Nan::FunctionCallbackInfo<Value> &info) {
364364
delete input;
365365
Local<Value> argv[] = {Tree::NewInstance(result)};
366366
auto callback = info[0].As<Function>();
367-
Nan::Call(callback, callback->CreationContext()->Global(), 1, argv);
367+
Nan::Call(callback, GetGlobal(callback), 1, argv);
368368
return;
369369
}
370370
}

src/util.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ bool instance_of(v8::Local<v8::Value> value, v8::Local<v8::Object> object) {
1111
return maybe_bool.FromJust();
1212
}
1313

14+
v8::Local<v8::Object> GetGlobal(v8::Local<v8::Function>& callback) {
15+
#if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4))
16+
return callback->GetCreationContext().ToLocalChecked()->Global();
17+
#else
18+
return callback->CreationContext()->Global();
19+
#endif
20+
}
21+
1422
} // namespace node_tree_sitter

src/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct FunctionPair {
2020

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

23+
v8::Local<v8::Object> GetGlobal(v8::Local<v8::Function>& callback);
24+
2325
} // namespace node_tree_sitter
2426

2527
#endif // NODE_TREE_SITTER_UTIL_H_

0 commit comments

Comments
 (0)