|
3 | 3 | #include <v8.h> |
4 | 4 | #include <nan.h> |
5 | 5 | #include <tree_sitter/api.h> |
| 6 | +#include "./util.h" |
6 | 7 |
|
7 | 8 | namespace node_tree_sitter { |
8 | 9 |
|
@@ -41,24 +42,14 @@ void Logger::Log(void *payload, TSLogType type, const char *message_str) { |
41 | 42 |
|
42 | 43 | Local<Value> argv[3] = { name, params, type_name }; |
43 | 44 | TryCatch try_catch(Isolate::GetCurrent()); |
44 | | - |
45 | | - #if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4)) |
46 | | - Nan::Call(fn, fn->GetCreationContext().ToLocalChecked()->Global(), 3, argv); |
47 | | - #else |
48 | | - Nan::Call(fn, fn->CreationContext()->Global(), 3, argv); |
49 | | - #endif |
| 45 | + Nan::Call(fn, GetGlobal(fn), 3, argv); |
50 | 46 | if (try_catch.HasCaught()) { |
51 | 47 | Local<Value> log_argv[2] = { |
52 | 48 | Nan::New("Error in debug callback:").ToLocalChecked(), |
53 | 49 | try_catch.Exception() |
54 | 50 | }; |
55 | 51 |
|
56 | | - |
57 | | - #if (V8_MAJOR_VERSION > 9 || (V8_MAJOR_VERSION == 9 && V8_MINOR_VERION > 4)) |
58 | | - Local<Object> console = Local<Object>::Cast(Nan::Get(fn->GetCreationContext().ToLocalChecked()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked()); |
59 | | - #else |
60 | | - Local<Object> console = Local<Object>::Cast(Nan::Get(fn->CreationContext()->Global(), Nan::New("console").ToLocalChecked()).ToLocalChecked()); |
61 | | - #endif |
| 52 | + Local<Object> console = Local<Object>::Cast(Nan::Get(GetGlobal(fn), Nan::New("console").ToLocalChecked()).ToLocalChecked()); |
62 | 53 | Local<Function> error_fn = Local<Function>::Cast(Nan::Get(console, Nan::New("error").ToLocalChecked()).ToLocalChecked()); |
63 | 54 | Nan::Call(error_fn, console, 2, log_argv); |
64 | 55 | } |
|
0 commit comments