Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make code compilable on Node 19 #134

Merged
merged 3 commits into from
Jun 14, 2023

Conversation

verhovsky
Copy link
Collaborator

@verhovsky verhovsky commented Apr 11, 2023

GetCreationContext was introduced in v8/v8@b38bf5b released as V8 version 9.1 (probably, I'm just looking at the git tags the commit belongs to and the state of https://github.com/v8/v8/blob/main/include/v8-version.h when the commit is made). Later they added a GetCreationContextChecked in v8/v8@91475f9 9.7.64 which does the same thing as CreationContext. CreationContext was removed in commit 46224e7 released as 10.3 (the commit says 10.2 but I think it's lying). So as per this table:

Version LTS Date V8 npm NODE_MODULE_VERSION
Node.js 20.3.0   2023-06-08 11.3.244.8 9.6.7 115
Node.js 19.9.0   2023-04-10 10.8.168.25 9.6.3 111
Node.js 18.16.0 Hydrogen 2023-04-12 10.2.154.26 9.5.1 108
Node.js 17.9.1   2022-06-01 9.6.180.15 8.11.0 102
Node.js 16.20.0 Gallium 2023-03-28 9.4.146.26 8.19.4 93
Node.js 15.14.0   2021-04-06 8.6.395.17 7.7.6 88
Node.js 14.21.3 Fermium 2023-02-16 8.4.371.23 6.14.18 83
Node.js 13.14.0   2020-04-29 7.9.317.25 6.14.4 79

node-tree-sitter is trying to use a function that doesn't exist in Node 19+. The oldest supported Electron version, Electron 22 uses V8 10.8.168.25 so this must be a problem there too, but I guess no one is using node-tree-sitter with Electron?

Note that after this commit node-tree-sitter still won't compile on Node 19+ due to the superstring dependency not supporting Node 19 for the exact same reason, but merging this shouldn't break anything.

This PR contains only the most relevant changes from #127

@@ -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.

@@ -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.

src/logger.cc Outdated
Nan::Call(fn, fn->GetCreationContext().ToLocalChecked()->Global(), 3, argv);
#else
Nan::Call(fn, fn->CreationContext()->Global(), 3, argv);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking - does NAN not provide a wrapper for this API that works across V8 versions?

If not, could you extract a conditionally-defined GetGlobal function from this, which you'd use in all of the changed call sites?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect, thanks!

@verhovsky verhovsky merged commit 7f4f49b into tree-sitter:master Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants