Skip to content

Migration to N-API - #189

Open
MrKashlakov wants to merge 2 commits into
bnoordhuis:masterfrom
MrKashlakov:n-api
Open

Migration to N-API#189
MrKashlakov wants to merge 2 commits into
bnoordhuis:masterfrom
MrKashlakov:n-api

Conversation

@MrKashlakov

Copy link
Copy Markdown

Hello!
I just did migration of this module to N-API. Please review this PR.
All tests passed!

@gabrielschulhof gabrielschulhof left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent! I'm glad you were able to address the test failures after our N-API workshop 👍

Comment thread package-lock.json
@@ -0,0 +1,18 @@
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@MrKashlakov I don't believe this file should be part of the commit. You should probably remove it.

Comment thread src/binding.cc
#include "iconv.h"
#include "nan.h"
#include "napi.h"
#include "uv.h"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@MrKashlakov why do you need "uv.h"?

Comment thread src/binding.cc
#include "nan.h"
#include "napi.h"
#include "uv.h"
#include "node_buffer.h"

@gabrielschulhof gabrielschulhof Nov 9, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@MrKashlakov I believe you can remove this include, because node-addon-api provides access to node::Buffer via N-API.

Comment thread src/binding.cc
Nan::New<FunctionTemplate>(Convert)->GetFunction());
Iconv::Init(env);
exports.Set(Napi::String::New(env, "make"),
Napi::Function::New(env, Make));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This line should be indented so the Napi::... is in the same column as the line above.

Comment thread src/binding.cc
exports.Set(Napi::String::New(env, "make"),
Napi::Function::New(env, Make));
exports.Set(Napi::String::New(env, "convert"),
Napi::Function::New(env, Convert));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same here wrt. indentation.

Comment thread src/binding.cc
using v8::String;
using v8::Value;

using namespace Napi;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You don't actually need this line, because the code uses Napi::... explicitly everywhere – which is good.

Comment thread src/binding.cc
// Forbid implicit copying.
Iconv(const Iconv&);
void operator=(const Iconv&);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This new empty line is not needed.

Comment thread binding.gyp
{
'target_name': 'iconv',
'include_dirs': ['<!(node -e "require(\'nan\')")'],
'cflags!': [ '-fno-exceptions' ],

@gabrielschulhof gabrielschulhof Nov 9, 2018

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The original version of node-iconv made sure there were no CPP exceptions. Thus, we should maintain that choice. This means that cflags! needs to be changed to cflags.

Comment thread binding.gyp
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

... and this needs to be changed to 'NO'.

Comment thread binding.gyp
'target_name': 'iconv',
'include_dirs': ['<!(node -e "require(\'nan\')")'],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

... and cflags_cc! needs to be changed to cflags_cc.

Comment thread package.json
"readmeFilename": "README.md",
"dependencies": {
"nan": "^2.11.1",
"node-addon-api": "1.6.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should be ^1.6.0 so that, when node-addon-api@1.7.0 comes out this package will start using it.

@bnoordhuis bnoordhuis left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, left some comments but mostly LGTM. I'll second Gabriel's comments.

Comment thread binding.gyp
'cflags_cc!': [ '-fno-exceptions' ],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you remove this? It's incompatible with Node.js v6.x. node-iconv can just inherit it from node's common.gypi.

Comment thread binding.gyp
'support'
],
'dependencies': [
"<!(node -p \"require('node-addon-api').gyp\")"],

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you use single quotes for consistency?

Comment thread binding.gyp
},
'msvs_settings': {
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
},

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This block should be removed.

Comment thread src/binding.cc
Napi::ObjectWrap<Iconv>(info) {
conv_ = info[0].As<Napi::External<iconv_t>>().Data();
}
iconv_t conv_;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Inconsistent indentation, and can you move conv_ back to its old place again? Cheers.

Comment thread src/binding.cc
size_t input_size = info[3].IsNumber() ? info[3].As<Napi::Number>().Uint32Value() : static_cast<uint32_t>(0);
char* output_buf = info[4].As<Napi::Buffer<char>>().Data();
size_t output_start = info[5].IsNumber() ? info[5].As<Napi::Number>().Uint32Value() : static_cast<uint32_t>(0);
size_t output_size = info[6].IsNumber() ? info[6].As<Napi::Number>().Uint32Value() : static_cast<uint32_t>(0);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why the ternaries? The JS layer always passes up numbers.

@mhdawson

Copy link
Copy Markdown

@bnoordhuis is this something you'd be able to review/consider landing?

@mhdawson

Copy link
Copy Markdown

Just confirming you are waiting on responses to your comments and once they are addressed it might move forward as we are are talking about whether we need to find somebody else to take over the pr.

@MrKashlakov are you going to be able to get back to this in order to address the comments.

@bnoordhuis

Copy link
Copy Markdown
Owner

Just confirming you are waiting on responses to your comments and once they are addressed it might move forward

That's correct. This PR also needs a rebase now.

@NickNaso

NickNaso commented Feb 4, 2019

Copy link
Copy Markdown

Hi @MrKashlakov I hope that you have the time to finish this work, but in case if you are busy what do you think if I help you to accomplish at tasks requested in this PR?

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.

5 participants