diff --git a/package.json b/package.json index e4232aff..881ff503 100644 --- a/package.json +++ b/package.json @@ -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" }, "scripts": { "install": "prebuild-install || node-gyp rebuild", diff --git a/src/conversions.cc b/src/conversions.cc index fefe01d7..0c749dd9 100644 --- a/src/conversions.cc +++ b/src/conversions.cc @@ -34,7 +34,7 @@ void InitConversions(Local exports) { v8::Local 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 diff --git a/src/logger.cc b/src/logger.cc index 5f0cacd1..9c3d47da 100644 --- a/src/logger.cc +++ b/src/logger.cc @@ -3,6 +3,7 @@ #include #include #include +#include "./util.h" namespace node_tree_sitter { @@ -41,14 +42,14 @@ void Logger::Log(void *payload, TSLogType type, const char *message_str) { Local 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 log_argv[2] = { Nan::New("Error in debug callback:").ToLocalChecked(), try_catch.Exception() }; - Local console = Local::Cast(Nan::Get(fn->CreationContext()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked()); + Local console = Local::Cast(Nan::Get(GetGlobal(fn), Nan::New("console").ToLocalChecked()).ToLocalChecked()); Local error_fn = Local::Cast(Nan::Get(console, Nan::New("error").ToLocalChecked()).ToLocalChecked()); Nan::Call(error_fn, console, 2, log_argv); } diff --git a/src/node.cc b/src/node.cc index be9b0468..f855ec7c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -35,7 +35,7 @@ static inline void setup_transfer_buffer(uint32_t node_count) { v8::Local 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 diff --git a/src/parser.cc b/src/parser.cc index 52e1beac..12954157 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -60,7 +60,7 @@ class CallbackInput { uint32_t utf16_unit = byte / 2; Local argv[2] = { Nan::New(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 result_value; @@ -364,7 +364,7 @@ void Parser::ParseTextBuffer(const Nan::FunctionCallbackInfo &info) { delete input; Local argv[] = {Tree::NewInstance(result)}; auto callback = info[0].As(); - Nan::Call(callback, callback->CreationContext()->Global(), 1, argv); + Nan::Call(callback, GetGlobal(callback), 1, argv); return; } } diff --git a/src/util.cc b/src/util.cc index 41133c66..5ea9084f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -11,4 +11,12 @@ bool instance_of(v8::Local value, v8::Local object) { return maybe_bool.FromJust(); } +v8::Local GetGlobal(v8::Local& 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 diff --git a/src/util.h b/src/util.h index eaa7cd99..42de5d13 100644 --- a/src/util.h +++ b/src/util.h @@ -20,6 +20,8 @@ struct FunctionPair { bool instance_of(v8::Local value, v8::Local object); +v8::Local GetGlobal(v8::Local& callback); + } // namespace node_tree_sitter #endif // NODE_TREE_SITTER_UTIL_H_