GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — module: add support for abi stable module API by jasongin · Pull Request #11975 · nodejs/node

Conversation

@jasongin

@jasongin jasongin commented Mar 21, 2017 •
edited by fhinkel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Add support for abi stable module API (N-API) as "Experimental feature".
The goal of this API is to provide a stable Node API for native
module developers. N-API aims to provide ABI compatibility guarantees
across different Node versions and also across different
Node VMs - allowing N-API enabled native modules to just work
across different versions and flavors of Node.js without recompilation.

A more detailed introduction is provided in:
https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md
and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf.

The feature, during its experimental state, will be guarded by a runtime
flag "--napi-modules". Only when this flag is added to the command line
will N-API modules along with regular non N-API modules be supported.

The API is defined by the methods in src/node_api.h,
src/node_api_types.h and "src/node_api_async.h". This is the best
starting point to review the API surface. More documentation will follow.

In addition to the implementation of the API using V8, which is included
in this PR, the API has also been validated against chakracore and that
port is available in
https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x.

The current plan is to provide N-API support in versions 8.X and 6.X
directly. For older versions, such as 4.X or pre N-API versions of 6.X,
we plan to create an external npm module to provide a migration path
that will allow modules targeting older Node.js versions to use the API,
albeit without getting the advantage of not having to recompile.

In addition, the external npm package will include C++ sugar to
simplify the use of the API. The sugar will be in-line only and will
only use the exported N-API methods but is not part of the N-API
itself. The current version is in:
https://github.com/nodejs/node-api.

This PR is a result of work in the abi-stable-node repo:
https://github.com/nodejs/abi-stable-node/tree/doc,
with this PR being the cumulative work on the api-prototype-8.x
branch with the following contributors in alphabetical order:

Arunesh Chandra (@aruneshchandra)
Gabriel Schulhof (@gabrielschulhof)
Hitesh Kanwathirtha (@digitalinfinity)
Ian Halliday (@ianwjhalliday)
Jason Ginchereau (@jasongin)
Michael Dawson (@mhdawson)
Sampson Gao (@sampsongao)
Taylor Woll (@boingoing)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added - IN PROGRESS
  • commit message follows commit guidelines
Affected core subsystem(s)

module

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lpinca, boingoing, aruneshchandra, jasnell, svieira, jshamley, RichiCoder1, siygle, addaleax, ChALkeR, and 9 more reacted with hooray emoji digitalinfinity, yosuke-furukawa, mcollina, matthewp, saeedtabrizi, and oshalygin reacted with heart emoji
All reactions
  • 🎉 19 reactions
  • ❤️ 6 reactions
@jasongin
module: add support for abi stable module API
43ab5a8
Add support for abi stable module API (N-API) as "Experimental feature".
The goal of this API is to provide a stable Node API for native
module developers. N-API aims to provide ABI compatibility guarantees
across different Node versions and also across different
Node VMs - allowing N-API enabled native modules to just work
across different versions and flavors of Node.js without recompilation.

A more detailed introduction is provided in:
https://github.com/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md
and https://github.com/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf.

The feature, during its experimental state, will be guarded by a runtime
flag "--napi-modules". Only when this flag is added to the command line
will N-API modules along with regular non N-API modules be supported.

The API is defined by the methods in "src/node_api.h",
"src/node_api_types.h" and "src/node_api_async.h". This is the best
starting point to review the API surface. More documentation will follow.

In addition to the implementation of the API using V8, which is included
in this PR, the API has also been validated against chakracore and that
port is available in
https://github.com/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x.

The current plan is to provide N-API support in versions 8.X and 6.X
directly. For older versions, such as 4.X or pre N-API versions of 6.X,
we plan to create an external npm module to provide a migration path
that will allow modules targeting older Node.js versions to use the API,
albeit without getting the advantage of not having to recompile.

In addition, we also plan an external npm package with C++ sugar to
simplify the use of the API. The sugar will be in-line only and will
only use the exported N-API methods but is not part of the N-API
itself. The current version is in:
https://github.com/nodejs/node-api.

