n-api: refactoring a previous commit
This is a refactoring of PR-URL: https://github.com/nodejs/node/issues/27628 following PR-URL: https://github.com/nodejs/node/pull/28505
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines