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

[6.x] n-api: backport to v6.x #19447

Closed

Conversation

@gabrielschulhof
Copy link
Contributor

commented Mar 19, 2018

  • src/node_api_backport.cc and src/node_api_backport.h are added
    containing stubs for internal APIs used by N-API.

  • expectsError() is brought in from master and added to
    tests/common/index.js.

  • N-API tests involving the JS async_hooks module are removed.

  • The following commits are partially or completely applied:

f24d0ec 6a5a9ad d20f1f0 5fb6f7f cd7d7b1 a03c90b
33e63fe 48b5c11 35c7238 d83f830 449d1c8 c698017
a29089d 9cb96ac 945eb1b 6e1c25c 463d1a4 caee112
755e07c a1bab82 2bead4b 1729af2 fe442f6 d3569b6
5ecd2e1 6101bd2 d379db3 a555397 c2b9048 629a447
47f664e 1286923 0c16b18 6e312c5 6c1906a c123467
f054855 f7c709f c90185c 316b5ef f75bc2c 3e06276
8938c4c 91c1ccd 8a86d9c 93acfe5 094d92b 94e2951
246aeac a893e79 ef49f55 d4cd8c2 50afd90 2475676
ff9a6bc 12c8b4d dc389bf 493340f 8f2c366 a4a9a3d
9cf3525 97ba69f 959c425 9b4ab14 51f92b6 e0b1394
3ee524b f2cb78c e04d23c 2336df1 0736ad4 201ecef
e07e708 7be4a84 b3f9b38 6bc82da a1c0804 f881789
3594223 17b818b 4957726 b33b3e1 84579b1 e6e58fd
cec6e21 05e4c1d 8b90250 a406a32 3070d53 a8c0a43
1976654 973c12f 0c258bd 92e5f5c 1a0727d 8c8c90b
290315a cb94905 a10856a 61e9ba1 7828698 1cdb41f
c77e6d3 7efb8f7 6c382de 82bad0b 70664bf e96b949
1fe0741 85d7d97 e6eb5c0 835c383 b72e702 af70c3b
ad664ea f3afe29 6968ead aa6fac6 77ca3cb 9926dfe
7849b52 e59987c 57a4ceb 4d1e086 bb29405 65eefa0
e3f7a54 73078d6 ac41db4 598a128 f52c707 d5b397c
8f3dab4 9c6804c 29df1a8 34cf8ad e36917b c9b6d95
ea927b3 732ae41 f803e77 0f1888f a71d205 ef28d85
3e18c49 d291338 ecf6a46 62e940d ca8a29c 2529119
01f4d9a c28418a df46fcb 7d9dfda ddba969 bd4b790
062071a 7a7ac1c 8ab8c33 fd54b10 bb91879 43e4efd
effeff1 d9ee297 1961900 2af49b6 260cd41 47919b3
f3ef971 bfade5a 4a7b7e8 a63b245 0dd8b9a 0083011
47c3c58 1b28022 9516aa1 abfd4bf 654afa2 147048a
2e3fef7 2bbabb1 0a734fe 73d9c0f 94a120c 8aca66a
cd32b77 a180259 0142276 deb9622 972bfe1 4271254
1d96803 4241577 b7a341d ba7bac5 468275a 6c60691
70b51c8 9d52222 46f2026 ad5f987 8bd26d3 9de2e15
0ec0272 affe0f2 9decfb1 ca786c3 afd5966 8fbace1
8460284 0a5bf4a 491d59d 4a21e39 56e881d

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

@gabrielschulhof gabrielschulhof force-pushed the gabrielschulhof:v6.x-backport-n-api branch 2 times, most recently from 95aece3 to 17f4970 Mar 19, 2018

@gabrielschulhof

This comment has been minimized.

Copy link
Contributor Author

commented Mar 19, 2018

@MylesBorins

This comment has been minimized.

Copy link
Member

commented Mar 20, 2018

@gabrielschulhof great work. Is this landed with the experimental flag in place? We may want to consider doing a semver minor for this... not 100%. We were not planning another minor for 6.x before it went into maintenance mode though

/cc @nodejs/lts, thoughts?

@gabrielschulhof

This comment has been minimized.

Copy link
Contributor Author

commented Mar 20, 2018

@gabrielschulhof

This comment has been minimized.

Copy link
Contributor Author

commented Mar 20, 2018

@gabrielschulhof

This comment has been minimized.

Copy link
Contributor Author

commented Mar 20, 2018

@MylesBorins

This comment has been minimized.

Copy link
Member

commented Mar 20, 2018

There is another PR that was just opened that would be semver minor against 6.x as well

I'll open an issue in the release repo tomorrow to discuss it

@gabrielschulhof

This comment has been minimized.

Copy link
Contributor Author

commented Mar 20, 2018

@mhdawson

This comment has been minimized.

Copy link
Member

commented Mar 20, 2018

@gabrielschulhof thanks for all the hard work on this.

@gabrielschulhof

This comment has been minimized.

Copy link
Contributor Author

commented Mar 20, 2018

