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

Port to N-API #54

Merged
merged 1 commit into from
Dec 3, 2017
Merged

Port to N-API #54

merged 1 commit into from
Dec 3, 2017

Conversation

andreek
Copy link

@andreek andreek commented Dec 2, 2017

  • removed nan dependency
  • add node-addon-api dependency
  • port validation.cc to N-API
  • add test case for no argument given

Since node 8 there is a new experimental feature called N-API which is aimed at reducing maintenance cost for node native addons. Checkout this blog/talk for more details on its benefits.

Edit:
utf-8-validate is one of the top 35 native modules by dependency count. I used this native module first as playground to get my hands on N-API. The port to N-API is now working pretty good so I like to share this code. This should not be merged into master. N-API is still a experimental feature. It would be useful to have a napi branch. The work group is asking for feedback from productive running systems. It would be nice if this branch could be published to npm registry. Here is a guide on how to do that. But its up to you if you want to support this feature in experimental state.

@lpinca
Copy link
Member

lpinca commented Dec 2, 2017

The feature is still experimental so no, not yet.

binding.gyp Outdated
'include_dirs': ["<!(node -e \"require('nan')\")"],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be merged with the other xcode_settings below.

fallback.js Outdated
@@ -16,6 +16,11 @@
* @public
*/
const isValidUTF8 = (buf) => {

if (!buf) {
Copy link
Member

Choose a reason for hiding this comment

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

Not needed, Buffer.isBuffer() covers this.

@andreek
Copy link
Author

andreek commented Dec 3, 2017

Sorry, I failed fetching latest changes from master. Could you maybe create a n-api branch and I'll make a new PR with latest changes?

Updated description to be more clear about creating a branch instead of merging against master.

@lpinca
Copy link
Member

lpinca commented Dec 3, 2017

Yes, the branch is called n-api. Thank you.

@andreek andreek changed the base branch from master to n-api December 3, 2017 18:00
@andreek andreek force-pushed the master branch 2 times, most recently from ddda467 to 5851321 Compare December 3, 2017 18:06
}

void init(v8::Local<v8::Object> exports, v8::Local<v8::Object> module) {
Nan::SetMethod(module, "exports", isValidUTF8);
Napi::Object Init(Napi::Env env, Napi::Object exports) {
Copy link
Member

Choose a reason for hiding this comment

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

Make it static and call it init for consistency with bufferutil?

 - removed nan dependency
 - add node-addon-api dependency
 - port validation.cc to N-API
@andreek
Copy link
Author

andreek commented Dec 3, 2017

Git history seems to be working now. But dates are not linear. I don't know if this worries you.

Applied latest review change.

@lpinca lpinca merged commit 4c84b16 into websockets:n-api Dec 3, 2017
@lpinca
Copy link
Member

lpinca commented Dec 3, 2017

Thank you.

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