This PR is a result of work in the abi-stable-node repo:
https://github.com/nodejs/abi-stable-node/tree/doc,
with this PR being the cumulative work on the api-prototype-8.x
branch with the following contributors in alphabetical order:

 Arunesh Chandra (@aruneshchandra)
 Gabriel Schulhof (@gabrielschulhof)
 Hitesh Kanwathirtha (@digitalinfinity)
 Ian Halliday (@ianwjhalliday)
 Jason Ginchereau (@jasongin)
 Michael Dawson (@mhdawson)
 Sampson Gao (@sampsongao)
 Taylor Woll (@boingoing)
@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to Node.js builds or CI infrastructure. c++ Issues and PRs that require attention from people who are familiar with C++. labels Mar 21, 2017
richardlau
richardlau reviewed Mar 21, 2017
View reviewed changes
Comment thread src/node.cc Outdated
" --trace-deprecation show stack traces on deprecations\n"
" --throw-deprecation throw an exception on deprecations\n"
" --no-warnings silence all process warnings\n"
" --napi-modules[=yes|no] load N-API modules (default no)\n"

@richardlau richardlau Mar 21, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

As the comment at the beginning of this function says:

   // XXX: If you add an option here, please also add it to doc/node.1 and
   // doc/api/cli.md

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think this would be our only option that has a [=yes|no] format (apart from configure flags, I guess). Is there a reason for that?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gabrielschulhof gabrielschulhof Mar 22, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If somebody really wants to avoid loading N-API modules even after we've eventually set the default to "yes", thus rendering the use of the command line option unnecessary, they will be unable to do so unless we give them the option to say "no".

Of course, if the consensus is that we do not need to provide users with a way to explicitly disable the support for N-API modules, then the option can be reducded to --napi-modules.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 22, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If somebody really wants to avoid loading N-API modules even after we've eventually set the default to "yes"

I'm not sure that's something that we'll need to support at that point. If N-API is successful it should become the normal way of writing native modules, so it wouldn't really make sense to disable it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mhdawson mhdawson Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I agree. Once non-experimental we would would most likely just remove the flag. I think at this point we could just likely make it --napi-modules with no options.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Fishrock123 Fishrock123 Mar 22, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I personally would prefer --napi-modules and then once it goes live we could add an optional =false or something to force-disable?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 22, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@Fishrock123 can you explain why you (or someone) might want to disable the feature after it is out of experimental status?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Fishrock123 Fishrock123 Mar 22, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

No, actually. I really do not know, but I would prefer to not have =yes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 23, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Resolved by 87c42e7

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mscdex mscdex added the addons Issues and PRs related to native addons. label Mar 21, 2017
@mhdawson mhdawson self-assigned this Mar 21, 2017
trevnorris
trevnorris reviewed Mar 21, 2017
View reviewed changes

@trevnorris trevnorris left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Quick review done. Great work on the tests. Will give more thorough review later, but only have a few small comments for now.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.h
NAPI_EXTERN napi_status napi_create_string_utf16(napi_env env,
const char16_t* s,
int length,
napi_value* result);

@trevnorris trevnorris Mar 21, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

why no napi_create_string_latin1? That's a fairly important type for string conversion.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell and addaleax reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@jasongin jasongin Mar 22, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good feedback, we should consider adding it. I opened nodejs/abi-stable-node#179 to track this.

Note missing APIs should probably not block this PR unless it is something critical. The goal for this PR is to establish an initial set of APIs that provide enough functionality for native module developers to begin experimenting and give us feedback. We have plans to expand on these APIs in the coming months, before the feature graduates out of experimental status.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mhdawson mhdawson Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

As @jasongin mentioned, we don't believe missing APIs should be a blocker. There are a few others we have in our plans to add which we will prioritized based on feedback from people using the API.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

boingoing reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread src/node_api.cc Outdated

CHECK_NEW_FROM_UTF8(isolate, prototypeString, "prototype");

auto maybe = v8Cons->Get(context, prototypeString);

@trevnorris trevnorris Mar 21, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why not use v8::Object::GetPrototype() here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 21, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Did you mean to put this comment somewhere else?