@mhdawson NP! Happy to help!

@gabrielschulhof gabrielschulhof force-pushed the gabrielschulhof:v6.x-backport-n-api branch from 17f4970 to f0872f3 Mar 22, 2018

@gabrielschulhof gabrielschulhof force-pushed the gabrielschulhof:v6.x-backport-n-api branch from f0872f3 to a80ec42 Apr 6, 2018

@gabrielschulhof

This comment has been minimized.

Copy link
Contributor Author

commented Apr 6, 2018

@MylesBorins I have now re-done this backport with complete commits as much as possible, much like the v8.x backport.

@gabrielschulhof gabrielschulhof changed the base branch from v6.x to v6.x-staging Apr 6, 2018

@gabrielschulhof gabrielschulhof force-pushed the gabrielschulhof:v6.x-backport-n-api branch from a80ec42 to 2966812 Apr 6, 2018

@MylesBorins

This comment has been minimized.

Copy link
Member

commented Apr 6, 2018

@nodejs/tsc @nodejs/lts if we want to land this we will have to do another semver-minor of v6.x, which I am somewhat uncomfortable with doing just before going into maintenance mode.

@mhdawson @jasnell @rvagg @addaleax @ofrobots who all may have particular thoughts here

@cjihrig

This comment has been minimized.

Copy link
Contributor

commented Apr 6, 2018

I think I'm in favor. It would be nice to have N-API in all of the supported release lines.

@mcollina

This comment has been minimized.

Copy link
Member

commented Apr 6, 2018

I’m in favor!

@MylesBorins

This comment has been minimized.

Copy link
Member

commented Apr 6, 2018

204 commits on 569 files with less than a month before maintenance... we don't even have time to follow our process for testing a semver-minor. I'm floating between -0 and -1. Looking forward to more people chiming in

@mcollina

This comment has been minimized.

Copy link
Member

commented Apr 6, 2018

@gabrielschulhof I think several commits got pulled in that have absolutely no relation to n-api. As an example, the whole reformatting of the docs to 80-chars width has been pulled in, and a change in the eslint. Those would have to be removed IMHO. @MylesBorins those are the the vast majority of the changed and the touched files.

@mcollina

This comment has been minimized.

Copy link
Member

commented Apr 6, 2018

Specifically 66e6d0b and 0b2d5bc (this one is 243 files!)

@rvagg

This comment has been minimized.

Copy link
Member

commented Apr 6, 2018

wow, lots of work here, +1 from me as long as you think it's fairly low risk .. I haven't reviewed the changeset but if there are any major departures to how it's been applied to 8.x+ could you let us know so we can have some idea of areas of risk?

@mcollina

This comment has been minimized.

Copy link
Member

commented Apr 6, 2018

wow, lots of work here, +1 from me as long as you think it's fairly low risk .. I haven't reviewed the changeset but if there are any major departures to how it's been applied to 8.x+ could you let us know so we can have some idea of areas of risk?

The vast majority of the touched files are just for linting changes, so it's very hard to review. IMHO the changes in itself is relatively low risk (as long as it passes CITGM and we can verify that n-api modules works here and in 8), as it's a new feature.

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: remove extra reference from test
Backport-PR-URL: #19447
PR-URL: #18542
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

doc: fix typo in n-api.md
Backport-PR-URL: #19447
PR-URL: #18590
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

test: improve error message output
Backport-PR-URL: #19447
PR-URL: #18498
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

test: convert new tests to use error types
Backport-PR-URL: #19447
PR-URL: #18581
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

doc: fix exporting a function example
Missing the length argument in napi_create_function.

Backport-PR-URL: #19447
PR-URL: #18661
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

doc: mark NAPI_AUTO_LENGTH as code
Backport-PR-URL: #19447
PR-URL: #18697
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

test: remove unnecessary timer
The timer in NAPI's test_callback_scope/test-resolve-async.js
can be removed. If the test fails, it will timeout on its own.
The extra timer increases the chances of the test being
flaky.

Backport-PR-URL: #19447
PR-URL: #18719
Fixes: #18702
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: fix object test
Passing a pointer to a static integer is sufficient for the test.

Backport-PR-URL: #19447
PR-URL: #19039
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

doc: fix n-api asynchronous threading docs
Documentation for N-API Custom Asynchronous Operations incorrectly
stated that async execution happens on the main event loop.
Added details to napi_create_async_work about which threads are
used to invoke the execute and complete callbacks.

Changed 'async' to 'asynchronous' in the documentation for Custom
Asynchronous Operations. Changed "executes in parallel" to "can
execute in parallel" for the documentation of napi_create_async_work
execute parameter.

Backport-PR-URL: #19447
PR-URL: #19073
Fixes: #19071
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: update reference test
Remove the necessity for allocating on the heap, and assert that the
correct pointer gets passed to the finalizer.

Backport-PR-URL: #19447
PR-URL: #19086
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: update documentation
Document which APIs work while an exception is pending. This is the
list of all APIs which do not start with `NAPI_PREAMBLE(env)`.

