Skip to content

Migration to N-API#189

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

Migration to N-API#189
MrKashlakov wants to merge 2 commits intobnoordhuis: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!

Copy link
Copy Markdown

@gabrielschulhof gabrielschulhof left a comment

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 👍

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

#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"?

#include "nan.h"
#include "napi.h"
#include "uv.h"
#include "node_buffer.h"
Copy link
Copy Markdown

@gabrielschulhof gabrielschulhof Nov 9, 2018

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.

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.

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.

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.

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

{
'target_name': 'iconv',
'include_dirs': ['<!(node -e "require(\'nan\')")'],
'cflags!': [ '-fno-exceptions' ],
Copy link
Copy Markdown

@gabrielschulhof gabrielschulhof Nov 9, 2018

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.

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

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

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

Copy link
Copy Markdown
Owner

@bnoordhuis bnoordhuis left a comment

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.

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

'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?

},
'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.

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.

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
Copy link
Copy Markdown

NickNaso commented Feb 4, 2019

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