I'm guessing you might be referring to the access of the prototype property in napi_instanceof() here. In that case, it is really a function's prototype property that is needed, that is different from the __proto__ property that is returned by GetPrototype(). The "instanceof" logic had to be implemented in this way rather than using v8::FunctionTemplate::HasInstance() because N-API does not expose the V8-specific concept of function or object templates, nor does it track them internally, so the FunctionTemplate that was used to create the function passed to napi_instanceof() is not available at that point.

(There is also a napi_get_prototype() API that simply calls v8::Object::GetPrototype().)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@trevnorris trevnorris Mar 30, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

ah yup. see what you're saying.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc Outdated
RETURN_STATUS_IF_FALSE(v8impl::TryCatch::lastException().IsEmpty(), \
napi_pending_exception); \
napi_clear_last_error(); \
v8impl::TryCatch tryCatch(v8impl::V8IsolateFromJsEnv((e)))

@trevnorris trevnorris Mar 21, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks like NAP_PREAMBLE is used in many functions that don't execute javascript. what's the rational for using TryCatch when no JS is called and the v8 Maybe APIs are used?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@boingoing boingoing Mar 21, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We have made an effort to avoid using NAPI_PREAMBLE for functions which don't execute JavaScript (see napi_is_error for example) but we haven't done that exhaustively. I think we took the more conservative approach of including TryCatch when we weren't sure if it was strictly required or not because the guidance seems to be that using TryCatch was cheap enough that this would be fine. If we're sure no JavaScript is getting executed, removing the NAPI_PREAMBLE seems like the right thing to do.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 21, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Also we know we need to remove the NAPI_PREAMBLE from at least a few of the functions, for https://github.com/nodejs/abi-stable-node/issues/122 

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@trevnorris trevnorris Mar 22, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the explanation. To clarify, I don't see this as a blocker.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc Outdated
} else if (finalize_cb != nullptr) {
// Create a self-deleting reference just for the finalize callback.
new v8impl::Reference(
isolate, obj, 0, true, finalize_cb, nativeObj, finalize_hint);

@trevnorris trevnorris Mar 21, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Not sure I can appreciate this auto-magical deletion of the the pointer. One reason is because there's no way to know whether the pointer was made via new or malloc. Even in node_base_object.h there's an explicit call to make the object weak.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@trevnorris trevnorris Mar 22, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Edit: missed the "self-deleting" part. Nothing to see here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc Outdated
}