Fixes: nodejs/abi-stable-node#257
Backport-PR-URL: #19447
PR-URL: #19078
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: resolve promise in test
The last promise created by the test for the purposes of making sure
that its type is indeed a promise needs to be resolved so as to avoid
having it left in the pending state at the end of the test.

Backport-PR-URL: #19447
PR-URL: #19245
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api,test: add a new.target test to addons-napi
Added a N-API test to verify new.target behavior.

Backport-PR-URL: #19447
PR-URL: #19236
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: take n-api out of experimental
Take n-api out of experimental as per:
nodejs/TSC#501

Backport-PR-URL: #19447
PR-URL: #19262
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api,test: add int64 bounds tests
Added some simple tests to verify that the int64 API is correctly
handling numbers greater than 32-bits. This is a basic test, but
verifies that an implementer hasn't truncated back to 32-bits.

Refs: nodejs/node-chakracore#496

Backport-PR-URL: #19447
PR-URL: #19309
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: James M Snell <jasnell@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

doc: fix typos on n-api
Backport-PR-URL: #19447
PR-URL: #19385
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: add missing exception checking
Add checks for a pending exception in napi_make_callback
after the callback has been invoked.  If there is a pending
exception then we need to avoid checking the result as that
will not be able to complete properly.

Add additional checks to the unit test for napi_make_callback
to catch this case.

Backport-PR-URL: #19447
PR-URL: #19362
Fixes: nodejs/node-addon-api#235
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: add napi_fatal_exception
Add function to trigger and uncaught exception.
Useful if an async callback throws an exception with
no way to recover.

Backport-PR-URL: #19447
PR-URL: #19337
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: re-write test_make_callback
This re-writes the test in C by dropping std::vector<napi_value> in
favour of a C99 variable length array, and by dropping the anonymous
namespace in favour of static function declarations.

Backport-PR-URL: #19447
PR-URL: #19448
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

doc: Add a missing comma
Backport-PR-URL: #19447
PR-URL: #19555
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: bump version of n-api supported
Bump the version due to additions to the api.

Backport-PR-URL: #19447
PR-URL: #19497
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: ensure in-module exceptions are propagated
Whenever we call into an addon, whether it is for a callback, for
module init, or for async work-related reasons, we should make sure
that

* the last error is cleared,
* the scopes before the call are the same as after, and
* if an exception was thrown and captured inside the module, then it is
  re-thrown after the call.

Therefore we should call into the module in a unified fashion. This
change introduces the macro NAPI_CALL_INTO_MODULE() which should be
used whenever invoking a callback provided by the module.

Fixes: #19437
Backport-PR-URL: #19447
PR-URL: #19537
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: back up env before finalize
Heed the comment to not use fields of a Reference after calling its
finalize callback, because such a call may destroy the Reference.

Fixes: #19673
Backport-PR-URL: #19447
PR-URL: #19718
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

MylesBorins added a commit that referenced this pull request Apr 16, 2018

n-api: add more `int64_t` tests
* Updated tests for `Number` and `int32_t`
* Added new tests for `int64_t`
* Updated N-API `int64_t` behavior to return zero for all non-finite
  numbers
* Clarified the documentation for these calls.

Backport-PR-URL: #19447
PR-URL: #19402
Refs: nodejs/node-chakracore#500
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins

This comment has been minimized.

Copy link
Member

commented Apr 16, 2018

landed in e54b8e8...3aa5b7d

If anything is out of the ordinary we can find it in the release tests and open separate PRs to help fix.

Was able to automate applying the Backport-PR-URL meta data to all the commits using the following command

git filter-branch --msg-filter 'perl -pe "s/PR-URL/Backport-PR-URL: https:\/\/github.com\/nodejs\/node\/pull\/19447\nPR-URL/g"' upstream/v6.x-staging..v6.x-staging

@gabrielschulhof gabrielschulhof deleted the gabrielschulhof:v6.x-backport-n-api branch Apr 28, 2018

MylesBorins added a commit that referenced this pull request Apr 30, 2018

2018-04-30, Version 6.14.2 'Boron' (LTS)
Notable Change:

* n-api:
  - n-api has been backported to v6.x. It is being landed as an experimental interface,
    and as such is landing in a Semver-Patch release. (Gabriel Schulhof)
    #19447

PR-URL: Coming Soon

MylesBorins added a commit that referenced this pull request Apr 30, 2018

2018-04-30, Version 6.14.2 'Boron' (LTS)
Notable Change:

* n-api:
  - n-api has been backported to v6.x. It is being landed as an experimental interface,
    and as such is landing in a Semver-Patch release. (Gabriel Schulhof)
    #19447

PR-URL: #19996

MylesBorins added a commit that referenced this pull request Apr 30, 2018

2018-04-30, Version 6.14.2 'Boron' (LTS)
Notable Change:

* n-api:
  - n-api has been backported to v6.x. It is being landed as an experimental interface,
    and as such is landing in a Semver-Patch release. (Gabriel Schulhof)
    #19447

PR-URL: #19996
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.