if (deleteSelf) {
delete reference;

@trevnorris trevnorris Mar 21, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It feels counter intuitive to go to such lengths to make the public API be C, but then use delete on a user-supplied pointer.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@boingoing boingoing Mar 21, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The delete here is deleting our Reference instance - not the user-supplied pointer. We aren't (hopefully) doing anything which would preclude a module written in C.

There is another delete reference in napi_delete_reference which operates on a user-supplied pointer (the napi_ref argument). We are expecting the user to hand us back a Reference* which we allocated (via new) in napi_create_reference. This Reference class acts as a container for us to do ref-counting.

If the user code calls napi_delete_reference with any random pointer, I guess behavior would be undefined. We would try to use ~Reference which might crash. But this is true of all the API which take an opaque pointer and cast it to an engine-specific type. We have a similar pattern for napi_close_handle_scope and napi_close_escapable_handle_scope.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasongin and mhdawson reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yeah, the code looks correct. I’d say for these cases it would be nice to turn the constructor private and re-expose it as a static method (New() or something), so that it’s more obvious that the instance was allocated using new. (Plus, imho it’s good practice to try and keep corresponding new and delete calls reasonably close to each other)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gabrielschulhof gabrielschulhof Mar 22, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@trevnorris it sounds like we should have a test where an addon is implemented in C, just to keep us honest.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 23, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

fb8ced4 adds New() and Delete() methods on the Reference class for clarity.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@trevnorris trevnorris Mar 30, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

my bad. misunderstood what was going on here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mhdawson mhdawson added the ctc-review label Mar 21, 2017
@mhdawson mhdawson mentioned this pull request Mar 21, 2017
Node.js Foundation Core Technical Committee (CTC) Meeting 2017-03-22 nodejs/CTC#82
Closed
@jasongin
Fix undefined snprintf use for older compiler
a5d43d1
The snprintf API is not available with older versions of MSVC. Found by a CI run.
@addaleax

addaleax commented Mar 22, 2017

Copy link
Copy Markdown
Member

Btw, in ba4847e we listed the authors as Author: name <email> as PR metadata, it looks like doing the same thing might make sense here, too?

jasongin and jasnell reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax added the module Issues and PRs related to the module subsystem. label Mar 22, 2017
addaleax
addaleax reviewed Mar 22, 2017
View reviewed changes
Comment thread src/node.cc Outdated
snprintf(errmsg,
sizeof(errmsg),
"The module '%s'"
"\nwas compiled against the Node.js API. This feature is "

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This error message could be a bit more specific than the Node.js API, I’d say. Also, maybe display the flag name here directly?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 23, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Resolved by b129624

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node.cc Outdated
" --trace-deprecation show stack traces on deprecations\n"
" --throw-deprecation throw an exception on deprecations\n"
" --no-warnings silence all process warnings\n"
" --napi-modules[=yes|no] load N-API modules (default no)\n"

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think this would be our only option that has a [=yes|no] format (apart from configure flags, I guess). Is there a reason for that?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node.cc
ProcessEmitWarning(&env, "N-API is an experimental feature "
"and could change at any time.");
}

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I’m not a fan of printing warnings like these… if the user opted into the feature, then they opted in because they know what they were asking for.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 22, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

CTC has specifically requested command-line enablement along with a warning message for features with experimental status. Tracing does the same thing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax and Fishrock123 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@mikeal mikeal Mar 23, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Is there a link somewhere to that decision?

I don't quite understand the justification for a printed warning for a feature that can't even be used without a flag. If you're using the flag, you wanted the feature and are quite aware that it is experimental. Do any V8 features do this?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@aruneshchandra aruneshchandra Mar 23, 2017

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

VM Summit 3 meeting notes has this
For 8.0, include an opt-in runtime flag, show experimental warning when a NAPI module is loaded.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 24, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If consensus is that documentation of experimental status is sufficient and this warning message is not necessary, we can take it out. I don't recall anyone feeling very strongly about this at the VM summit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@addaleax addaleax Mar 24, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@jasongin I’d say take it out, and we can re-visit that in the unlikely case anybody complains.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mhdawson mhdawson Mar 27, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think the main motivation was to ensure that anybody turning it on is fully aware of the status and to be consistent with what we have done for other experimental features.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc Outdated
v8::Local<v8::Value> l;
U(v8::Local<v8::Value> _l) : l(_l) {}
} u(local);
assert(sizeof(u.v) == sizeof(u.l));

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

static_assert for all of these

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasongin and mhdawson reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

@jasongin jasongin Mar 23, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Resolved by 116bd19

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc
} u(local);
assert(sizeof(u.v) == sizeof(u.l));
return u.v;
}

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yeah, awkward is a good description, I’m not even sure these would work if we didn’t compile with -fno-strict-aliasing. Is there anything speaking against a simple return reinterpret_cast<napi_value>(*local), at least for the V8-to-napi_value conversion?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 22, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

return reinterpret_cast<napi_value>(*local)

Yes, I agree that's correct and more straightforward. I'll update it.

(This is some of the oldest code in the N-API project; I'm guessing whoever wrote it was initially trying to avoid using reinterpret_cast<>, though the union accomplishes the same thing in a roundabout way.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

boingoing reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@jasongin jasongin Mar 23, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Resolved by 116bd19

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc Outdated
// Gets the number of CHARACTERS in the string.
napi_status napi_get_value_string_length(napi_env e,
napi_value value,
int* result) {

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It seems like int is a V8 implementation detail here too, size_t is probably better for string lengths (also here and below)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 22, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes, good point.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 23, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Resolved by 9e3ab83

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc Outdated

napi_status napi_new_instance(napi_env e,
napi_value constructor,
int argc,

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It seems to me like int is a V8 implementation detail, size_t might better for argument counts (here and elsewhere)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 23, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Resolved by 9e3ab83

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc Outdated
CHECK_ARG(ref);

v8impl::Reference* reference = reinterpret_cast<v8impl::Reference*>(ref);
delete reference;

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

(re: my comment above … maybe also make the Reference destructor private and add a Delete static? I know it might seem a bit superfluous but I think it would really help with readability)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

boingoing reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@jasongin jasongin Mar 23, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Resolved by fb8ced4

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc Outdated
v8::Isolate* isolate = v8impl::V8IsolateFromJsEnv(e);
v8::Local<v8::Context> context = isolate->GetCurrentContext();

std::vector<v8::Handle<v8::Value>> args(argc);

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

v8::Handle → v8::Local (also something for search & replace… 😄)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasongin reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@jasongin jasongin Mar 23, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Resolved by 116bd19

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/node_api.cc
napi_status napi_instanceof(napi_env e,
napi_value object,
napi_value constructor,
bool* result) {

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

If we want to support an instanceof implementation that doesn’t conform to ES6 (in that it isn’t based on [Symbol.hasInstance]()), could/should we call it something else? Alternatively, could this wrapper just manually call out to constructor[Symbol.hasInstance](object)?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jasongin jasongin Mar 22, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This does conform to ES6 instanceof. There are extensive tests at test/addons-napi/test_instanceof that re-run all of V8's instanceof tests using this API.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gabrielschulhof gabrielschulhof Mar 22, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@addaleax I implemented napi_instanceof() this way because I didn't have access to the implementation of the operator. However, if v8 provides access to an implementation that does not require retaining/acquiring the FunctionTemplate then I'd be happy to change this API. Additionally, it looks like Symbol.hasInstance() allows users to customize the behaviour of the instanceof operator, so we absolutely have to use Symbol.hasInstance() when available.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@addaleax addaleax Mar 22, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@jasongin Yeah, it matches OrdinaryHasInstance(). I’m good with just naming it that.

Otoh, it should really not be a problem for V8 to expose InstanceOf() and OrdinaryHasInstance() directly…

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gabrielschulhof pushed a commit to gabrielschulhof/abi-stable-node that referenced this pull request Mar 22, 2017
Gabriel Schulhof
doc: update to reflect new command line switch
b97d518
Re nodejs/node#11975 (comment)
@gabrielschulhof gabrielschulhof mentioned this pull request Mar 22, 2017
doc: update to reflect new command line switch nodejs/abi-stable-node#180
Closed
@jasnell jasnell added this to the 8.0.0 milestone Mar 22, 2017
This was referenced Mar 22, 2017
Use Symbol.hasInstance() for napi_instanceof on V8, when available nodejs/abi-stable-node#182
Closed
Remove [=yes|no] from runtime flag nodejs/abi-stable-node#184
Closed
gabrielschulhof pushed a commit to gabrielschulhof/abi-stable-node that referenced this pull request Mar 22, 2017
Gabriel Schulhof
napi: change napi_instanceof() to use Symbol.hasInstance
ccee0af
Re nodejs/node#11975 (comment)
Fixes nodejs#182
Closes nodejs#185
gabrielschulhof pushed a commit to gabrielschulhof/abi-stable-node that referenced this pull request Mar 22, 2017
Gabriel Schulhof
all: update --napi-modules flag to not have a yes/no
48a44c3
This updates the documentation, the error message upon module load
failure, the command line option parsing of the flag, and the way
the N-API addon tests pass the flag to node.

Re nodejs/node#11975 (comment)
Re nodejs/node#11975 (comment)
Fixes nodejs#184
@gabrielschulhof gabrielschulhof mentioned this pull request Mar 22, 2017
all: update --napi-modules flag to not have a yes/no nodejs/abi-stable-node#186
Closed
This was referenced Mar 22, 2017
Address some minor PR feedback nodejs/abi-stable-node#187
Merged
Use ref/unref terminology instead of addref/release nodejs/abi-stable-node#188
Closed
@jasongin jasongin mentioned this pull request Mar 22, 2017
Type-checking when getting values nodejs/abi-stable-node#191
Closed
@mhdawson mhdawson added the semver-minor PRs that contain new features and should be released in the next minor version. label Mar 22, 2017
@boingoing boingoing mentioned this pull request Mar 23, 2017
Convert all locals and parameter names to snake_case nodejs/abi-stable-node#193
Merged
Gabriel Schulhof
all: update --napi-modules flag to not have a yes/no
87c42e7
This updates the documentation, the error message upon module load
failure, the command line option parsing of the flag, and the way
the N-API addon tests pass the flag to node.

Re nodejs#11975 (comment)
Re nodejs#11975 (comment)
Fixes nodejs/abi-stable-node#184
Closes nodejs/abi-stable-node#186
@Trott Trott mentioned this pull request Apr 3, 2017
Node.js Foundation Core Technical Committee (CTC) Meeting 2017-04-05 nodejs/CTC#93
Closed
@addaleax

ghost commented Apr 3, 2017

Copy link
Copy Markdown
Member

Landed in 56e881d 🎉

@nodejs/abi-stable-node I think that also means that from now on you can open PRs against this repository instead of nodejs/abi-stable-node. :)

gabrielschulhof, jasnell, mhdawson, aruneshchandra, boingoing, hiroppy, piccoloaiutante, and fhinkel reacted with hooray emoji
All reactions
  • 🎉 8 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax closed this Apr 3, 2017
@addaleax addaleax removed the ctc-review label Apr 3, 2017
@mykmelez mykmelez mentioned this pull request Apr 4, 2017
Merge node mozilla/spidernode#372
Closed
@jasnell jasnell mentioned this pull request Apr 4, 2017
8.0.0 Release Proposal #12220
Closed
@RReverser RReverser mentioned this pull request Apr 5, 2017
New Node.js NAPI neon-bindings/neon#202
Closed
@addaleax addaleax mentioned this pull request Apr 6, 2017
n-api: implement async helper methods #12250
Closed
3 tasks done
@jasnell jasnell mentioned this pull request Apr 25, 2017
Collaborator nominations #12646
Closed
@addaleax addaleax mentioned this pull request Apr 29, 2017
doc: adding "rules of thumb" #12744
Closed
2 tasks done
@jasongin jasongin mentioned this pull request May 8, 2017
Merge N-API JSRT implementation from abi-stable-node nodejs/node-chakracore#238
Merged
3 tasks done
@bnoordhuis bnoordhuis mentioned this pull request Mar 16, 2018
Adding Websocket support to core #19308
Closed
@MylesBorins MylesBorins mentioned this pull request Apr 16, 2018
v6.14.2 proposal #19996
Merged
@bnoordhuis bnoordhuis mentioned this pull request Apr 18, 2018
src: kickstart addon by calling its constructor #20114
Closed
3 of 4 tasks
@vmoroz vmoroz mentioned this pull request Jan 25, 2023
node-api: deprecate napi_module_register based registration #46319
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@addaleax addaleax addaleax approved these changes
@gabrielschulhof gabrielschulhof gabrielschulhof left review comments
@richardlau richardlau richardlau left review comments
@jasnell jasnell jasnell approved these changes
+7 more reviewers
@mikeal mikeal mikeal left review comments
@trevnorris trevnorris trevnorris left review comments
@Fishrock123 Fishrock123 Fishrock123 left review comments
@boingoing boingoing boingoing left review comments
@kkoopa kkoopa kkoopa left review comments
@mhdawson mhdawson mhdawson left review comments
@aruneshchandra aruneshchandra aruneshchandra left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@mhdawson mhdawson

Labels

addons Issues and PRs related to native addons. build Issues and PRs related to Node.js builds or CI infrastructure. c++ Issues and PRs that require attention from people who are familiar with C++. module Issues and PRs related to the module subsystem. node-api Issues and PRs related to Node-API. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

15 participants

@jasongin @addaleax @mhdawson @jasnell @gabrielschulhof @aruneshchandra @kunalspathak @Fishrock123 @kkoopa @mikeal @trevnorris @boingoing @richardlau @mscdex @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.