-6.14.1
+6.14.2
+6.14.1 6.14.0 6.13.1 6.13.0
diff --git a/COLLABORATOR_GUIDE.md b/COLLABORATOR_GUIDE.md
index 7d8d70cdac38e0..11cf78f69b806f 100644
--- a/COLLABORATOR_GUIDE.md
+++ b/COLLABORATOR_GUIDE.md
@@ -593,20 +593,20 @@ Validate that the commit message is properly formatted using
$ git rev-list upstream/master...HEAD | xargs core-validate-commit
```
+Optional: When landing your own commits, force push the amended commit to the
+branch you used to open the pull request. If your branch is called `bugfix`,
+then the command would be `git push --force-with-lease origin master:bugfix`.
+When the pull request is closed, this will cause the pull request to
+show the purple merged status rather than the red closed status that is
+usually used for pull requests that weren't merged.
+
Time to push it:
```text
$ git push upstream master
```
-* Optional: Force push the amended commit to the branch you used to
-open the pull request. If your branch is called `bugfix`, then the
-command would be `git push --force-with-lease origin master:bugfix`.
-When the pull request is closed, this will cause the pull request to
-show the purple merged status rather than the red closed status that is
-usually used for pull requests that weren't merged. Only do this when
-landing your own contributions.
-* Close the pull request with a "Landed in ``" comment. If
+Close the pull request with a "Landed in ``" comment. If
your pull request shows the purple merged status then you should still
add the "Landed in .." comment if you added
multiple commits.
diff --git a/Makefile b/Makefile
index c947a2a4367d05..523a3d8c541ed8 100644
--- a/Makefile
+++ b/Makefile
@@ -120,9 +120,10 @@ v8:
test: all
$(MAKE) build-addons
+ $(MAKE) build-addons-napi
$(MAKE) cctest
$(PYTHON) tools/test.py --mode=release -J \
- doctool inspector known_issues message pseudo-tty parallel sequential addons
+ doctool inspector known_issues message pseudo-tty parallel sequential addons addons-napi
$(MAKE) lint
test-parallel: all
@@ -189,6 +190,41 @@ test/addons/.buildstamp: config.gypi \
# TODO(bnoordhuis) Force rebuild after gyp update.
build-addons: $(NODE_EXE) test/addons/.buildstamp
+ADDONS_NAPI_BINDING_GYPS := \
+ $(filter-out test/addons-napi/??_*/binding.gyp, \
+ $(wildcard test/addons-napi/*/binding.gyp))
+
+ADDONS_NAPI_BINDING_SOURCES := \
+ $(filter-out test/addons-napi/??_*/*.cc, $(wildcard test/addons-napi/*/*.cc)) \
+ $(filter-out test/addons-napi/??_*/*.h, $(wildcard test/addons-napi/*/*.h))
+
+# Implicitly depends on $(NODE_EXE), see the build-addons-napi rule for rationale.
+test/addons-napi/.buildstamp: config.gypi \
+ deps/npm/node_modules/node-gyp/package.json \
+ $(ADDONS_NAPI_BINDING_GYPS) $(ADDONS_NAPI_BINDING_SOURCES) \
+ deps/uv/include/*.h deps/v8/include/*.h \
+ src/node.h src/node_buffer.h src/node_object_wrap.h src/node_version.h \
+ src/node_api.h src/node_api_types.h
+# Cannot use $(wildcard test/addons-napi/*/) here, it's evaluated before
+# embedded addons have been generated from the documentation.
+ @for dirname in test/addons-napi/*/; do \
+ printf "\nBuilding addon $$PWD/$$dirname\n" ; \
+ env MAKEFLAGS="-j1" $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp \
+ --loglevel=$(LOGLEVEL) rebuild \
+ --python="$(PYTHON)" \
+ --directory="$$PWD/$$dirname" \
+ --nodedir="$$PWD" || exit 1 ; \
+ done
+ touch $@
+
+# .buildstamp and .docbuildstamp need $(NODE_EXE) but cannot depend on it
+# directly because it calls make recursively. The parent make cannot know
+# if the subprocess touched anything so it pessimistically assumes that
+# .buildstamp and .docbuildstamp are out of date and need a rebuild.
+# Just goes to show that recursive make really is harmful...
+# TODO(bnoordhuis) Force rebuild after gyp or node-gyp update.
+build-addons-napi: $(NODE_EXE) test/addons-napi/.buildstamp
+
clear-stalled:
# Clean up any leftover processes but don't error if found.
ps awwx | grep Release/node | grep -v grep | cat
@@ -200,7 +236,9 @@ clear-stalled:
test-gc: all test/gc/node_modules/weak/build/Release/weakref.node
$(PYTHON) tools/test.py --mode=release gc
-test-build: | all build-addons
+test-build: | all build-addons build-addons-napi
+
+test-build-addons-napi: all build-addons-napi
test-all: test-build test/gc/node_modules/weak/build/Release/weakref.node
$(PYTHON) tools/test.py --mode=debug,release
@@ -208,12 +246,12 @@ test-all: test-build test/gc/node_modules/weak/build/Release/weakref.node
test-all-valgrind: test-build
$(PYTHON) tools/test.py --mode=debug,release --valgrind
-CI_NATIVE_SUITES := addons
+CI_NATIVE_SUITES := addons addons-napi
CI_JS_SUITES := doctool inspector known_issues message parallel pseudo-tty sequential
# Build and test addons without building anything else
test-ci-native: LOGLEVEL := info
-test-ci-native: | test/addons/.buildstamp
+test-ci-native: | test/addons/.buildstamp test/addons-napi/.buildstamp
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
--mode=release --flaky-tests=$(FLAKY_TESTS) \
$(TEST_CI_ARGS) $(CI_NATIVE_SUITES)
@@ -231,11 +269,11 @@ test-ci-js: | clear-stalled
fi
test-ci: LOGLEVEL := info
-test-ci: | clear-stalled build-addons
+test-ci: | clear-stalled build-addons build-addons-napi
out/Release/cctest --gtest_output=tap:cctest.tap
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
--mode=release --flaky-tests=$(FLAKY_TESTS) \
- $(TEST_CI_ARGS) $(CI_JS_SUITES) $(CI_NATIVE_SUITES)
+ $(TEST_CI_ARGS) $(CI_JS_SUITES) addons-napi $(CI_NATIVE_SUITES)
# Clean up any leftover processes, error if found.
ps awwx | grep Release/node | grep -v grep | cat
@PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \
@@ -282,7 +320,10 @@ test-npm: $(NODE_EXE)
test-npm-publish: $(NODE_EXE)
npm_package_config_publishtest=true $(NODE) deps/npm/test/run.js
-test-addons: test-build
+test-addons-napi: test-build-addons-napi
+ $(PYTHON) tools/test.py --mode=release addons-napi
+
+test-addons: test-build test-addons-napi
$(PYTHON) tools/test.py --mode=release addons
test-addons-clean:
@@ -813,6 +854,8 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
test/addons/*/*.h \
test/cctest/*.cc \
test/cctest/*.h \
+ test/addons-napi/*/*.cc \
+ test/addons-napi/*/*.h \
tools/icu/*.cc \
tools/icu/*.h \
))
@@ -857,5 +900,6 @@ endif
bench-buffer bench-net bench-http bench-fs bench-tls cctest run-ci \
test-v8 test-v8-intl test-v8-benchmarks test-v8-all v8 lint-ci \
bench-ci lint-js-ci doc-only $(TARBALL)-headers test-ci test-ci-native \
- test-ci-js build-ci test-hash-seed clear-stalled
+ test-ci-js build-ci test-hash-seed clear-stalled test-addons-napi \
+ build-addons-napi
diff --git a/README.md b/README.md
index 55ad1756f15c1e..ab7c7967efc26e 100644
--- a/README.md
+++ b/README.md
@@ -7,10 +7,9 @@
-Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js
-uses an event-driven, non-blocking I/O model that makes it lightweight and
-efficient. The Node.js package ecosystem, [npm][], is the largest ecosystem of
-open source libraries in the world.
+Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. For
+more information on using Node.js, see the
+[Node.js Website][].
The Node.js project is supported by the
[Node.js Foundation](https://nodejs.org/en/foundation/). Contributions,
@@ -195,8 +194,8 @@ us a report nonetheless.
- [#14519](https://github.com/nodejs/node/issues/14519): _Internal domain
function can be used to cause segfaults_. Causing program termination using
- either the public Javascript APIs or the private bindings layer APIs requires
- the ability to execute arbitrary Javascript code, which is already the highest
+ either the public JavaScript APIs or the private bindings layer APIs requires
+ the ability to execute arbitrary JavaScript code, which is already the highest
level of privilege possible.
- [#12141](https://github.com/nodejs/node/pull/12141): _buffer: zero fill
@@ -248,8 +247,8 @@ For more information about the governance of the Node.js project, see
**Franziska Hinkelmann** <franziska.hinkelmann@gmail.com> (she/her)
* [Fishrock123](https://github.com/Fishrock123) -
**Jeremiah Senkpiel** <fishrock123@rocketmail.com>
-* [indutny](https://github.com/indutny) -
-**Fedor Indutny** <fedor.indutny@gmail.com>
+* [gibfahn](https://github.com/gibfahn) -
+**Gibson Fahnestock** <gibfahn@gmail.com> (he/him)
* [jasnell](https://github.com/jasnell) -
**James M Snell** <jasnell@gmail.com> (he/him)
* [joyeecheung](https://github.com/joyeecheung) -
@@ -258,8 +257,6 @@ For more information about the governance of the Node.js project, see
**Matteo Collina** <matteo.collina@gmail.com> (he/him)
* [mhdawson](https://github.com/mhdawson) -
**Michael Dawson** <michael_dawson@ca.ibm.com> (he/him)
-* [mscdex](https://github.com/mscdex) -
-**Brian White** <mscdex@mscdex.net>
* [MylesBorins](https://github.com/MylesBorins) -
**Myles Borins** <myles.borins@gmail.com> (he/him)
* [ofrobots](https://github.com/ofrobots) -
@@ -281,10 +278,14 @@ For more information about the governance of the Node.js project, see
**Ben Noordhuis** <info@bnoordhuis.nl>
* [chrisdickinson](https://github.com/chrisdickinson) -
**Chris Dickinson** <christopher.s.dickinson@gmail.com>
+* [indutny](https://github.com/indutny) -
+**Fedor Indutny** <fedor.indutny@gmail.com>
* [isaacs](https://github.com/isaacs) -
**Isaac Z. Schlueter** <i@izs.me>
* [joshgav](https://github.com/joshgav) -
**Josh Gavant** <josh.gavant@outlook.com>
+* [mscdex](https://github.com/mscdex) -
+**Brian White** <mscdex@mscdex.net>
* [nebrius](https://github.com/nebrius) -
**Bryan Hughes** <bryan@nebri.us>
* [orangemocha](https://github.com/orangemocha) -
@@ -342,6 +343,8 @@ For more information about the governance of the Node.js project, see
**Daniel Bevenius** <daniel.bevenius@gmail.com>
* [DavidCai1993](https://github.com/DavidCai1993) -
**David Cai** <davidcai1993@yahoo.com> (he/him)
+* [devsnek](https://github.com/devsnek) -
+**Gus Caplan** <me@gus.host> (he/him)
* [edsadr](https://github.com/edsadr) -
**Adrian Estrada** <edsadr@gmail.com> (he/him)
* [eljefedelrodeodeljefe](https://github.com/eljefedelrodeodeljefe) -
@@ -426,6 +429,8 @@ For more information about the governance of the Node.js project, see
**Mikeal Rogers** <mikeal.rogers@gmail.com>
* [misterdjules](https://github.com/misterdjules) -
**Julien Gilli** <jgilli@nodejs.org>
+* [mmarchini](https://github.com/mmarchini) -
+**Matheus Marchini** <matheus@sthima.com>
* [mscdex](https://github.com/mscdex) -
**Brian White** <mscdex@mscdex.net>
* [MylesBorins](https://github.com/MylesBorins) -
@@ -593,12 +598,13 @@ Previous releases may also have been signed with one of the following GPG keys:
* [Contributing to the project][]
* [Working Groups][]
+* [Strategic Initiatives][]
-[npm]: https://www.npmjs.com
[Code of Conduct]: https://github.com/nodejs/admin/blob/master/CODE_OF_CONDUCT.md
[Contributing to the project]: CONTRIBUTING.md
[Node.js Help]: https://github.com/nodejs/help
[Node.js Website]: https://nodejs.org/en/
[Questions tagged 'node.js' on StackOverflow]: https://stackoverflow.com/questions/tagged/node.js
[Working Groups]: https://github.com/nodejs/TSC/blob/master/WORKING_GROUPS.md
+[Strategic Initiatives]: https://github.com/nodejs/TSC/blob/master/Strategic-Initiatives.md
[#node.js channel on chat.freenode.net]: https://webchat.freenode.net?channels=node.js&uio=d4
diff --git a/configure b/configure
index e67a15c4753dd3..dd72cc332436a2 100755
--- a/configure
+++ b/configure
@@ -61,7 +61,7 @@ parser = optparse.OptionParser()
valid_os = ('win', 'mac', 'solaris', 'freebsd', 'openbsd', 'linux',
'android', 'aix')
valid_arch = ('arm', 'arm64', 'ia32', 'mips', 'mipsel', 'mips64el', 'ppc',
- 'ppc64', 'x32','x64', 'x86', 's390', 's390x')
+ 'ppc64', 'x32','x64', 'x86', 'x86_64', 's390', 's390x')
valid_arm_float_abi = ('soft', 'softfp', 'hard')
valid_arm_fpu = ('vfp', 'vfpv3', 'vfpv3-d16', 'neon')
valid_mips_arch = ('loongson', 'r1', 'r2', 'r6', 'rx')
@@ -825,6 +825,9 @@ def configure_node(o):
# the Makefile resets this to x86 afterward
if target_arch == 'x86':
target_arch = 'ia32'
+ # x86_64 is common across linuxes, allow it as an alias for x64
+ if target_arch == 'x86_64':
+ target_arch = 'x64'
o['variables']['host_arch'] = host_arch
o['variables']['target_arch'] = target_arch
o['variables']['node_byteorder'] = sys.byteorder
@@ -842,7 +845,6 @@ def configure_node(o):
configure_mips(o)
if flavor == 'aix':
- o['variables']['node_core_target_name'] = 'node_base'
o['variables']['node_target_type'] = 'static_library'
if target_arch in ('x86', 'x64', 'ia32', 'x32'):
@@ -942,6 +944,13 @@ def configure_node(o):
else:
o['variables']['coverage'] = 'false'
+ if options.shared:
+ o['variables']['node_target_type'] = 'shared_library'
+ elif options.enable_static:
+ o['variables']['node_target_type'] = 'static_library'
+ else:
+ o['variables']['node_target_type'] = 'executable'
+
def configure_library(lib, output):
shared_lib = 'shared_' + lib
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -1437,6 +1446,7 @@ config = {
'BUILDTYPE': 'Debug' if options.debug else 'Release',
'USE_XCODE': str(int(options.use_xcode or 0)),
'PYTHON': sys.executable,
+ 'NODE_TARGET_TYPE': variables['node_target_type'],
}
if options.prefix:
diff --git a/doc/api/_toc.md b/doc/api/_toc.md
index 5f7bca59e87d75..cdca642eeb9b93 100644
--- a/doc/api/_toc.md
+++ b/doc/api/_toc.md
@@ -7,7 +7,8 @@
* [Assertion Testing](assert.html)
* [Buffer](buffer.html)
-* [C/C++ Addons](addons.html)
+* [C++ Addons](addons.html)
+* [C/C++ Addons - N-API](n-api.html)
* [Child Processes](child_process.html)
* [Cluster](cluster.html)
* [Command Line Options](cli.html)
diff --git a/doc/api/addons.md b/doc/api/addons.md
index 17811245f1c23e..8f0853fb1db7df 100644
--- a/doc/api/addons.md
+++ b/doc/api/addons.md
@@ -1,8 +1,8 @@
-# C/C++ Addons
+# C++ Addons
-Node.js Addons are dynamically-linked shared objects, written in C or C++, that
+Node.js Addons are dynamically-linked shared objects, written in C++, that
can be loaded into Node.js using the [`require()`][require] function, and used
just as if they were an ordinary Node.js module. They are used primarily to
provide an interface between JavaScript running in Node.js and C/C++ libraries.
@@ -28,7 +28,7 @@ involving knowledge of several components and APIs :
off-loading work via libuv to non-blocking system operations, worker threads
or a custom use of libuv's threads.
- - Internal Node.js libraries. Node.js itself exports a number of C/C++ APIs
+ - Internal Node.js libraries. Node.js itself exports a number of C++ APIs
that Addons can use — the most important of which is the
`node::ObjectWrap` class.
@@ -101,7 +101,7 @@ Addon module name is `addon`.
Once the source code has been written, it must be compiled into the binary
`addon.node` file. To do so, create a file called `binding.gyp` in the
top-level of the project describing the build configuration of your module
-using a JSON-like format. This file is used by [node-gyp][] -- a tool written
+using a JSON-like format. This file is used by [node-gyp][] — a tool written
specifically to compile Node.js Addons.
```json
@@ -215,6 +215,26 @@ Addon developers are recommended to use to keep compatibility between past and
future releases of V8 and Node.js. See the `nan` [examples][] for an
illustration of how it can be used.
+
+## N-API
+
+> Stability: 1 - Experimental
+
+N-API is an API for building native Addons. It is independent from
+the underlying JavaScript runtime (ex V8) and is maintained as part of
+Node.js itself. This API will be Application Binary Interface (ABI) stable
+across version of Node.js. It is intended to insulate Addons from
+changes in the underlying JavaScript engine and allow modules
+compiled for one version to run on later versions of Node.js without
+recompilation. Addons are built/packaged with the same approach/tools
+outlined in this document (node-gyp, etc.). The only difference is the
+set of APIs that are used by the native code. Instead of using the V8
+or [Native Abstractions for Node.js][] APIs, the functions available
+in the N-API are used.
+
+The functions available and how to use them are documented in the
+section titled [C/C++ Addons - N-API](n-api.html).
+
## Addon examples
Following are some example Addons intended to help developers get started. The
diff --git a/doc/api/buffer.md b/doc/api/buffer.md
index 9583fa15949fd2..2668d43e8754f4 100644
--- a/doc/api/buffer.md
+++ b/doc/api/buffer.md
@@ -395,7 +395,7 @@ deprecated: v6.0.0
* `size` {integer} The desired length of the new `Buffer`.
-Allocates a new `Buffer` of `size` bytes. The `size` must be less than or equal
+Allocates a new `Buffer` of `size` bytes. The `size` must be less than or equal
to the value of [`buffer.kMaxLength`]. Otherwise, a [`RangeError`] is thrown.
A zero-length `Buffer` will be created if `size <= 0`.
diff --git a/doc/api/child_process.md b/doc/api/child_process.md
index b55bd0fea1d874..4759d9bd4a9337 100644
--- a/doc/api/child_process.md
+++ b/doc/api/child_process.md
@@ -38,7 +38,7 @@ the event loop until the spawned process either exits or is terminated.
For convenience, the `child_process` module provides a handful of synchronous
and asynchronous alternatives to [`child_process.spawn()`][] and
-[`child_process.spawnSync()`][]. *Note that each of these alternatives are
+[`child_process.spawnSync()`][]. *Note that each of these alternatives are
implemented on top of [`child_process.spawn()`][] or [`child_process.spawnSync()`][].*
* [`child_process.exec()`][]: spawns a shell and runs a command within that shell,
@@ -140,7 +140,8 @@ added: v0.1.90
command line parsing should be compatible with `cmd.exe`.
* `timeout` {number} **Default:** `0`
* [`maxBuffer`][] {number} Largest amount of data (in bytes) allowed on
- stdout or stderr - if exceeded child process is killed. **Default:** `200*1024`
+ stdout or stderr - if exceeded child process is killed.
+ **Default:** `200 * 1024`.
* `killSignal` {string|integer} **Default:** `'SIGTERM'`
* `uid` {number} Sets the user identity of the process (see setuid(2)).
* `gid` {number} Sets the group identity of the process (see setgid(2)).
@@ -170,7 +171,7 @@ exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
```
If a `callback` function is provided, it is called with the arguments
-`(error, stdout, stderr)`. On success, `error` will be `null`. On error,
+`(error, stdout, stderr)`. On success, `error` will be `null`. On error,
`error` will be an instance of [`Error`][]. The `error.code` property will be
the exit code of the child process while `error.signal` will be set to the
signal that terminated the process. Any exit code other than `0` is considered
@@ -218,7 +219,7 @@ added: v0.1.91
* `timeout` {number} **Default:** `0`
* [`maxBuffer`][] {number} Largest amount of data (in bytes) allowed on
stdout or stderr - if exceeded child process is killed.
- **Default:**: `200*1024`
+ **Default:** `200 * 1024`.
* `killSignal` {string|integer} **Default:** `'SIGTERM'`
* `uid` {number} Sets the user identity of the process (see setuid(2)).
* `gid` {number} Sets the group identity of the process (see setgid(2)).
@@ -446,7 +447,7 @@ disabled*.
On non-Windows platforms, if `options.detached` is set to `true`, the child
process will be made the leader of a new process group and session. Note that
child processes may continue running after the parent exits regardless of
-whether they are detached or not. See setsid(2) for more information.
+whether they are detached or not. See setsid(2) for more information.
By default, the parent will wait for the detached child to exit. To prevent
the parent from waiting for a given `subprocess`, use the `subprocess.unref()`
@@ -656,12 +657,12 @@ The `child_process.execSync()` method is generally identical to
[`child_process.exec()`][] with the exception that the method will not return until
the child process has fully closed. When a timeout has been encountered and
`killSignal` is sent, the method won't return until the process has completely
-exited. *Note that if the child process intercepts and handles the `SIGTERM`
+exited. *Note that if the child process intercepts and handles the `SIGTERM`
signal and doesn't exit, the parent process will wait until the child
process has exited.*
If the process times out, or has a non-zero exit code, this method ***will***
-throw. The [`Error`][] object will contain the entire result from
+throw. The [`Error`][] object will contain the entire result from
[`child_process.spawnSync()`][]
**Note: Never pass unsanitised user input to this function. Any input
@@ -997,7 +998,7 @@ properties:
Defaults to `false`.
The optional `callback` is a function that is invoked after the message is
-sent but before the child may have received it. The function is called with a
+sent but before the child may have received it. The function is called with a
single argument: `null` on success, or an [`Error`][] object on failure.
If no `callback` function is provided and the message cannot be sent, an
diff --git a/doc/api/cli.md b/doc/api/cli.md
index f1b33e883ae883..5a943b3428c6ca 100644
--- a/doc/api/cli.md
+++ b/doc/api/cli.md
@@ -342,7 +342,7 @@ added: v6.12.0
-->
`options...` are interpreted as if they had been specified on the command line
-before the actual command line (so they can be overriden). Node will exit with
+before the actual command line (so they can be overriden). Node will exit with
an error if an option that is not allowed in the environment is used, such as
`-p` or a script file.
@@ -353,7 +353,6 @@ Node options that are allowed are:
- `--debug-brk`
- `--debug-port`
- `--debug`
-- `--napi-modules`
- `--no-deprecation`
- `--no-warnings`
- `--openssl-config`
@@ -382,7 +381,7 @@ added: v3.0.0
Path to the file used to store the persistent REPL history. The default path is
`~/.node_repl_history`, which is overridden by this variable. Setting the value
-to an empty string (`""` or `" "`) disables persistent REPL history.
+to an empty string (`''` or `' '`) disables persistent REPL history.
### `NODE_TTY_UNSAFE_ASYNC=1`
diff --git a/doc/api/cluster.md b/doc/api/cluster.md
index 648c753931d936..fd5b8398bceb69 100644
--- a/doc/api/cluster.md
+++ b/doc/api/cluster.md
@@ -90,26 +90,26 @@ Node.js process and a cluster worker differs:
idea of what the number 7 file descriptor references.
2. `server.listen(handle)` Listening on handles explicitly will cause
the worker to use the supplied handle, rather than talk to the master
- process. If the worker already has the handle, then it's presumed
+ process. If the worker already has the handle, then it's presumed
that you know what you are doing.
3. `server.listen(0)` Normally, this will cause servers to listen on a
- random port. However, in a cluster, each worker will receive the
- same "random" port each time they do `listen(0)`. In essence, the
- port is random the first time, but predictable thereafter. If you
+ random port. However, in a cluster, each worker will receive the
+ same "random" port each time they do `listen(0)`. In essence, the
+ port is random the first time, but predictable thereafter. If you
want to listen on a unique port, generate a port number based on the
cluster worker ID.
There is no routing logic in Node.js, or in your program, and no shared
-state between the workers. Therefore, it is important to design your
+state between the workers. Therefore, it is important to design your
program such that it does not rely too heavily on in-memory data objects
for things like sessions and login.
Because workers are all separate processes, they can be killed or
re-spawned depending on your program's needs, without affecting other
-workers. As long as there are some workers still alive, the server will
-continue to accept connections. If no workers are alive, existing connections
-will be dropped and new connections will be refused. Node.js does not
-automatically manage the number of workers for you, however. It is your
+workers. As long as there are some workers still alive, the server will
+continue to accept connections. If no workers are alive, existing connections
+will be dropped and new connections will be refused. Node.js does not
+automatically manage the number of workers for you, however. It is your
responsibility to manage the worker pool for your application's needs.
Although a primary use case for the `cluster` module is networking, it can
@@ -265,7 +265,7 @@ It is not emitted in the worker.
added: v0.7.7
-->
-* Returns: {Worker} A reference to `worker`.
+* Returns: {cluster.Worker} A reference to `worker`.
In a worker, this function will close all servers, wait for the `'close'` event on
those servers, and then disconnect the IPC channel.
@@ -489,7 +489,7 @@ Emitted after the worker IPC channel has disconnected. This can occur when a
worker exits gracefully, is killed, or is disconnected manually (such as with
worker.disconnect()).
-There may be a delay between the `'disconnect'` and `'exit'` events. These events
+There may be a delay between the `'disconnect'` and `'exit'` events. These events
can be used to detect if the process is stuck in a cleanup or if there are
long-living connections.
@@ -582,7 +582,7 @@ The `addressType` is one of:
* `4` (TCPv4)
* `6` (TCPv6)
* `-1` (unix domain socket)
-* `"udp4"` or `"udp6"` (UDP v4 or v6)
+* `'udp4'` or `'udp6'` (UDP v4 or v6)
## Event: 'message'
@@ -709,7 +709,7 @@ distribute IOCP handles without incurring a large performance hit.
`cluster.schedulingPolicy` can also be set through the
`NODE_CLUSTER_SCHED_POLICY` environment variable. Valid
-values are `"rr"` and `"none"`.
+values are `'rr'` and `'none'`.
## cluster.settings
Returns the Diffie-Hellman generator in the specified `encoding`, which can
-be `'latin1'`, `'hex'`, or `'base64'`. If `encoding` is provided a string is
+be `'latin1'`, `'hex'`, or `'base64'`. If `encoding` is provided a string is
returned; otherwise a [`Buffer`][] is returned.
### diffieHellman.getPrime([encoding])
@@ -1172,8 +1172,8 @@ recent OpenSSL releases, `openssl list-cipher-algorithms` will display the
available cipher algorithms.
The `key` is the raw key used by the `algorithm` and `iv` is an
-[initialization vector][]. Both arguments must be `'utf8'` encoded strings or
-[buffers][`Buffer`].
+[initialization vector][]. Both arguments must be `'utf8'` encoded strings,
+[Buffers][`Buffer`], `TypedArray`, or `DataView`s.
### crypto.createDiffieHellman(prime[, prime_encoding][, generator][, generator_encoding])
Throughout the documentation, you will see indications of a section's
-stability. The Node.js API is still somewhat changing, and as it
-matures, certain parts are more reliable than others. Some are so
+stability. The Node.js API is still somewhat changing, and as it
+matures, certain parts are more reliable than others. Some are so
proven, and so relied upon, that they are unlikely to ever change at
-all. Others are brand new and experimental, or known to be hazardous
+all. Others are brand new and experimental, or known to be hazardous
and in the process of being redesigned.
The stability indices are as follows:
diff --git a/doc/api/domain.md b/doc/api/domain.md
index 08d6edc7d8cb24..99a44925034827 100644
--- a/doc/api/domain.md
+++ b/doc/api/domain.md
@@ -12,7 +12,7 @@ but should expect to have to migrate to a different solution
in the future.
Domains provide a way to handle multiple different IO operations as a
-single group. If any of the event emitters or callbacks registered to a
+single group. If any of the event emitters or callbacks registered to a
domain emit an `'error'` event, or throw an error, then the domain object
will be notified, rather than losing the context of the error in the
`process.on('uncaughtException')` handler, or causing the program to
@@ -30,7 +30,7 @@ never any way to safely "pick up where you left off", without leaking
references, or creating some other sort of undefined brittle state.
The safest way to respond to a thrown error is to shut down the
-process. Of course, in a normal web server, you might have many
+process. Of course, in a normal web server, you might have many
connections open, and it is not reasonable to abruptly shut those down
because an error was triggered by someone else.
@@ -40,7 +40,7 @@ time, and stop listening for new requests in that worker.
In this way, `domain` usage goes hand-in-hand with the cluster module,
since the master process can fork a new worker when a worker
-encounters an error. For Node.js programs that scale to multiple
+encounters an error. For Node.js programs that scale to multiple
machines, the terminating proxy or service registry can take note of
the failure, and react accordingly.
@@ -103,7 +103,7 @@ if (cluster.isMaster) {
const domain = require('domain');
// See the cluster documentation for more details about using
- // worker processes to serve requests. How it works, caveats, etc.
+ // worker processes to serve requests. How it works, caveats, etc.
const server = require('http').createServer((req, res) => {
const d = domain.create();
@@ -126,7 +126,7 @@ if (cluster.isMaster) {
// stop taking new requests.
server.close();
- // Let the master know we're dead. This will trigger a
+ // Let the master know we're dead. This will trigger a
// 'disconnect' in the cluster master, and then it will fork
// a new worker.
cluster.worker.disconnect();
@@ -155,7 +155,7 @@ if (cluster.isMaster) {
server.listen(PORT);
}
-// This part is not important. Just an example routing thing.
+// This part is not important. Just an example routing thing.
// You'd put your fancy application logic here.
function handleRequest(req, res) {
switch (req.url) {
@@ -197,11 +197,11 @@ the active domain at the time of their creation.
Additionally, callbacks passed to lowlevel event loop requests (such as
to fs.open, or other callback-taking methods) will automatically be
-bound to the active domain. If they throw, then the domain will catch
+bound to the active domain. If they throw, then the domain will catch
the error.
In order to prevent excessive memory usage, Domain objects themselves
-are not implicitly added as children of the active domain. If they
+are not implicitly added as children of the active domain. If they
were, then it would be too easy to prevent request and response objects
from being properly garbage collected.
@@ -218,7 +218,7 @@ Implicit binding only takes care of thrown errors and `'error'` events.
Sometimes, the domain in use is not the one that ought to be used for a
-specific event emitter. Or, the event emitter could have been created
+specific event emitter. Or, the event emitter could have been created
in the context of one domain, but ought to instead be bound to some
other domain.
@@ -268,7 +268,7 @@ Returns a new Domain object.
The Domain class encapsulates the functionality of routing errors and
uncaught exceptions to the active Domain object.
-Domain is a child class of [`EventEmitter`][]. To handle the errors that it
+Domain is a child class of [`EventEmitter`][]. To handle the errors that it
catches, listen to its `'error'` event.
### domain.run(fn[, ...args])
@@ -318,13 +318,13 @@ to the domain.
* `emitter` {EventEmitter|Timer} emitter or timer to be added to the domain
-Explicitly adds an emitter to the domain. If any event handlers called by
+Explicitly adds an emitter to the domain. If any event handlers called by
the emitter throw an error, or if the emitter emits an `'error'` event, it
will be routed to the domain's `'error'` event, just like with implicit
binding.
This also works with timers that are returned from [`setInterval()`][] and
-[`setTimeout()`][]. If their callback function throws, it will be caught by
+[`setTimeout()`][]. If their callback function throws, it will be caught by
the domain 'error' handler.
If the Timer or EventEmitter was already bound to a domain, it is removed
@@ -334,7 +334,7 @@ from that one, and bound to this one instead.
* `emitter` {EventEmitter|Timer} emitter or timer to be removed from the domain
-The opposite of [`domain.add(emitter)`][]. Removes domain handling from the
+The opposite of [`domain.add(emitter)`][]. Removes domain handling from the
specified emitter.
### domain.bind(callback)
@@ -343,7 +343,7 @@ specified emitter.
* Returns: {Function} The bound function
The returned function will be a wrapper around the supplied callback
-function. When the returned function is called, any errors that are
+function. When the returned function is called, any errors that are
thrown will be routed to the domain's `'error'` event.
#### Example
@@ -370,7 +370,7 @@ d.on('error', (er) => {
* `callback` {Function} The callback function
* Returns: {Function} The intercepted function
-This method is almost identical to [`domain.bind(callback)`][]. However, in
+This method is almost identical to [`domain.bind(callback)`][]. However, in
addition to catching thrown errors, it will also intercept [`Error`][]
objects sent as the first argument to the function.
@@ -439,7 +439,7 @@ without exiting the domain.
### domain.dispose()
-> Stability: 0 - Deprecated. Please recover from failed IO actions
+> Stability: 0 - Deprecated. Please recover from failed IO actions
> explicitly via error event handlers set on the domain.
Once `dispose` has been called, the domain will no longer be used by callbacks
diff --git a/doc/api/errors.md b/doc/api/errors.md
index 49b4bac595a6dc..306b58a908ee5d 100644
--- a/doc/api/errors.md
+++ b/doc/api/errors.md
@@ -107,7 +107,7 @@ pass or fail).
For *all* `EventEmitter` objects, if an `'error'` event handler is not
provided, the error will be thrown, causing the Node.js process to report an
-unhandled exception and crash unless either: The [`domain`][domains] module is used
+unhandled exception and crash unless either: The [`domain`][domains] module is used
appropriately or a handler has been registered for the
[`process.on('uncaughtException')`][] event.
@@ -133,7 +133,7 @@ exactly how errors raised by those methods are propagated.
Most asynchronous methods exposed by the Node.js core API follow an idiomatic
-pattern referred to as a "Node.js style callback". With this pattern, a
+pattern referred to as a "Node.js style callback". With this pattern, a
callback function is passed to the method as an argument. When the operation
either completes or an error is raised, the callback function is called with
the Error object (if any) passed as the first argument. If no error was raised,
@@ -155,7 +155,7 @@ fs.readFile('/some/file/that/does-exist', nodeStyleCallback);
```
The JavaScript `try / catch` mechanism **cannot** be used to intercept errors
-generated by asynchronous APIs. A common mistake for beginners is to try to
+generated by asynchronous APIs. A common mistake for beginners is to try to
use `throw` inside a Node.js style callback:
```js
@@ -204,7 +204,7 @@ provided text message. If an object is passed as `message`, the text message
is generated by calling `message.toString()`. The `error.stack` property will
represent the point in the code at which `new Error()` was called. Stack traces
are dependent on [V8's stack trace API][]. Stack traces extend only to either
-(a) the beginning of *synchronous code execution*, or (b) the number of frames
+(a) the beginning of *synchronous code execution*, or (b) the number of frames
given by the property `Error.stackTraceLimit`, whichever is smaller.
### Error.captureStackTrace(targetObject[, constructorOpt])
@@ -502,7 +502,7 @@ found [here][online].
- `EACCES` (Permission denied): An attempt was made to access a file in a way
forbidden by its file access permissions.
-- `EADDRINUSE` (Address already in use): An attempt to bind a server
+- `EADDRINUSE` (Address already in use): An attempt to bind a server
([`net`][], [`http`][], or [`https`][]) to a local address failed due to
another server on the local system already occupying that address.
@@ -530,14 +530,14 @@ found [here][online].
`ulimit -n 2048` in the same shell that will run the Node.js process.
- `ENOENT` (No such file or directory): Commonly raised by [`fs`][] operations
- to indicate that a component of the specified pathname does not exist -- no
+ to indicate that a component of the specified pathname does not exist — no
entity (file or directory) could be found by the given path.
- `ENOTDIR` (Not a directory): A component of the given pathname existed, but
was not a directory as expected. Commonly raised by [`fs.readdir`][].
- `ENOTEMPTY` (Directory not empty): A directory with entries was the target
- of an operation that requires an empty directory -- usually [`fs.unlink`][].
+ of an operation that requires an empty directory — usually [`fs.unlink`][].
- `EPERM` (Operation not permitted): An attempt was made to perform an
operation that requires elevated privileges.
@@ -549,7 +549,7 @@ found [here][online].
- `ETIMEDOUT` (Operation timed out): A connect or send request failed because
the connected party did not properly respond after a period of time. Usually
- encountered by [`http`][] or [`net`][] -- often a sign that a `socket.end()`
+ encountered by [`http`][] or [`net`][] — often a sign that a `socket.end()`
was not properly called.
[`fs.readdir`]: fs.html#fs_fs_readdir_path_options_callback
diff --git a/doc/api/fs.md b/doc/api/fs.md
index b47e639e3ca98f..74e3cc3c460c29 100644
--- a/doc/api/fs.md
+++ b/doc/api/fs.md
@@ -6,7 +6,7 @@
-File I/O is provided by simple wrappers around standard POSIX functions. To
+File I/O is provided by simple wrappers around standard POSIX functions. To
use this module do `require('fs')`. All the methods have asynchronous and
synchronous forms.
@@ -67,7 +67,7 @@ fs.rename('/tmp/hello', '/tmp/world', (err) => {
In busy processes, the programmer is _strongly encouraged_ to use the
asynchronous versions of these calls. The synchronous versions will block
-the entire process until they complete--halting all connections.
+the entire process until they complete — halting all connections.
The relative path to a filename can be used. Remember, however, that this path
will be relative to `process.cwd()`.
@@ -252,16 +252,16 @@ page.
The times in the stat object have the following semantics:
-* `atime` "Access Time" - Time when file data last accessed. Changed
+* `atime` "Access Time" - Time when file data last accessed. Changed
by the mknod(2), utimes(2), and read(2) system calls.
* `mtime` "Modified Time" - Time when file data last modified.
Changed by the mknod(2), utimes(2), and write(2) system calls.
* `ctime` "Change Time" - Time when file status was last changed
- (inode data modification). Changed by the chmod(2), chown(2),
+ (inode data modification). Changed by the chmod(2), chown(2),
link(2), mknod(2), rename(2), unlink(2), utimes(2),
read(2), and write(2) system calls.
-* `birthtime` "Birth Time" - Time of file creation. Set once when the
- file is created. On filesystems where birthtime is not available,
+* `birthtime` "Birth Time" - Time of file creation. Set once when the
+ file is created. On filesystems where birthtime is not available,
this field may instead hold either the `ctime` or
`1970-01-01T00:00Z` (ie, unix epoch timestamp `0`). Note that this
value may be greater than `atime` or `mtime` in this case. On Darwin
@@ -270,7 +270,7 @@ The times in the stat object have the following semantics:
utimes(2) system call.
Prior to Node v0.12, the `ctime` held the `birthtime` on Windows
-systems. Note that as of v0.12, `ctime` is not "creation time", and
+systems. Note that as of v0.12, `ctime` is not "creation time", and
on Unix systems, it never was.
## Class: fs.WriteStream
@@ -567,7 +567,7 @@ added: v0.0.2
* `callback` {Function}
* `err` {Error}
-Asynchronous close(2). No arguments other than a possible exception are given
+Asynchronous close(2). No arguments other than a possible exception are given
to the completion callback.
## fs.closeSync(fd)
@@ -621,7 +621,7 @@ const defaults = {
```
`options` can include `start` and `end` values to read a range of bytes from
-the file instead of the entire file. Both `start` and `end` are inclusive and
+the file instead of the entire file. Both `start` and `end` are inclusive and
start counting at 0. If `fd` is specified and `start` is omitted or `undefined`,
`fs.createReadStream()` reads sequentially from the current file position.
The `encoding` can be any one of those accepted by [`Buffer`][].
@@ -632,8 +632,8 @@ emitted. Note that `fd` should be blocking; non-blocking `fd`s should be passed
to [`net.Socket`][].
If `autoClose` is false, then the file descriptor won't be closed, even if
-there's an error. It is your responsibility to close it and make sure
-there's no file descriptor leak. If `autoClose` is set to true (default
+there's an error. It is your responsibility to close it and make sure
+there's no file descriptor leak. If `autoClose` is set to true (default
behavior), on `error` or `end` the file descriptor will be closed
automatically.
@@ -677,7 +677,7 @@ const defaults = {
```
`options` may also include a `start` option to allow writing data at
-some position past the beginning of the file. Modifying a file rather
+some position past the beginning of the file. Modifying a file rather
than replacing it may require a `flags` mode of `r+` rather than the
default mode `w`. The `defaultEncoding` can be any one of those accepted by
[`Buffer`][].
@@ -708,7 +708,7 @@ deprecated: v1.0.0
* `exists` {Boolean}
Test whether or not the given path exists by checking with the file system.
-Then call the `callback` argument with either true or false. Example:
+Then call the `callback` argument with either true or false. Example:
```js
fs.exists('/etc/passwd', (exists) => {
@@ -1286,7 +1286,7 @@ to a non-existent file. The exclusive flag may or may not work with network file
systems.
`flags` can also be a number as documented by open(2); commonly used constants
-are available from `fs.constants`. On Windows, flags are translated to
+are available from `fs.constants`. On Windows, flags are translated to
their equivalent ones where applicable, e.g. `O_WRONLY` to `FILE_GENERIC_WRITE`,
or `O_EXCL|O_CREAT` to `CREATE_NEW`, as accepted by CreateFileW.
@@ -1373,7 +1373,7 @@ added: v0.1.8
* `err` {Error}
* `files` {string[]|Buffer[]}
-Asynchronous readdir(3). Reads the contents of a directory.
+Asynchronous readdir(3). Reads the contents of a directory.
The callback gets two arguments `(err, files)` where `files` is an array of
the names of the files in the directory excluding `'.'` and `'..'`.
@@ -1809,12 +1809,12 @@ added: v0.5.10
* `filename` {string|Buffer}
Watch for changes on `filename`, where `filename` is either a file or a
-directory. The returned object is a [`fs.FSWatcher`][].
+directory. The returned object is a [`fs.FSWatcher`][].
The second argument is optional. If `options` is provided as a string, it
specifies the `encoding`. Otherwise `options` should be passed as an object.
-The listener callback gets two arguments `(eventType, filename)`. `eventType` is either
+The listener callback gets two arguments `(eventType, filename)`. `eventType` is either
`'rename'` or `'change'`, and `filename` is the name of the file which triggered
the event.
@@ -1879,7 +1879,7 @@ this improves the usability of file watching. This is expected behavior.
Providing `filename` argument in the callback is only supported on Linux and
-Windows. Even on supported platforms, `filename` is not always guaranteed to
+Windows. Even on supported platforms, `filename` is not always guaranteed to
be provided. Therefore, don't assume that `filename` argument is always
provided in the callback, and have some fallback logic if it is null.
@@ -2000,7 +2000,7 @@ added: v0.11.5
* `written` {integer}
* `string` {string}
-Write `string` to the file specified by `fd`. If `string` is not a string, then
+Write `string` to the file specified by `fd`. If `string` is not a string, then
the value will be coerced to one.
`position` refers to the offset from the beginning of the file where this data
diff --git a/doc/api/globals.md b/doc/api/globals.md
index 054bc2300bd411..79b11d0bde6c0e 100644
--- a/doc/api/globals.md
+++ b/doc/api/globals.md
@@ -188,7 +188,7 @@ added: v0.1.13
* {Function}
-To require modules. See the [Modules][] section. `require` is not actually a
+To require modules. See the [Modules][] section. `require` is not actually a
global but rather local to each module.
### require.cache
@@ -221,14 +221,14 @@ Process files with the extension `.sjs` as `.js`:
require.extensions['.sjs'] = require.extensions['.js'];
```
-**Deprecated** In the past, this list has been used to load
+**Deprecated** In the past, this list has been used to load
non-JavaScript modules into Node.js by compiling them on-demand.
However, in practice, there are much better ways to do this, such as
loading modules via some other Node.js program, or compiling them to
JavaScript ahead of time.
Since the Module system is locked, this feature will probably never go
-away. However, it may have subtle bugs and complexities that are best
+away. However, it may have subtle bugs and complexities that are best
left untouched.
### require.resolve()
diff --git a/doc/api/http.md b/doc/api/http.md
index 9860f0949d3987..00b0bb5b3b8c88 100644
--- a/doc/api/http.md
+++ b/doc/api/http.md
@@ -9,7 +9,7 @@ To use the HTTP server and client one must `require('http')`.
The HTTP interfaces in Node.js are designed to support many features
of the protocol which have been traditionally difficult to use.
In particular, large, possibly chunk-encoded, messages. The interface is
-careful to never buffer entire requests or responses--the
+careful to never buffer entire requests or responses — the
user is able to stream data.
HTTP message headers are represented by an object like this:
@@ -33,7 +33,7 @@ parse the actual headers or the body.
See [`message.headers`][] for details on how duplicate headers are handled.
The raw headers as they were received are retained in the `rawHeaders`
-property, which is an array of `[key, value, key2, value2, ...]`. For
+property, which is an array of `[key, value, key2, value2, ...]`. For
example, the previous message header object might have a `rawHeaders`
list like the following:
@@ -122,9 +122,9 @@ added: v0.3.4
for TCP Keep-Alive packets. Ignored when the
`keepAlive` option is `false` or `undefined`. Default = `1000`.
* `maxSockets` {number} Maximum number of sockets to allow per
- host. Default = `Infinity`.
+ host. Default = `Infinity`.
* `maxFreeSockets` {number} Maximum number of sockets to leave open
- in a free state. Only relevant if `keepAlive` is set to `true`.
+ in a free state. Only relevant if `keepAlive` is set to `true`.
Default = `256`.
The default [`http.globalAgent`][] that is used by [`http.request()`][] has all
@@ -202,9 +202,9 @@ added: v0.11.4
Destroy any sockets that are currently in use by the agent.
-It is usually not necessary to do this. However, if you are using an
+It is usually not necessary to do this. However, if you are using an
agent with `keepAlive` enabled, then it is best to explicitly shut down
-the agent when you know that it will no longer be used. Otherwise,
+the agent when you know that it will no longer be used. Otherwise,
sockets may hang open for quite a long time before the server
terminates them.
@@ -216,7 +216,7 @@ added: v0.11.4
* {Object}
An object which contains arrays of sockets currently awaiting use by
-the agent when `keepAlive` is enabled. Do not modify.
+the agent when `keepAlive` is enabled. Do not modify.
### agent.getName(options)
-This object is created internally and returned from [`http.request()`][]. It
-represents an _in-progress_ request whose header has already been queued. The
+This object is created internally and returned from [`http.request()`][]. It
+represents an _in-progress_ request whose header has already been queued. The
header is still mutable using the `setHeader(name, value)`, `getHeader(name)`,
-`removeHeader(name)` API. The actual header will be sent along with the first
+`removeHeader(name)` API. The actual header will be sent along with the first
data chunk or when closing the connection.
To get the response, add a listener for [`'response'`][] to the request object.
[`'response'`][] will be emitted from the request object when the response
-headers have been received. The [`'response'`][] event is executed with one
+headers have been received. The [`'response'`][] event is executed with one
argument which is an instance of [`http.IncomingMessage`][].
During the [`'response'`][] event, one can add listeners to the
response object; particularly to listen for the `'data'` event.
If no [`'response'`][] handler is added, then the response will be
-entirely discarded. However, if you add a [`'response'`][] event handler,
+entirely discarded. However, if you add a [`'response'`][] event handler,
then you **must** consume the data from the response object, either by
calling `response.read()` whenever there is a `'readable'` event, or
by adding a `'data'` handler, or by calling the `.resume()` method.
-Until the data is consumed, the `'end'` event will not fire. Also, until
+Until the data is consumed, the `'end'` event will not fire. Also, until
the data is read it will consume memory that can eventually lead to a
'process out of memory' error.
@@ -517,11 +517,11 @@ added: v1.6.0
Flush the request headers.
For efficiency reasons, Node.js normally buffers the request headers until you
-call `request.end()` or write the first chunk of request data. It then tries
+call `request.end()` or write the first chunk of request data. It then tries
hard to pack the request headers and data into a single TCP packet.
That's usually what you want (it saves a TCP round-trip) but not when the first
-data is not sent until possibly much later. `request.flushHeaders()` lets you bypass
+data is not sent until possibly much later. `request.flushHeaders()` lets you bypass
the optimization and kickstart the request.
### request.setNoDelay([noDelay])
@@ -567,9 +567,9 @@ added: v0.1.29
* `encoding` {string}
* `callback` {Function}
-Sends a chunk of the body. By calling this method
+Sends a chunk of the body. By calling this method
many times, the user can stream a request body to a
-server--in that case it is suggested to use the
+server — in that case it is suggested to use the
`['Transfer-Encoding', 'chunked']` header line when
creating the request.
@@ -579,7 +579,9 @@ Defaults to `'utf8'`.
The `callback` argument is optional and will be called when this chunk of data
is flushed.
-Returns `request`.
+Returns `true` if the entire data was flushed successfully to the kernel
+buffer. Returns `false` if all or part of the data was queued in user memory.
+`'drain'` will be emitted when the buffer is free again.
## Class: http.Server
-This object is created internally by an HTTP server--not by the user. It is
+This object is created internally by an HTTP server — not by the user. It is
passed as the second parameter to the [`'request'`][] event.
The response implements, but does not inherit from, the [Writable Stream][]
@@ -1013,8 +1015,8 @@ added: v0.4.0
* `name` {string}
* `value` {string}
-Sets a single header value for implicit headers. If this header already exists
-in the to-be-sent headers, its value will be replaced. Use an array of strings
+Sets a single header value for implicit headers. If this header already exists
+in the to-be-sent headers, its value will be replaced. Use an array of strings
here if you need to send multiple headers with the same name.
Example:
@@ -1054,12 +1056,12 @@ added: v0.9.12
* `msecs` {number}
* `callback` {Function}
-Sets the Socket's timeout value to `msecs`. If a callback is
+Sets the Socket's timeout value to `msecs`. If a callback is
provided, then it is added as a listener on the `'timeout'` event on
the response object.
If no `'timeout'` listener is added to the request, the response, or
-the server, then sockets are destroyed when they time out. If you
+the server, then sockets are destroyed when they time out. If you
assign a handler on the request, the response, or the server's
`'timeout'` events, then it is your responsibility to handle timed out
sockets.
@@ -1311,8 +1313,8 @@ added: v0.11.6
The raw request/response headers list exactly as they were received.
-Note that the keys and values are in the same list. It is *not* a
-list of tuples. So, the even-numbered offsets are key values, and the
+Note that the keys and values are in the same list. It is *not* a
+list of tuples. So, the even-numbered offsets are key values, and the
odd-numbered offsets are the associated values.
Header names are not lowercased, and duplicates are not merged.
@@ -1339,7 +1341,7 @@ added: v0.11.6
* {Array}
The raw request/response trailer keys and values exactly as they were
-received. Only populated at the `'end'` event.
+received. Only populated at the `'end'` event.
### message.setTimeout(msecs, callback)
-An Agent object for HTTPS similar to [`http.Agent`][]. See [`https.request()`][]
+An Agent object for HTTPS similar to [`http.Agent`][]. See [`https.request()`][]
for more information.
## Class: https.Server
diff --git a/doc/api/modules.md b/doc/api/modules.md
index e87b209395fb1a..59c675f17c813e 100644
--- a/doc/api/modules.md
+++ b/doc/api/modules.md
@@ -28,7 +28,7 @@ exports.circumference = (r) => 2 * PI * r;
```
The module `circle.js` has exported the functions `area()` and
-`circumference()`. To add functions and objects to the root of your module,
+`circumference()`. To add functions and objects to the root of your module,
you can add them to the special `exports` object.
Variables local to the module will be private, because the module is wrapped
@@ -92,7 +92,7 @@ Let's say that we wanted to have the folder at
specific version of a package.
Packages can depend on one another. In order to install package `foo`, you
-may have to install a specific version of package `bar`. The `bar` package
+may have to install a specific version of package `bar`. The `bar` package
may itself have dependencies, and in some cases, these dependencies may even
collide or form cycles.
@@ -121,12 +121,12 @@ the version that is symlinked into
Furthermore, to make the module lookup process even more optimal, rather
than putting packages directly in `/usr/lib/node`, we could put them in
-`/usr/lib/node_modules//`. Then Node.js will not bother
+`/usr/lib/node_modules//`. Then Node.js will not bother
looking for missing dependencies in `/usr/node_modules` or `/node_modules`.
In order to make modules available to the Node.js REPL, it might be useful to
also add the `/usr/lib/node_modules` folder to the `$NODE_PATH` environment
-variable. Since the module lookups using `node_modules` folders are all
+variable. Since the module lookups using `node_modules` folders are all
relative, and based on the real path of the files making the calls to
`require()`, the packages themselves can be anywhere.
@@ -194,12 +194,12 @@ NODE_MODULES_PATHS(START)
-Modules are cached after the first time they are loaded. This means
+Modules are cached after the first time they are loaded. This means
(among other things) that every call to `require('foo')` will get
exactly the same object returned, if it would resolve to the same file.
Multiple calls to `require('foo')` may not cause the module code to be
-executed multiple times. This is an important feature. With it,
+executed multiple times. This is an important feature. With it,
"partially done" objects can be returned, thus allowing transitive
dependencies to be loaded even when they would cause cycles.
@@ -210,7 +210,7 @@ function, and call that function.
-Modules are cached based on their resolved filename. Since modules may
+Modules are cached based on their resolved filename. Since modules may
resolve to a different filename based on the location of the calling
module (loading from `node_modules` folders), it is not a *guarantee*
that `require('foo')` will always return the exact same object, if it
@@ -226,14 +226,14 @@ irrespective of whether or not `./foo` and `./FOO` are the same file.
-Node.js has several modules compiled into the binary. These modules are
+Node.js has several modules compiled into the binary. These modules are
described in greater detail elsewhere in this documentation.
The core modules are defined within Node.js's source and are located in the
`lib/` folder.
Core modules are always preferentially loaded if their identifier is
-passed to `require()`. For instance, `require('http')` will always
+passed to `require()`. For instance, `require('http')` will always
return the built in HTTP module, even if there is a file by that name.
## Cycles
@@ -273,13 +273,13 @@ console.log('b done');
console.log('main starting');
const a = require('./a.js');
const b = require('./b.js');
-console.log('in main, a.done=%j, b.done=%j', a.done, b.done);
+console.log('in main, a.done = %j, b.done = %j', a.done, b.done);
```
-When `main.js` loads `a.js`, then `a.js` in turn loads `b.js`. At that
-point, `b.js` tries to load `a.js`. In order to prevent an infinite
+When `main.js` loads `a.js`, then `a.js` in turn loads `b.js`. At that
+point, `b.js` tries to load `a.js`. In order to prevent an infinite
loop, an **unfinished copy** of the `a.js` exports object is returned to the
-`b.js` module. `b.js` then finishes loading, and its `exports` object is
+`b.js` module. `b.js` then finishes loading, and its `exports` object is
provided to the `a.js` module.
By the time `main.js` has loaded both modules, they're both finished.
@@ -294,7 +294,7 @@ in b, a.done = false
b done
in a, b.done = true
a done
-in main, a.done=true, b.done=true
+in main, a.done = true, b.done = true
```
If you have cyclic module dependencies in your program, make sure to
@@ -312,7 +312,7 @@ required filename with the added extensions: `.js`, `.json`, and finally
parsed as JSON text files. `.node` files are interpreted as compiled addon
modules loaded with `dlopen`.
-A required module prefixed with `'/'` is an absolute path to the file. For
+A required module prefixed with `'/'` is an absolute path to the file. For
example, `require('/home/marco/foo.js')` will load the file at
`/home/marco/foo.js`.
@@ -336,7 +336,7 @@ There are three ways in which a folder may be passed to `require()` as
an argument.
The first is to create a `package.json` file in the root of the folder,
-which specifies a `main` module. An example package.json file might
+which specifies a `main` module. An example package.json file might
look like this:
```json
@@ -350,7 +350,7 @@ If this was in a folder at `./some-library`, then
This is the extent of Node.js's awareness of package.json files.
-Note: If the file specified by the `"main"` entry of `package.json` is missing
+Note: If the file specified by the `'main'` entry of `package.json` is missing
and can not be resolved, Node.js will report the entire module as missing with
the default error:
@@ -360,7 +360,7 @@ Error: Cannot find module 'some-library'
If there is no package.json file present in the directory, then Node.js
will attempt to load an `index.js` or `index.node` file out of that
-directory. For example, if there was no package.json file in the above
+directory. For example, if there was no package.json file in the above
example, then `require('./some-library')` would attempt to load:
* `./some-library/index.js`
@@ -403,7 +403,7 @@ same module resolution semantics.
If the `NODE_PATH` environment variable is set to a colon-delimited list
of absolute paths, then Node.js will search those paths for modules if they
-are not found elsewhere. (Note: On Windows, `NODE_PATH` is delimited by
+are not found elsewhere. (Note: On Windows, `NODE_PATH` is delimited by
semicolons instead of colons.)
`NODE_PATH` was originally created to support loading modules from
@@ -412,7 +412,7 @@ varying paths before the current [module resolution][] algorithm was frozen.
`NODE_PATH` is still supported, but is less necessary now that the Node.js
ecosystem has settled on a convention for locating dependent modules.
Sometimes deployments that rely on `NODE_PATH` show surprising behavior
-when people are unaware that `NODE_PATH` must be set. Sometimes a
+when people are unaware that `NODE_PATH` must be set. Sometimes a
module's dependencies change, causing a different version (or even a
different module) to be loaded as the `NODE_PATH` is searched.
@@ -425,8 +425,8 @@ Additionally, Node.js will search in the following locations:
Where `$HOME` is the user's home directory, and `$PREFIX` is Node.js's
configured `node_prefix`.
-These are mostly for historic reasons. **You are highly encouraged
-to place your dependencies locally in `node_modules` folders.** They
+These are mostly for historic reasons. **You are highly encouraged
+to place your dependencies locally in `node_modules` folders.** They
will be loaded faster, and more reliably.
## The module wrapper
@@ -464,7 +464,7 @@ added: v0.1.16
* {Object}
In each module, the `module` free variable is a reference to the object
-representing the current module. For convenience, `module.exports` is
+representing the current module. For convenience, `module.exports` is
also accessible via the `exports` module-global. `module` is not actually
a global but rather local to each module.
@@ -515,7 +515,7 @@ a.on('ready', () => {
Note that assignment to `module.exports` must be done immediately. It cannot be
-done in any callbacks. This does not work:
+done in any callbacks. This does not work:
x.js:
@@ -595,7 +595,7 @@ added: v0.1.16
* {string}
-The identifier for the module. Typically this is the fully resolved
+The identifier for the module. Typically this is the fully resolved
filename.
### module.loaded
@@ -629,7 +629,7 @@ The `module.require` method provides a way to load a module as if
`require()` was called from the original module.
Note that in order to do this, you must get a reference to the `module`
-object. Since `require()` returns the `module.exports`, and the `module` is
+object. Since `require()` returns the `module.exports`, and the `module` is
typically *only* available within a specific module's code, it must be
explicitly exported in order to be used.
@@ -642,7 +642,7 @@ added: v0.3.7
* {Object}
Provides general utility methods when interacting with instances of
-`Module` -- the `module` variable often seen in file modules. Accessed
+`Module` — the `module` variable often seen in file modules. Accessed
via `require('module')`.
### module.builtinModules
@@ -652,7 +652,7 @@ added: v6.13.0
* {string[]}
-A list of the names of all modules provided by Node.js. Can be used to verify
+A list of the names of all modules provided by Node.js. Can be used to verify
if a module is maintained by a third-party module or not.
[`__dirname`]: #modules_dirname
diff --git a/doc/api/n-api.md b/doc/api/n-api.md
new file mode 100644
index 00000000000000..8910b923d8be34
--- /dev/null
+++ b/doc/api/n-api.md
@@ -0,0 +1,3850 @@
+# N-API
+
+> Stability: 1 - Experimental
+
+N-API (pronounced N as in the letter, followed by API)
+is an API for building native Addons. It is independent from
+the underlying JavaScript runtime (ex V8) and is maintained as part of
+Node.js itself. This API will be Application Binary Interface (ABI) stable
+across versions of Node.js. It is intended to insulate Addons from
+changes in the underlying JavaScript engine and allow modules
+compiled for one version to run on later versions of Node.js without
+recompilation.
+
+Addons are built/packaged with the same approach/tools
+outlined in the section titled [C++ Addons](addons.html).
+The only difference is the set of APIs that are used by the native code.
+Instead of using the V8 or [Native Abstractions for Node.js][] APIs,
+the functions available in the N-API are used.
+
+APIs exposed by N-API are generally used to create and manipulate
+JavaScript values. Concepts and operations generally map to ideas specified
+in the ECMA262 Language Specification. The APIs have the following
+properties:
+- All N-API calls return a status code of type `napi_status`. This
+ status indicates whether the API call succeeded or failed.
+- The API's return value is passed via an out parameter.
+- All JavaScript values are abstracted behind an opaque type named
+ `napi_value`.
+- In case of an error status code, additional information can be obtained
+ using `napi_get_last_error_info`. More information can be found in the error
+ handling section [Error Handling][].
+
+The documentation for N-API is structured as follows:
+
+* [Basic N-API Data Types][]
+* [Error Handling][]
+* [Object Lifetime Management][]
+* [Module Registration][]
+* [Working with JavaScript Values][]
+* [Working with JavaScript Values - Abstract Operations][]
+* [Working with JavaScript Properties][]
+* [Working with JavaScript Functions][]
+* [Object Wrap][]
+* [Simple Asynchronous Operations][]
+* [Custom Asynchronous Operations][]
+* [Promises][]
+* [Script Execution][]
+
+The N-API is a C API that ensures ABI stability across Node.js versions
+and different compiler levels. However, we also understand that a C++
+API can be easier to use in many cases. To support these cases we expect
+there to be one or more C++ wrapper modules that provide an inlineable C++
+API. Binaries built with these wrapper modules will depend on the symbols
+for the N-API C based functions exported by Node.js. These wrappers are not
+part of N-API, nor will they be maintained as part of Node.js. One such
+example is: [node-api](https://github.com/nodejs/node-api).
+
+In order to use the N-API functions, include the file
+[node_api.h](https://github.com/nodejs/node/blob/master/src/node_api.h)
+which is located in the src directory in the node development tree.
+For example:
+```C
+#include
+```
+
+## Basic N-API Data Types
+
+N-API exposes the following fundamental datatypes as abstractions that are
+consumed by the various APIs. These APIs should be treated as opaque,
+introspectable only with other N-API calls.
+
+### napi_status
+Integral status code indicating the success or failure of a N-API call.
+Currently, the following status codes are supported.
+```C
+typedef enum {
+ napi_ok,
+ napi_invalid_arg,
+ napi_object_expected,
+ napi_string_expected,
+ napi_name_expected,
+ napi_function_expected,
+ napi_number_expected,
+ napi_boolean_expected,
+ napi_array_expected,
+ napi_generic_failure,
+ napi_pending_exception,
+ napi_cancelled,
+ napi_status_last
+} napi_status;
+```
+If additional information is required upon an API returning a failed status,
+it can be obtained by calling `napi_get_last_error_info`.
+
+### napi_extended_error_info
+```C
+typedef struct {
+ const char* error_message;
+ void* engine_reserved;
+ uint32_t engine_error_code;
+ napi_status error_code;
+} napi_extended_error_info;
+```
+
+- `error_message`: UTF8-encoded string containing a VM-neutral description of
+ the error.
+- `engine_reserved`: Reserved for VM-specific error details. This is currently
+ not implemented for any VM.
+- `engine_error_code`: VM-specific error code. This is currently
+ not implemented for any VM.
+- `error_code`: The N-API status code that originated with the last error.
+
+See the [Error Handling][] section for additional information.
+
+### napi_env
+`napi_env` is used to represent a context that the underlying N-API
+implementation can use to persist VM-specific state. This structure is passed
+to native functions when they're invoked, and it must be passed back when
+making N-API calls. Specifically, the same `napi_env` that was passed in when
+the initial native function was called must be passed to any subsequent
+nested N-API calls. Caching the `napi_env` for the purpose of general reuse is
+not allowed.
+
+### napi_value
+This is an opaque pointer that is used to represent a JavaScript value.
+
+### N-API Memory Management types
+#### napi_handle_scope
+This is an abstraction used to control and modify the lifetime of objects
+created within a particular scope. In general, N-API values are created within
+the context of a handle scope. When a native method is called from
+JavaScript, a default handle scope will exist. If the user does not explicitly
+create a new handle scope, N-API values will be created in the default handle
+scope. For any invocations of code outside the execution of a native method
+(for instance, during a libuv callback invocation), the module is required to
+create a scope before invoking any functions that can result in the creation
+of JavaScript values.
+
+Handle scopes are created using [`napi_open_handle_scope`][] and are destroyed
+using [`napi_close_handle_scope`][]. Closing the scope can indicate to the GC that
+all `napi_value`s created during the lifetime of the handle scope are no longer
+referenced from the current stack frame.
+
+For more details, review the [Object Lifetime Management][].
+
+#### napi_escapable_handle_scope
+Escapable handle scopes are a special type of handle scope to return values
+created within a particular handle scope to a parent scope.
+
+#### napi_ref
+This is the abstraction to use to reference a `napi_value`. This allows for
+users to manage the lifetimes of JavaScript values, including defining their
+minimum lifetimes explicitly.
+
+For more details, review the [Object Lifetime Management][].
+
+### N-API Callback types
+#### napi_callback_info
+Opaque datatype that is passed to a callback function. It can be used for
+getting additional information about the context in which the callback was
+invoked.
+
+#### napi_callback
+Function pointer type for user-provided native functions which are to be
+exposed to JavaScript via N-API. Callback functions should satisfy the
+following signature:
+```C
+typedef napi_value (*napi_callback)(napi_env, napi_callback_info);
+```
+
+#### napi_finalize
+Function pointer type for add-on provided functions that allow the user to be
+notified when externally-owned data is ready to be cleaned up because the
+object with which it was associated with, has been garbage-collected. The user
+must provide a function satisfying the following signature which would get
+called upon the object's collection. Currently, `napi_finalize` can be used for
+finding out when objects that have external data are collected.
+
+```C
+typedef void (*napi_finalize)(napi_env env,
+ void* finalize_data,
+ void* finalize_hint);
+```
+
+
+#### napi_async_execute_callback
+Function pointer used with functions that support asynchronous
+operations. Callback functions must statisfy the following signature:
+
+```C
+typedef void (*napi_async_execute_callback)(napi_env env, void* data);
+```
+
+#### napi_async_complete_callback
+Function pointer used with functions that support asynchronous
+operations. Callback functions must statisfy the following signature:
+
+```C
+typedef void (*napi_async_complete_callback)(napi_env env,
+ napi_status status,
+ void* data);
+```
+
+## Error Handling
+N-API uses both return values and JavaScript exceptions for error handling.
+The following sections explain the approach for each case.
+
+### Return values
+All of the N-API functions share the same error handling pattern. The
+return type of all API functions is `napi_status`.
+
+The return value will be `napi_ok` if the request was successful and
+no uncaught JavaScript exception was thrown. If an error occurred AND
+an exception was thrown, the `napi_status` value for the error
+will be returned. If an exception was thrown, and no error occurred,
+`napi_pending_exception` will be returned.
+
+In cases where a return value other than `napi_ok` or
+`napi_pending_exception` is returned, [`napi_is_exception_pending`][]
+must be called to check if an exception is pending.
+See the section on exceptions for more details.
+
+The full set of possible napi_status values is defined
+in `napi_api_types.h`.
+
+The `napi_status` return value provides a VM-independent representation of
+the error which occurred. In some cases it is useful to be able to get
+more detailed information, including a string representing the error as well as
+VM (engine)-specific information.
+
+In order to retrieve this information [`napi_get_last_error_info`][]
+is provided which returns a `napi_extended_error_info` structure.
+The format of the `napi_extended_error_info` structure is as follows:
+
+```C
+typedef struct napi_extended_error_info {
+ const char* error_message;
+ void* engine_reserved;
+ uint32_t engine_error_code;
+ napi_status error_code;
+};
+```
+- `error_message`: Textual representation of the error that occured.
+- `engine_reserved`: Opaque handle reserved for engine use only.
+- `engine_error_code`: VM specific error code.
+- `error_code`: n-api status code for the last error.
+
+[`napi_get_last_error_info`][] returns the information for the last
+N-API call that was made.
+
+**Note:** Do not rely on the content or format of any of the extended
+information as it is not subject to SemVer and may change at any time.
+It is intended only for logging purposes.
+
+#### napi_get_last_error_info
+
+```C
+napi_status
+napi_get_last_error_info(napi_env env,
+ const napi_extended_error_info** result);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: The `napi_extended_error_info` structure with more
+information about the error.
+
+Returns `napi_ok` if the API succeeded.
+
+This API retrieves a `napi_extended_error_info` structure with information
+about the last error that occured.
+
+*Note*: The content of the `napi_extended_error_info` returned is only
+valid up until an n-api function is called on the same `env`.
+
+*Note*: Do not rely on the content or format of any of the extended
+information as it is not subject to SemVer and may change at any time.
+It is intended only for logging purposes.
+
+This API can be called even if there is a pending JavaScript exception.
+
+
+### Exceptions
+Any N-API function call may result in a pending JavaScript exception. This is
+obviously the case for any function that may cause the execution of
+JavaScript, but N-API specifies that an exception may be pending
+on return from any of the API functions.
+
+If the `napi_status` returned by a function is `napi_ok` then no
+exception is pending and no additional action is required. If the
+`napi_status` returned is anything other than `napi_ok` or
+`napi_pending_exception`, in order to try to recover and continue
+instead of simply returning immediately, [`napi_is_exception_pending`][]
+must be called in order to determine if an exception is pending or not.
+
+When an exception is pending one of two approaches can be employed.
+
+The first approach is to do any appropriate cleanup and then return so that
+execution will return to JavaScript. As part of the transition back to
+JavaScript the exception will be thrown at the point in the JavaScript
+code where the native method was invoked. The behavior of most N-API calls
+is unspecified while an exception is pending, and many will simply return
+`napi_pending_exception`, so it is important to do as little as possible
+and then return to JavaScript where the exception can be handled.
+
+The second approach is to try to handle the exception. There will be cases
+where the native code can catch the exception, take the appropriate action,
+and then continue. This is only recommended in specific cases
+where it is known that the exception can be safely handled. In these
+cases [`napi_get_and_clear_last_exception`][] can be used to get and
+clear the exception. On success, result will contain the handle to
+the last JavaScript Object thrown. If it is determined, after
+retrieving the exception, the exception cannot be handled after all
+it can be re-thrown it with [`napi_throw`][] where error is the
+JavaScript Error object to be thrown.
+
+The following utility functions are also available in case native code
+needs to throw an exception or determine if a `napi_value` is an instance
+of a JavaScript `Error` object: [`napi_throw_error`][],
+[`napi_throw_type_error`][], [`napi_throw_range_error`][] and
+[`napi_is_error`][].
+
+The following utility functions are also available in case native
+code needs to create an Error object: [`napi_create_error`][],
+[`napi_create_type_error`][], and [`napi_create_range_error`][].
+where result is the napi_value that refers to the newly created
+JavaScript Error object.
+
+The Node.js project is adding error codes to all of the errors
+generated internally. The goal is for applications to use these
+error codes for all error checking. The associated error messages
+will remain, but will only be meant to be used for logging and
+display with the expectation that the message can change without
+SemVer applying. In order to support this model with N-API, both
+in internal functionality and for module specific functionality
+(as its good practice), the `throw_` and `create_` functions
+take an optional code parameter which is the string for the code
+to be added to the error object. If the optional parameter is NULL
+then no code will be associated with the error. If a code is provided,
+the name associated with the error is also updated to be:
+
+```text
+originalName [code]
+```
+
+where originalName is the original name associated with the error
+and code is the code that was provided. For example if the code
+is 'ERR_ERROR_1' and a TypeError is being created the name will be:
+
+```text
+TypeError [ERR_ERROR_1]
+```
+
+#### napi_throw
+
+```C
+NODE_EXTERN napi_status napi_throw(napi_env env, napi_value error);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] error`: The `napi_value` for the Error to be thrown.
+
+Returns `napi_ok` if the API succeeded.
+
+This API throws the JavaScript Error provided.
+
+
+#### napi_throw_error
+
+```C
+NODE_EXTERN napi_status napi_throw_error(napi_env env,
+ const char* code,
+ const char* msg);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] code`: Optional error code to be set on the error.
+- `[in] msg`: C string representing the text to be associated with
+the error.
+
+Returns `napi_ok` if the API succeeded.
+
+This API throws a JavaScript Error with the text provided.
+
+#### napi_throw_type_error
+
+```C
+NODE_EXTERN napi_status napi_throw_type_error(napi_env env,
+ const char* code,
+ const char* msg);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] code`: Optional error code to be set on the error.
+- `[in] msg`: C string representing the text to be associated with
+the error.
+
+Returns `napi_ok` if the API succeeded.
+
+This API throws a JavaScript TypeError with the text provided.
+
+#### napi_throw_range_error
+
+```C
+NODE_EXTERN napi_status napi_throw_range_error(napi_env env,
+ const char* code,
+ const char* msg);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] code`: Optional error code to be set on the error.
+- `[in] msg`: C string representing the text to be associated with
+the error.
+
+Returns `napi_ok` if the API succeeded.
+
+This API throws a JavaScript RangeError with the text provided.
+
+
+#### napi_is_error
+
+```C
+NODE_EXTERN napi_status napi_is_error(napi_env env,
+ napi_value value,
+ bool* result);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] msg`: The `napi_value` to be checked.
+- `[out] result`: Boolean value that is set to true if `napi_value` represents
+an error, false otherwise.
+
+Returns `napi_ok` if the API succeeded.
+
+This API queries a `napi_value` to check if it represents an error object.
+
+
+#### napi_create_error
+
+```C
+NODE_EXTERN napi_status napi_create_error(napi_env env,
+ napi_value code,
+ napi_value msg,
+ napi_value* result);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] code`: Optional `napi_value` with the string for the error code to
+ be associated with the error.
+- `[in] msg`: napi_value that references a JavaScript String to be
+used as the message for the Error.
+- `[out] result`: `napi_value` representing the error created.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns a JavaScript Error with the text provided.
+
+#### napi_create_type_error
+
+```C
+NODE_EXTERN napi_status napi_create_type_error(napi_env env,
+ napi_value code,
+ napi_value msg,
+ napi_value* result);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] code`: Optional `napi_value` with the string for the error code to
+ be associated with the error.
+- `[in] msg`: napi_value that references a JavaScript String to be
+used as the message for the Error.
+- `[out] result`: `napi_value` representing the error created.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns a JavaScript TypeError with the text provided.
+
+
+#### napi_create_range_error
+
+```C
+NODE_EXTERN napi_status napi_create_range_error(napi_env env,
+ napi_value code,
+ const char* msg,
+ napi_value* result);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] code`: Optional `napi_value` with the string for the error code to
+ be associated with the error.
+- `[in] msg`: napi_value that references a JavaScript String to be
+used as the message for the Error.
+- `[out] result`: `napi_value` representing the error created.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns a JavaScript RangeError with the text provided.
+
+#### napi_get_and_clear_last_exception
+
+```C
+napi_status napi_get_and_clear_last_exception(napi_env env,
+ napi_value* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: The exception if one is pending, NULL otherwise.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns true if an exception is pending.
+
+This API can be called even if there is a pending JavaScript exception.
+
+#### napi_is_exception_pending
+
+```C
+napi_status napi_is_exception_pending(napi_env env, bool* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: Boolean value that is set to true if an exception is pending.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns true if an exception is pending.
+
+This API can be called even if there is a pending JavaScript exception.
+
+#### napi_fatal_exception
+
+```C
+napi_status napi_fatal_exception(napi_env env, napi_value err);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] err`: The error you want to pass to `uncaughtException`.
+
+Trigger an `uncaughtException` in JavaScript. Useful if an async
+callback throws an exception with no way to recover.
+
+### Fatal Errors
+
+In the event of an unrecoverable error in a native module, a fatal error can be
+thrown to immediately terminate the process.
+
+#### napi_fatal_error
+
+```C
+NAPI_NO_RETURN void napi_fatal_error(const char* location,
+ size_t location_len,
+ const char* message,
+ size_t message_len);
+```
+
+- `[in] location`: Optional location at which the error occurred.
+- `[in] location_len`: The length of the location in bytes, or
+`NAPI_AUTO_LENGTH` if it is null-terminated.
+- `[in] message`: The message associated with the error.
+- `[in] message_len`: The length of the message in bytes, or
+`NAPI_AUTO_LENGTH` if it is
+null-terminated.
+
+The function call does not return, the process will be terminated.
+
+This API can be called even if there is a pending JavaScript exception.
+
+## Object Lifetime management
+
+As N-API calls are made, handles to objects in the heap for the underlying
+VM may be returned as `napi_values`. These handles must hold the
+objects 'live' until they are no longer required by the native code,
+otherwise the objects could be collected before the native code was
+finished using them.
+
+As object handles are returned they are associated with a
+'scope'. The lifespan for the default scope is tied to the lifespan
+of the native method call. The result is that, by default, handles
+remain valid and the objects associated with these handles will be
+held live for the lifespan of the native method call.
+
+In many cases, however, it is necessary that the handles remain valid for
+either a shorter or longer lifespan than that of the native method.
+The sections which follow describe the N-API functions than can be used
+to change the handle lifespan from the default.
+
+### Making handle lifespan shorter than that of the native method
+It is often necessary to make the lifespan of handles shorter than
+the lifespan of a native method. For example, consider a native method
+that has a loop which iterates through the elements in a large array:
+
+```C
+for (int i = 0; i < 1000000; i++) {
+ napi_value result;
+ napi_status status = napi_get_element(e, object, i, &result);
+ if (status != napi_ok) {
+ break;
+ }
+ // do something with element
+}
+```
+
+This would result in a large number of handles being created, consuming
+substantial resources. In addition, even though the native code could only
+use the most recent handle, all of the associated objects would also be
+kept alive since they all share the same scope.
+
+To handle this case, N-API provides the ability to establish a new 'scope' to
+which newly created handles will be associated. Once those handles
+are no longer required, the scope can be 'closed' and any handles associated
+with the scope are invalidated. The methods available to open/close scopes are
+[`napi_open_handle_scope`][] and [`napi_close_handle_scope`][].
+
+N-API only supports a single nested hierarchy of scopes. There is only one
+active scope at any time, and all new handles will be associated with that
+scope while it is active. Scopes must be closed in the reverse order from
+which they are opened. In addition, all scopes created within a native method
+must be closed before returning from that method.
+
+Taking the earlier example, adding calls to [`napi_open_handle_scope`][] and
+[`napi_close_handle_scope`][] would ensure that at most a single handle
+is valid throughout the execution of the loop:
+
+```C
+for (int i = 0; i < 1000000; i++) {
+ napi_handle_scope scope;
+ napi_status status = napi_open_handle_scope(env, &scope);
+ if (status != napi_ok) {
+ break;
+ }
+ napi_value result;
+ status = napi_get_element(e, object, i, &result);
+ if (status != napi_ok) {
+ break;
+ }
+ // do something with element
+ status = napi_close_handle_scope(env, scope);
+ if (status != napi_ok) {
+ break;
+ }
+}
+```
+
+When nesting scopes, there are cases where a handle from an
+inner scope needs to live beyond the lifespan of that scope. N-API supports an
+'escapable scope' in order to support this case. An escapable scope
+allows one handle to be 'promoted' so that it 'escapes' the
+current scope and the lifespan of the handle changes from the current
+scope to that of the outer scope.
+
+The methods available to open/close escapable scopes are
+[`napi_open_escapable_handle_scope`][] and [`napi_close_escapable_handle_scope`][].
+
+The request to promote a handle is made through [`napi_escape_handle`][] which
+can only be called once.
+
+#### napi_open_handle_scope
+
+```C
+NODE_EXTERN napi_status napi_open_handle_scope(napi_env env,
+ napi_handle_scope* result);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: `napi_value` representing the new scope.
+
+Returns `napi_ok` if the API succeeded.
+
+This API open a new scope.
+
+#### napi_close_handle_scope
+
+```C
+NODE_EXTERN napi_status napi_close_handle_scope(napi_env env,
+ napi_handle_scope scope);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] scope`: `napi_value` representing the scope to be closed.
+
+Returns `napi_ok` if the API succeeded.
+
+This API closes the scope passed in. Scopes must be closed in the
+reverse order from which they were created.
+
+This API can be called even if there is a pending JavaScript exception.
+
+#### napi_open_escapable_handle_scope
+
+```C
+NODE_EXTERN napi_status
+ napi_open_escapable_handle_scope(napi_env env,
+ napi_handle_scope* result);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: `napi_value` representing the new scope.
+
+Returns `napi_ok` if the API succeeded.
+
+This API open a new scope from which one object can be promoted
+to the outer scope.
+
+#### napi_close_escapable_handle_scope
+
+```C
+NODE_EXTERN napi_status
+ napi_close_escapable_handle_scope(napi_env env,
+ napi_handle_scope scope);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] scope`: `napi_value` representing the scope to be closed.
+
+Returns `napi_ok` if the API succeeded.
+
+This API closes the scope passed in. Scopes must be closed in the
+reverse order from which they were created.
+
+This API can be called even if there is a pending JavaScript exception.
+
+#### napi_escape_handle
+
+```C
+napi_status napi_escape_handle(napi_env env,
+ napi_escapable_handle_scope scope,
+ napi_value escapee,
+ napi_value* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] scope`: `napi_value` representing the current scope.
+- `[in] escapee`: `napi_value` representing the JavaScript Object to be escaped.
+- `[out] result`: `napi_value` representing the handle to the escaped
+Object in the outer scope.
+
+Returns `napi_ok` if the API succeeded.
+
+This API promotes the handle to the JavaScript object so that it is valid
+for the lifetime of the outer scope. It can only be called once per scope.
+If it is called more than once an error will be returned.
+
+This API can be called even if there is a pending JavaScript exception.
+
+### References to objects with a lifespan longer than that of the native method
+
+In some cases an addon will need to be able to create and reference objects
+with a lifespan longer than that of a single native method invocation. For
+example, to create a constructor and later use that constructor
+in a request to creates instances, it must be possible to reference
+the constructor object across many different instance creation requests. This
+would not be possible with a normal handle returned as a `napi_value` as
+described in the earlier section. The lifespan of a normal handle is
+managed by scopes and all scopes must be closed before the end of a native
+method.
+
+N-API provides methods to create persistent references to an object.
+Each persistent reference has an associated count with a value of 0
+or higher. The count determines if the reference will keep
+the corresponding object live. References with a count of 0 do not
+prevent the object from being collected and are often called 'weak'
+references. Any count greater than 0 will prevent the object
+from being collected.
+
+References can be created with an initial reference count. The count can
+then be modified through [`napi_reference_ref`][] and
+[`napi_reference_unref`][]. If an object is collected while the count
+for a reference is 0, all subsequent calls to
+get the object associated with the reference [`napi_get_reference_value`][]
+will return NULL for the returned `napi_value`. An attempt to call
+[`napi_reference_ref`][] for a reference whose object has been collected
+will result in an error.
+
+References must be deleted once they are no longer required by the addon. When
+a reference is deleted it will no longer prevent the corresponding object from
+being collected. Failure to delete a persistent reference will result in
+a 'memory leak' with both the native memory for the persistent reference and
+the corresponding object on the heap being retained forever.
+
+There can be multiple persistent references created which refer to the same
+object, each of which will either keep the object live or not based on its
+individual count.
+
+#### napi_create_reference
+
+```C
+NODE_EXTERN napi_status napi_create_reference(napi_env env,
+ napi_value value,
+ int initial_refcount,
+ napi_ref* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing the Object to which we want
+a reference.
+- `[in] initial_refcount`: Initial reference count for the new reference.
+- `[out] result`: `napi_ref` pointing to the new reference.
+
+Returns `napi_ok` if the API succeeded.
+
+This API create a new reference with the specified reference count
+to the Object passed in.
+
+#### napi_delete_reference
+
+```C
+NODE_EXTERN napi_status napi_delete_reference(napi_env env, napi_ref ref);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] ref`: `napi_ref` to be deleted.
+
+Returns `napi_ok` if the API succeeded.
+
+This API deletes the reference passed in.
+
+This API can be called even if there is a pending JavaScript exception.
+
+#### napi_reference_ref
+
+```C
+NODE_EXTERN napi_status napi_reference_ref(napi_env env,
+ napi_ref ref,
+ int* result);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] ref`: `napi_ref` for which the reference count will be incremented.
+- `[out] result`: The new reference count.
+
+Returns `napi_ok` if the API succeeded.
+
+This API increments the reference count for the reference
+passed in and returns the resulting reference count.
+
+#### napi_reference_unref
+
+```C
+NODE_EXTERN napi_status napi_reference_unref(napi_env env,
+ napi_ref ref,
+ int* result);
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] ref`: `napi_ref` for which the reference count will be decremented.
+- `[out] result`: The new reference count.
+
+Returns `napi_ok` if the API succeeded.
+
+This API decrements the reference count for the reference
+passed in and returns the resulting reference count.
+
+#### napi_get_reference_value
+
+```C
+NODE_EXTERN napi_status napi_get_reference_value(napi_env env,
+ napi_ref ref,
+ napi_value* result);
+```
+
+the `napi_value passed` in or out of these methods is a handle to the
+object to which the reference is related.
+- `[in] env`: The environment that the API is invoked under.
+- `[in] ref`: `napi_ref` for which we requesting the corresponding Object.
+- `[out] result`: The `napi_value` for the Object referenced by the
+`napi_ref`.
+
+Returns `napi_ok` if the API succeeded.
+
+If still valid, this API returns the `napi_value` representing the
+JavaScript Object associated with the `napi_ref`. Otherwise, result
+will be NULL.
+
+## Module registration
+N-API modules are registered in a manner similar to other modules
+except that instead of using the `NODE_MODULE` macro the following
+is used:
+
+```C
+NAPI_MODULE(addon, Init)
+```
+
+The next difference is the signature for the `Init` method. For a N-API
+module it is as follows:
+
+```C
+napi_value Init(napi_env env, napi_value exports);
+```
+
+The return value from `Init` is treated as the `exports` object for the module.
+The `Init` method is passed an empty object via the `exports` parameter as a
+convenience. If `Init` returns NULL, the parameter passed as `exports` is
+exported by the module. N-API modules cannot modify the `module` object but can
+specify anything as the `exports` property of the module.
+
+For example, to add the method `hello` as a function so that it can be called
+as a method provided by the addon:
+
+```C
+napi_value Init(napi_env env, napi_value exports) {
+ napi_status status;
+ napi_property_descriptor desc =
+ {"hello", Method, 0, 0, 0, napi_default, 0};
+ if (status != napi_ok) return NULL;
+ status = napi_define_properties(env, exports, 1, &desc);
+ if (status != napi_ok) return NULL;
+ return exports;
+}
+```
+
+For example, to set a function to be returned by the `require()` for the addon:
+
+```C
+napi_value Init(napi_env env, napi_value exports) {
+ napi_value method;
+ napi_status status;
+ status = napi_create_function(env, "exports", NAPI_AUTO_LENGTH, Method, NULL, &method);
+ if (status != napi_ok) return NULL;
+ return method;
+}
+```
+
+For example, to define a class so that new instances can be created
+(often used with [Object Wrap][]):
+
+```C
+// NOTE: partial example, not all referenced code is included
+napi_value Init(napi_env env, napi_value exports) {
+ napi_status status;
+ napi_property_descriptor properties[] = {
+ { "value", NULL, GetValue, SetValue, 0, napi_default, 0 },
+ DECLARE_NAPI_METHOD("plusOne", PlusOne),
+ DECLARE_NAPI_METHOD("multiply", Multiply),
+ };
+
+ napi_value cons;
+ status =
+ napi_define_class(env, "MyObject", New, NULL, 3, properties, &cons);
+ if (status != napi_ok) return NULL;
+
+ status = napi_create_reference(env, cons, 1, &constructor);
+ if (status != napi_ok) return NULL;
+
+ status = napi_set_named_property(env, exports, "MyObject", cons);
+ if (status != napi_ok) return NULL;
+
+ return exports;
+}
+```
+
+For more details on setting properties on objects, see the section on
+[Working with JavaScript Properties][].
+
+For more details on building addon modules in general, refer to the existing API
+
+## Working with JavaScript Values
+N-API exposes a set of APIs to create all types of JavaScript values.
+Some of these types are documented under
+[Section 6](https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values)
+of the [ECMAScript Language Specification][].
+
+Fundamentally, these APIs are used to do one of the following:
+1. Create a new JavaScript object
+2. Convert from a primitive C type to an N-API value
+3. Convert from N-API value to a primitive C type
+4. Get global instances including `undefined` and `null`
+
+N-API values are represented by the type `napi_value`.
+Any N-API call that requires a JavaScript value takes in a `napi_value`.
+In some cases, the API does check the type of the `napi_value` up-front.
+However, for better performance, it's better for the caller to make sure that
+the `napi_value` in question is of the JavaScript type expected by the API.
+
+### Enum types
+#### napi_valuetype
+```C
+typedef enum {
+ // ES6 types (corresponds to typeof)
+ napi_undefined,
+ napi_null,
+ napi_boolean,
+ napi_number,
+ napi_string,
+ napi_symbol,
+ napi_object,
+ napi_function,
+ napi_external,
+} napi_valuetype;
+```
+
+Describes the type of a `napi_value`. This generally corresponds to the types
+described in
+[Section 6.1](https://tc39.github.io/ecma262/#sec-ecmascript-language-types) of
+the ECMAScript Language Specification.
+In addition to types in that section, `napi_valuetype` can also represent
+Functions and Objects with external data.
+
+#### napi_typedarray_type
+```C
+typedef enum {
+ napi_int8_array,
+ napi_uint8_array,
+ napi_uint8_clamped_array,
+ napi_int16_array,
+ napi_uint16_array,
+ napi_int32_array,
+ napi_uint32_array,
+ napi_float32_array,
+ napi_float64_array,
+} napi_typedarray_type;
+```
+
+This represents the underlying binary scalar datatype of the TypedArray.
+Elements of this enum correspond to
+[Section 22.2](https://tc39.github.io/ecma262/#sec-typedarray-objects)
+of the [ECMAScript Language Specification][].
+
+### Object Creation Functions
+#### napi_create_array
+
+```C
+napi_status napi_create_array(napi_env env, napi_value* result)
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[out] result`: A `napi_value` representing a JavaScript Array.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns an N-API value corresponding to a JavaScript Array type.
+JavaScript arrays are described in
+[Section 22.1](https://tc39.github.io/ecma262/#sec-array-objects) of the
+ECMAScript Language Specification.
+
+#### napi_create_array_with_length
+
+```C
+napi_status napi_create_array_with_length(napi_env env,
+ size_t length,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] length`: The initial length of the Array.
+- `[out] result`: A `napi_value` representing a JavaScript Array.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns an N-API value corresponding to a JavaScript Array type.
+The Array's length property is set to the passed-in length parameter.
+However, the underlying buffer is not guaranteed to be pre-allocated by the VM
+when the array is created - that behavior is left to the underlying VM
+implementation.
+If the buffer must be a contiguous block of memory that can be
+directly read and/or written via C, consider using
+[`napi_create_external_arraybuffer`][].
+
+JavaScript arrays are described in
+[Section 22.1](https://tc39.github.io/ecma262/#sec-array-objects) of the
+ECMAScript Language Specification.
+
+#### napi_create_arraybuffer
+
+```C
+napi_status napi_create_arraybuffer(napi_env env,
+ size_t byte_length,
+ void** data,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] length`: The length in bytes of the array buffer to create.
+- `[out] data`: Pointer to the underlying byte buffer of the ArrayBuffer.
+- `[out] result`: A `napi_value` representing a JavaScript ArrayBuffer.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns an N-API value corresponding to a JavaScript ArrayBuffer.
+ArrayBuffers are used to represent fixed-length binary data buffers. They are
+normally used as a backing-buffer for TypedArray objects.
+The ArrayBuffer allocated will have an underlying byte buffer whose size is
+determined by the `length` parameter that's passed in.
+The underlying buffer is optionally returned back to the caller in case the
+caller wants to directly manipulate the buffer. This buffer can only be
+written to directly from native code. To write to this buffer from JavaScript,
+a typed array or DataView object would need to be created.
+
+JavaScript ArrayBuffer objects are described in
+[Section 24.1](https://tc39.github.io/ecma262/#sec-arraybuffer-objects)
+of the ECMAScript Language Specification.
+
+#### napi_create_buffer
+
+```C
+napi_status napi_create_buffer(napi_env env,
+ size_t size,
+ void** data,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] size`: Size in bytes of the underlying buffer.
+- `[out] data`: Raw pointer to the underlying buffer.
+- `[out] result`: A `napi_value` representing a `node::Buffer`.
+
+Returns `napi_ok` if the API succeeded.
+
+This API allocates a `node::Buffer` object. While this is still a
+fully-supported data structure, in most cases using a TypedArray will suffice.
+
+#### napi_create_buffer_copy
+
+```C
+napi_status napi_create_buffer_copy(napi_env env,
+ size_t length,
+ const void* data,
+ void** result_data,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] size`: Size in bytes of the input buffer (should be the same as the
+ size of the new buffer).
+- `[in] data`: Raw pointer to the underlying buffer to copy from.
+- `[out] result_data`: Pointer to the new Buffer's underlying data buffer.
+- `[out] result`: A `napi_value` representing a `node::Buffer`.
+
+Returns `napi_ok` if the API succeeded.
+
+This API allocates a `node::Buffer` object and initializes it with data copied
+from the passed-in buffer. While this is still a fully-supported data
+structure, in most cases using a TypedArray will suffice.
+
+#### napi_create_external
+
+```C
+napi_status napi_create_external(napi_env env,
+ void* data,
+ napi_finalize finalize_cb,
+ void* finalize_hint,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] data`: Raw pointer to the external data.
+- `[in] finalize_cb`: Optional callback to call when the external value
+is being collected.
+- `[in] finalize_hint`: Optional hint to pass to the finalize callback
+during collection.
+- `[out] result`: A `napi_value` representing an external value.
+
+Returns `napi_ok` if the API succeeded.
+
+This API allocates a JavaScript value with external data attached to it. This
+is used to pass external data through JavaScript code, so it can be retrieved
+later by native code. The API allows the caller to pass in a finalize callback,
+in case the underlying native resource needs to be cleaned up when the external
+JavaScript value gets collected.
+
+*Note*: The created value is not an object, and therefore does not support
+additional properties. It is considered a distinct value type: calling
+`napi_typeof()` with an external value yields `napi_external`.
+
+#### napi_create_external_arraybuffer
+
+```C
+napi_status
+napi_create_external_arraybuffer(napi_env env,
+ void* external_data,
+ size_t byte_length,
+ napi_finalize finalize_cb,
+ void* finalize_hint,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] external_data`: Pointer to the underlying byte buffer of the
+ArrayBuffer.
+- `[in] byte_length`: The length in bytes of the underlying buffer.
+- `[in] finalize_cb`: Optional callback to call when the ArrayBuffer is
+being collected.
+- `[in] finalize_hint`: Optional hint to pass to the finalize callback
+during collection.
+- `[out] result`: A `napi_value` representing a JavaScript ArrayBuffer.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns an N-API value corresponding to a JavaScript ArrayBuffer.
+The underlying byte buffer of the ArrayBuffer is externally allocated and
+managed. The caller must ensure that the byte buffer remains valid until the
+finalize callback is called.
+
+JavaScript ArrayBuffers are described in
+[Section 24.1](https://tc39.github.io/ecma262/#sec-arraybuffer-objects)
+of the ECMAScript Language Specification.
+
+#### napi_create_external_buffer
+
+```C
+napi_status napi_create_external_buffer(napi_env env,
+ size_t length,
+ void* data,
+ napi_finalize finalize_cb,
+ void* finalize_hint,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] length`: Size in bytes of the input buffer (should be the same as
+the size of the new buffer).
+- `[in] data`: Raw pointer to the underlying buffer to copy from.
+- `[in] finalize_cb`: Optional callback to call when the ArrayBuffer is
+being collected.
+- `[in] finalize_hint`: Optional hint to pass to the finalize callback
+during collection.
+- `[out] result`: A `napi_value` representing a `node::Buffer`.
+
+Returns `napi_ok` if the API succeeded.
+
+This API allocates a `node::Buffer` object and initializes it with data
+backed by the passed in buffer. While this is still a fully-supported data
+structure, in most cases using a TypedArray will suffice.
+
+**Note:** For Node.js >=4 `Buffers` are Uint8Arrays.
+
+#### napi_create_function
+
+```C
+napi_status napi_create_function(napi_env env,
+ const char* utf8name,
+ size_t length,
+ napi_callback cb,
+ void* data,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] utf8name`: A string representing the name of the function encoded as
+UTF8.
+- `[in] length`: The length of the utf8name in bytes, or
+`NAPI_AUTO_LENGTH` if it is null-terminated.
+- `[in] cb`: A function pointer to the native function to be invoked when the
+created function is invoked from JavaScript.
+- `[in] data`: Optional arbitrary context data to be passed into the native
+function when it is invoked.
+- `[out] result`: A `napi_value` representing a JavaScript function.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns an N-API value corresponding to a JavaScript Function object.
+It's used to wrap native functions so that they can be invoked from JavaScript.
+
+JavaScript Functions are described in
+[Section 19.2](https://tc39.github.io/ecma262/#sec-function-objects)
+of the ECMAScript Language Specification.
+
+#### napi_create_object
+
+```C
+napi_status napi_create_object(napi_env env, napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: A `napi_value` representing a JavaScript Object.
+
+Returns `napi_ok` if the API succeeded.
+
+This API allocates a default JavaScript Object.
+It is the equivalent of doing `new Object()` in JavaScript.
+
+The JavaScript Object type is described in
+[Section 6.1.7](https://tc39.github.io/ecma262/#sec-object-type) of the
+ECMAScript Language Specification.
+
+#### napi_create_symbol
+
+```C
+napi_status napi_create_symbol(napi_env env,
+ napi_value description,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] description`: Optional napi_value which refers to a JavaScript
+String to be set as the description for the symbol.
+- `[out] result`: A `napi_value` representing a JavaScript Symbol.
+
+Returns `napi_ok` if the API succeeded.
+
+This API creates a JavaScript Symbol object from a UTF8-encoded C string
+
+The JavaScript Symbol type is described in
+[Section 19.4](https://tc39.github.io/ecma262/#sec-symbol-objects)
+of the ECMAScript Language Specification.
+
+#### napi_create_typedarray
+
+```C
+napi_status napi_create_typedarray(napi_env env,
+ napi_typedarray_type type,
+ size_t length,
+ napi_value arraybuffer,
+ size_t byte_offset,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] type`: Scalar datatype of the elements within the TypedArray.
+- `[in] length`: Number of elements in the TypedArray.
+- `[in] arraybuffer`: ArrayBuffer underlying the typed array.
+- `[in] byte_offset`: The byte offset within the ArrayBuffer from which to
+start projecting the TypedArray.
+- `[out] result`: A `napi_value` representing a JavaScript TypedArray.
+
+Returns `napi_ok` if the API succeeded.
+
+This API creates a JavaScript TypedArray object over an existing ArrayBuffer.
+TypedArray objects provide an array-like view over an underlying data buffer
+where each element has the same underlying binary scalar datatype.
+
+It's required that (length * size_of_element) + byte_offset should
+be <= the size in bytes of the array passed in. If not, a RangeError exception is
+raised.
+
+JavaScript TypedArray Objects are described in
+[Section 22.2](https://tc39.github.io/ecma262/#sec-typedarray-objects)
+of the ECMAScript Language Specification.
+
+
+#### napi_create_dataview
+
+
+```C
+napi_status napi_create_dataview(napi_env env,
+ size_t byte_length,
+ napi_value arraybuffer,
+ size_t byte_offset,
+ napi_value* result)
+
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] length`: Number of elements in the DataView.
+- `[in] arraybuffer`: ArrayBuffer underlying the DataView.
+- `[in] byte_offset`: The byte offset within the ArrayBuffer from which to
+ start projecting the DataView.
+- `[out] result`: A `napi_value` representing a JavaScript DataView.
+
+Returns `napi_ok` if the API succeeded.
+
+This API creates a JavaScript DataView object over an existing ArrayBuffer.
+DataView objects provide an array-like view over an underlying data buffer,
+but one which allows items of different size and type in the ArrayBuffer.
+
+It is required that `byte_length + byte_offset` is less than or equal to the
+size in bytes of the array passed in. If not, a RangeError exception is raised.
+
+JavaScript DataView Objects are described in
+[Section 24.3][] of the ECMAScript Language Specification.
+
+### Functions to convert from C types to N-API
+#### napi_create_int32
+
+```C
+napi_status napi_create_int32(napi_env env, int32_t value, napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: Integer value to be represented in JavaScript.
+- `[out] result`: A `napi_value` representing a JavaScript Number.
+
+Returns `napi_ok` if the API succeeded.
+
+This API is used to convert from the C `int32_t` type to the JavaScript
+Number type.
+
+The JavaScript Number type is described in
+[Section 6.1.6](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type)
+of the ECMAScript Language Specification.
+
+#### napi_create_uint32
+
+```C
+napi_status napi_create_uint32(napi_env env, uint32_t value, napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: Unsigned integer value to be represented in JavaScript.
+- `[out] result`: A `napi_value` representing a JavaScript Number.
+
+Returns `napi_ok` if the API succeeded.
+
+This API is used to convert from the C `uint32_t` type to the JavaScript
+Number type.
+
+The JavaScript Number type is described in
+[Section 6.1.6](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type)
+of the ECMAScript Language Specification.
+
+#### napi_create_int64
+
+```C
+napi_status napi_create_int64(napi_env env, int64_t value, napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: Integer value to be represented in JavaScript.
+- `[out] result`: A `napi_value` representing a JavaScript Number.
+
+Returns `napi_ok` if the API succeeded.
+
+This API is used to convert from the C `int64_t` type to the JavaScript
+Number type.
+
+The JavaScript Number type is described in
+[Section 6.1.6](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type)
+of the ECMAScript Language Specification. Note the complete range of `int64_t`
+cannot be represented with full precision in JavaScript. Integer values
+outside the range of
+[`Number.MIN_SAFE_INTEGER`](https://tc39.github.io/ecma262/#sec-number.min_safe_integer)
+-(2^53 - 1) -
+[`Number.MAX_SAFE_INTEGER`](https://tc39.github.io/ecma262/#sec-number.max_safe_integer)
+(2^53 - 1) will lose precision.
+
+#### napi_create_double
+
+```C
+napi_status napi_create_double(napi_env env, double value, napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: Double-precision value to be represented in JavaScript.
+- `[out] result`: A `napi_value` representing a JavaScript Number.
+
+Returns `napi_ok` if the API succeeded.
+
+This API is used to convert from the C `double` type to the JavaScript
+Number type.
+
+The JavaScript Number type is described in
+[Section 6.1.6](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type)
+of the ECMAScript Language Specification.
+
+#### napi_create_string_latin1
+
+```C
+napi_status napi_create_string_latin1(napi_env env,
+ const char* str,
+ size_t length,
+ napi_value* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] str`: Character buffer representing a ISO-8859-1-encoded string.
+- `[in] length`: The length of the string in bytes, or
+`NAPI_AUTO_LENGTH` if it is null-terminated.
+- `[out] result`: A `napi_value` representing a JavaScript String.
+
+Returns `napi_ok` if the API succeeded.
+
+This API creates a JavaScript String object from a ISO-8859-1-encoded C string.
+
+The JavaScript String type is described in
+[Section 6.1.4](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type)
+of the ECMAScript Language Specification.
+
+#### napi_create_string_utf16
+
+```C
+napi_status napi_create_string_utf16(napi_env env,
+ const char16_t* str,
+ size_t length,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] str`: Character buffer representing a UTF16-LE-encoded string.
+- `[in] length`: The length of the string in two-byte code units, or
+`NAPI_AUTO_LENGTH` if it is null-terminated.
+- `[out] result`: A `napi_value` representing a JavaScript String.
+
+Returns `napi_ok` if the API succeeded.
+
+This API creates a JavaScript String object from a UTF16-LE-encoded C string
+
+The JavaScript String type is described in
+[Section 6.1.4](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type)
+of the ECMAScript Language Specification.
+
+#### napi_create_string_utf8
+
+```C
+napi_status napi_create_string_utf8(napi_env env,
+ const char* str,
+ size_t length,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] str`: Character buffer representing a UTF8-encoded string.
+- `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH`
+if it is null-terminated.
+- `[out] result`: A `napi_value` representing a JavaScript String.
+
+Returns `napi_ok` if the API succeeded.
+
+This API creates a JavaScript String object from a UTF8-encoded C string
+
+The JavaScript String type is described in
+[Section 6.1.4](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type)
+of the ECMAScript Language Specification.
+
+### Functions to convert from N-API to C types
+#### napi_get_array_length
+
+```C
+napi_status napi_get_array_length(napi_env env,
+ napi_value value,
+ uint32_t* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing the JavaScript Array whose length is
+being queried.
+- `[out] result`: `uint32` representing length of the array.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns the length of an array.
+
+Array length is described in
+[Section 22.1.4.1](https://tc39.github.io/ecma262/#sec-properties-of-array-instances-length)
+of the ECMAScript Language Specification.
+
+#### napi_get_arraybuffer_info
+
+```C
+napi_status napi_get_arraybuffer_info(napi_env env,
+ napi_value arraybuffer,
+ void** data,
+ size_t* byte_length)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] arraybuffer`: `napi_value` representing the ArrayBuffer being queried.
+- `[out] data`: The underlying data buffer of the ArrayBuffer.
+- `[out] byte_length`: Length in bytes of the underlying data buffer.
+
+Returns `napi_ok` if the API succeeded.
+
+This API is used to retrieve the underlying data buffer of an ArrayBuffer and
+its length.
+
+*WARNING*: Use caution while using this API. The lifetime of the underlying data
+buffer is managed by the ArrayBuffer even after it's returned. A
+possible safe way to use this API is in conjunction with [`napi_create_reference`][],
+which can be used to guarantee control over the lifetime of the
+ArrayBuffer. It's also safe to use the returned data buffer within the same
+callback as long as there are no calls to other APIs that might trigger a GC.
+
+#### napi_get_buffer_info
+
+```C
+napi_status napi_get_buffer_info(napi_env env,
+ napi_value value,
+ void** data,
+ size_t* length)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing the `node::Buffer` being queried.
+- `[out] data`: The underlying data buffer of the `node::Buffer`.
+- `[out] length`: Length in bytes of the underlying data buffer.
+
+Returns `napi_ok` if the API succeeded.
+
+This API is used to retrieve the underlying data buffer of a `node::Buffer`
+and it's length.
+
+*Warning*: Use caution while using this API since the underlying data buffer's
+lifetime is not guaranteed if it's managed by the VM.
+
+#### napi_get_prototype
+
+```C
+napi_status napi_get_prototype(napi_env env,
+ napi_value object,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] object`: `napi_value` representing JavaScript Object whose prototype
+to return. This returns the equivalent of `Object.getPrototypeOf` (which is
+not the same as the function's `prototype` property).
+- `[out] result`: `napi_value` representing prototype of the given object.
+
+Returns `napi_ok` if the API succeeded.
+
+#### napi_get_typedarray_info
+
+```C
+napi_status napi_get_typedarray_info(napi_env env,
+ napi_value typedarray,
+ napi_typedarray_type* type,
+ size_t* length,
+ void** data,
+ napi_value* arraybuffer,
+ size_t* byte_offset)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] typedarray`: `napi_value` representing the TypedArray whose
+properties to query.
+- `[out] type`: Scalar datatype of the elements within the TypedArray.
+- `[out] length`: Number of elements in the TypedArray.
+- `[out] data`: The data buffer underlying the typed array.
+- `[out] byte_offset`: The byte offset within the data buffer from which
+to start projecting the TypedArray.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns various properties of a typed array.
+
+*Warning*: Use caution while using this API since the underlying data buffer
+is managed by the VM
+
+#### napi_get_dataview_info
+
+
+```C
+napi_status napi_get_dataview_info(napi_env env,
+ napi_value dataview,
+ size_t* byte_length,
+ void** data,
+ napi_value* arraybuffer,
+ size_t* byte_offset)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] dataview`: `napi_value` representing the DataView whose
+ properties to query.
+- `[out] byte_length`: Number of bytes in the DataView.
+- `[out] data`: The data buffer underlying the DataView.
+- `[out] arraybuffer`: ArrayBuffer underlying the DataView.
+- `[out] byte_offset`: The byte offset within the data buffer from which
+ to start projecting the DataView.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns various properties of a DataView.
+
+#### napi_get_value_bool
+
+```C
+napi_status napi_get_value_bool(napi_env env, napi_value value, bool* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing JavaScript Boolean.
+- `[out] result`: C boolean primitive equivalent of the given JavaScript
+Boolean.
+
+Returns `napi_ok` if the API succeeded. If a non-boolean `napi_value` is
+passed in it returns `napi_boolean_expected`.
+
+This API returns the C boolean primitive equivalent of the given JavaScript
+Boolean.
+
+#### napi_get_value_double
+
+```C
+napi_status napi_get_value_double(napi_env env,
+ napi_value value,
+ double* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing JavaScript Number.
+- `[out] result`: C double primitive equivalent of the given JavaScript
+Number.
+
+Returns `napi_ok` if the API succeeded. If a non-number `napi_value` is passed
+in it returns `napi_number_expected`.
+
+This API returns the C double primitive equivalent of the given JavaScript
+Number.
+
+#### napi_get_value_external
+
+```C
+napi_status napi_get_value_external(napi_env env,
+ napi_value value,
+ void** result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing JavaScript external value.
+- `[out] result`: Pointer to the data wrapped by the JavaScript external value.
+
+Returns `napi_ok` if the API succeeded. If a non-external `napi_value` is
+passed in it returns `napi_invalid_arg`.
+
+This API retrieves the external data pointer that was previously passed to
+`napi_create_external()`.
+
+#### napi_get_value_int32
+
+```C
+napi_status napi_get_value_int32(napi_env env,
+ napi_value value,
+ int32_t* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing JavaScript Number.
+- `[out] result`: C int32 primitive equivalent of the given JavaScript Number.
+
+Returns `napi_ok` if the API succeeded. If a non-number `napi_value`
+is passed in `napi_number_expected`.
+
+This API returns the C int32 primitive equivalent
+of the given JavaScript Number.
+
+If the number exceeds the range of the 32 bit integer, then the result is
+truncated to the equivalent of the bottom 32 bits. This can result in a large
+positive number becoming a negative number if the value is > 2^31 -1.
+
+Non-finite number values (NaN, positive infinity, or negative infinity) set the
+result to zero.
+
+#### napi_get_value_int64
+
+```C
+napi_status napi_get_value_int64(napi_env env,
+ napi_value value,
+ int64_t* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing JavaScript Number.
+- `[out] result`: C int64 primitive equivalent of the given JavaScript Number.
+
+Returns `napi_ok` if the API succeeded. If a non-number `napi_value`
+is passed in it returns `napi_number_expected`.
+
+This API returns the C int64 primitive equivalent of the given JavaScript
+Number.
+
+Number values outside the range of
+[`Number.MIN_SAFE_INTEGER`](https://tc39.github.io/ecma262/#sec-number.min_safe_integer)
+-(2^53 - 1) -
+[`Number.MAX_SAFE_INTEGER`](https://tc39.github.io/ecma262/#sec-number.max_safe_integer)
+(2^53 - 1) will lose precision.
+
+Non-finite number values (NaN, positive infinity, or negative infinity) set the
+result to zero.
+
+#### napi_get_value_string_latin1
+
+```C
+napi_status napi_get_value_string_latin1(napi_env env,
+ napi_value value,
+ char* buf,
+ size_t bufsize,
+ size_t* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing JavaScript string.
+- `[in] buf`: Buffer to write the ISO-8859-1-encoded string into. If NULL is
+passed in, the length of the string (in bytes) is returned.
+- `[in] bufsize`: Size of the destination buffer. When this value is
+insufficient, the returned string will be truncated.
+- `[out] result`: Number of bytes copied into the buffer, excluding the null
+terminator.
+
+Returns `napi_ok` if the API succeeded. If a non-String `napi_value`
+is passed in it returns `napi_string_expected`.
+
+This API returns the ISO-8859-1-encoded string corresponding the value passed
+in.
+
+#### napi_get_value_string_utf8
+
+```C
+napi_status napi_get_value_string_utf8(napi_env env,
+ napi_value value,
+ char* buf,
+ size_t bufsize,
+ size_t* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing JavaScript string.
+- `[in] buf`: Buffer to write the UTF8-encoded string into. If NULL is passed
+ in, the length of the string (in bytes) is returned.
+- `[in] bufsize`: Size of the destination buffer. When this value is
+insufficient, the returned string will be truncated.
+- `[out] result`: Number of bytes copied into the buffer, excluding the null
+terminator.
+
+Returns `napi_ok` if the API succeeded. If a non-String `napi_value`
+is passed in it returns `napi_string_expected`.
+
+This API returns the UTF8-encoded string corresponding the value passed in.
+
+#### napi_get_value_string_utf16
+
+```C
+napi_status napi_get_value_string_utf16(napi_env env,
+ napi_value value,
+ char16_t* buf,
+ size_t bufsize,
+ size_t* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing JavaScript string.
+- `[in] buf`: Buffer to write the UTF16-LE-encoded string into. If NULL is
+passed in, the length of the string (in 2-byte code units) is returned.
+- `[in] bufsize`: Size of the destination buffer. When this value is
+insufficient, the returned string will be truncated.
+- `[out] result`: Number of 2-byte code units copied into the buffer, excluding the null
+terminator.
+
+Returns `napi_ok` if the API succeeded. If a non-String `napi_value`
+is passed in it returns `napi_string_expected`.
+
+This API returns the UTF16-encoded string corresponding the value passed in.
+
+#### napi_get_value_uint32
+
+```C
+napi_status napi_get_value_uint32(napi_env env,
+ napi_value value,
+ uint32_t* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: `napi_value` representing JavaScript Number.
+- `[out] result`: C primitive equivalent of the given `napi_value` as a
+`uint32_t`.
+
+Returns `napi_ok` if the API succeeded. If a non-number `napi_value`
+is passed in it returns `napi_number_expected`.
+
+This API returns the C primitive equivalent of the given `napi_value` as a
+`uint32_t`.
+
+### Functions to get global instances
+#### napi_get_boolean
+
+```C
+napi_status napi_get_boolean(napi_env env, bool value, napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The value of the boolean to retrieve.
+- `[out] result`: `napi_value` representing JavaScript Boolean singleton to
+retrieve.
+
+Returns `napi_ok` if the API succeeded.
+
+This API is used to return the JavaScript singleton object that is used to
+represent the given boolean value
+
+#### napi_get_global
+
+```C
+napi_status napi_get_global(napi_env env, napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: `napi_value` representing JavaScript Global Object.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns the global Object.
+
+#### napi_get_null
+
+```C
+napi_status napi_get_null(napi_env env, napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: `napi_value` representing JavaScript Null Object.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns the null Object.
+
+#### napi_get_undefined
+
+```C
+napi_status napi_get_undefined(napi_env env, napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: `napi_value` representing JavaScript Undefined value.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns the Undefined object.
+
+## Working with JavaScript Values - Abstract Operations
+
+N-API exposes a set of APIs to perform some abstract operations on JavaScript
+values. Some of these operations are documented under
+[Section 7](https://tc39.github.io/ecma262/#sec-abstract-operations)
+of the [ECMAScript Language Specification](https://tc39.github.io/ecma262/).
+
+These APIs support doing one of the following:
+1. Coerce JavaScript values to specific JavaScript types (such as Number or
+ String)
+2. Check the type of a JavaScript value
+3. Check for equality between two JavaScript values
+
+### napi_coerce_to_bool
+
+```C
+napi_status napi_coerce_to_bool(napi_env env,
+ napi_value value,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to coerce.
+- `[out] result`: `napi_value` representing the coerced JavaScript Boolean.
+
+Returns `napi_ok` if the API succeeded.
+
+This API implements the abstract operation ToBoolean as defined in
+[Section 7.1.2](https://tc39.github.io/ecma262/#sec-toboolean)
+of the ECMAScript Language Specification.
+This API can be re-entrant if getters are defined on the passed-in Object.
+
+### napi_coerce_to_number
+
+```C
+napi_status napi_coerce_to_number(napi_env env,
+ napi_value value,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to coerce.
+- `[out] result`: `napi_value` representing the coerced JavaScript Number.
+
+Returns `napi_ok` if the API succeeded.
+
+This API implements the abstract operation ToNumber as defined in
+[Section 7.1.3](https://tc39.github.io/ecma262/#sec-tonumber)
+of the ECMAScript Language Specification.
+This API can be re-entrant if getters are defined on the passed-in Object.
+
+### napi_coerce_to_object
+
+```C
+napi_status napi_coerce_to_object(napi_env env,
+ napi_value value,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to coerce.
+- `[out] result`: `napi_value` representing the coerced JavaScript Object.
+
+Returns `napi_ok` if the API succeeded.
+
+This API implements the abstract operation ToObject as defined in
+[Section 7.1.13](https://tc39.github.io/ecma262/#sec-toobject)
+of the ECMAScript Language Specification.
+This API can be re-entrant if getters are defined on the passed-in Object.
+
+### napi_coerce_to_string
+
+```C
+napi_status napi_coerce_to_string(napi_env env,
+ napi_value value,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to coerce.
+- `[out] result`: `napi_value` representing the coerced JavaScript String.
+
+Returns `napi_ok` if the API succeeded.
+
+This API implements the abstract operation ToString as defined in
+[Section 7.1.13](https://tc39.github.io/ecma262/#sec-tostring)
+of the ECMAScript Language Specification.
+This API can be re-entrant if getters are defined on the passed-in Object.
+
+### napi_typeof
+
+```C
+napi_status napi_typeof(napi_env env, napi_value value, napi_valuetype* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value whose type to query.
+- `[out] result`: The type of the JavaScript value.
+
+Returns `napi_ok` if the API succeeded.
+- `napi_invalid_arg` if the type of `value` is not a known ECMAScript type and
+ `value` is not an External value.
+
+This API represents behavior similar to invoking the `typeof` Operator on
+the object as defined in [Section 12.5.5][] of the ECMAScript Language
+Specification. However, it has support for detecting an External value.
+If `value` has a type that is invalid, an error is returned.
+
+### napi_instanceof
+
+```C
+napi_status napi_instanceof(napi_env env,
+ napi_value object,
+ napi_value constructor,
+ bool* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] object`: The JavaScript value to check.
+- `[in] constructor`: The JavaScript function object of the constructor
+function to check against.
+- `[out] result`: Boolean that is set to true if `object instanceof constructor`
+is true.
+
+Returns `napi_ok` if the API succeeded.
+
+This API represents invoking the `instanceof` Operator on the object as
+defined in
+[Section 12.10.4](https://tc39.github.io/ecma262/#sec-instanceofoperator)
+of the ECMAScript Language Specification.
+
+### napi_is_array
+
+```C
+napi_status napi_is_array(napi_env env, napi_value value, bool* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to check.
+- `[out] result`: Whether the given object is an array.
+
+Returns `napi_ok` if the API succeeded.
+
+This API represents invoking the `IsArray` operation on the object
+as defined in [Section 7.2.2](https://tc39.github.io/ecma262/#sec-isarray)
+of the ECMAScript Language Specification.
+
+### napi_is_arraybuffer
+
+```C
+napi_status napi_is_arraybuffer(napi_env env, napi_value value, bool* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to check.
+- `[out] result`: Whether the given object is an ArrayBuffer.
+
+Returns `napi_ok` if the API succeeded.
+
+This API checks if the Object passed in is an array buffer.
+
+### napi_is_buffer
+
+```C
+napi_status napi_is_buffer(napi_env env, napi_value value, bool* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to check.
+- `[out] result`: Whether the given `napi_value` represents a `node::Buffer`
+object.
+
+Returns `napi_ok` if the API succeeded.
+
+This API checks if the Object passed in is a buffer.
+
+### napi_is_error
+
+```C
+napi_status napi_is_error(napi_env env, napi_value value, bool* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to check.
+- `[out] result`: Whether the given `napi_value` represents an Error object.
+
+Returns `napi_ok` if the API succeeded.
+
+This API checks if the Object passed in is an Error.
+
+### napi_is_typedarray
+
+```C
+napi_status napi_is_typedarray(napi_env env, napi_value value, bool* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to check.
+- `[out] result`: Whether the given `napi_value` represents a TypedArray.
+
+Returns `napi_ok` if the API succeeded.
+
+This API checks if the Object passed in is a typed array.
+
+### napi_is_dataview
+
+
+```C
+napi_status napi_is_dataview(napi_env env, napi_value value, bool* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] value`: The JavaScript value to check.
+- `[out] result`: Whether the given `napi_value` represents a DataView.
+
+Returns `napi_ok` if the API succeeded.
+
+This API checks if the Object passed in is a DataView.
+
+### napi_strict_equals
+
+```C
+napi_status napi_strict_equals(napi_env env,
+ napi_value lhs,
+ napi_value rhs,
+ bool* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] lhs`: The JavaScript value to check.
+- `[in] rhs`: The JavaScript value to check against.
+- `[out] result`: Whether the two `napi_value` objects are equal.
+
+Returns `napi_ok` if the API succeeded.
+
+This API represents the invocation of the Strict Equality algorithm as
+defined in
+[Section 7.2.14](https://tc39.github.io/ecma262/#sec-strict-equality-comparison)
+of the ECMAScript Language Specification.
+
+## Working with JavaScript Properties
+
+N-API exposes a set of APIs to get and set properties on JavaScript
+objects. Some of these types are documented under
+[Section 7](https://tc39.github.io/ecma262/#sec-operations-on-objects) of the
+[ECMAScript Language Specification](https://tc39.github.io/ecma262/).
+
+Properties in JavaScript are represented as a tuple of a key and a value.
+Fundamentally, all property keys in N-API can be represented in one of the
+following forms:
+- Named: a simple UTF8-encoded string
+- Integer-Indexed: an index value represented by `uint32_t`
+- JavaScript value: these are represented in N-API by `napi_value`. This can
+be a `napi_value` representing a String, Number or Symbol.
+
+N-API values are represented by the type `napi_value`.
+Any N-API call that requires a JavaScript value takes in a `napi_value`.
+However, it's the caller's responsibility to make sure that the
+`napi_value` in question is of the JavaScript type expected by the API.
+
+The APIs documented in this section provide a simple interface to
+get and set properties on arbitrary JavaScript objects represented by
+`napi_value`.
+
+For instance, consider the following JavaScript code snippet:
+```js
+const obj = {};
+obj.myProp = 123;
+```
+The equivalent can be done using N-API values with the following snippet:
+```C
+napi_status status = napi_generic_failure;
+
+// const obj = {}
+napi_value obj, value;
+status = napi_create_object(env, &obj);
+if (status != napi_ok) return status;
+
+// Create a napi_value for 123
+status = napi_create_int32(env, 123, &value);
+if (status != napi_ok) return status;
+
+// obj.myProp = 123
+status = napi_set_named_property(env, obj, "myProp", value);
+if (status != napi_ok) return status;
+```
+
+Indexed properties can be set in a similar manner. Consider the following
+JavaScript snippet:
+```js
+const arr = [];
+arr[123] = 'hello';
+```
+The equivalent can be done using N-API values with the following snippet:
+```C
+napi_status status = napi_generic_failure;
+
+// const arr = [];
+napi_value arr, value;
+status = napi_create_array(env, &arr);
+if (status != napi_ok) return status;
+
+// Create a napi_value for 'hello'
+status = napi_create_string_utf8(env, "hello", NAPI_AUTO_LENGTH, &value);
+if (status != napi_ok) return status;
+
+// arr[123] = 'hello';
+status = napi_set_element(env, arr, 123, value);
+if (status != napi_ok) return status;
+```
+
+Properties can be retrieved using the APIs described in this section.
+Consider the following JavaScript snippet:
+```js
+const arr = [];
+const value = arr[123];
+```
+
+The following is the approximate equivalent of the N-API counterpart:
+```C
+napi_status status = napi_generic_failure;
+
+// const arr = []
+napi_value arr, value;
+status = napi_create_array(env, &arr);
+if (status != napi_ok) return status;
+
+// const value = arr[123]
+status = napi_get_element(env, arr, 123, &value);
+if (status != napi_ok) return status;
+```
+
+Finally, multiple properties can also be defined on an object for performance
+reasons. Consider the following JavaScript:
+```js
+const obj = {};
+Object.defineProperties(obj, {
+ 'foo': { value: 123, writable: true, configurable: true, enumerable: true },
+ 'bar': { value: 456, writable: true, configurable: true, enumerable: true }
+});
+```
+
+The following is the approximate equivalent of the N-API counterpart:
+```C
+napi_status status = napi_status_generic_failure;
+
+// const obj = {};
+napi_value obj;
+status = napi_create_object(env, &obj);
+if (status != napi_ok) return status;
+
+// Create napi_values for 123 and 456
+napi_value fooValue, barValue;
+status = napi_create_int32(env, 123, &fooValue);
+if (status != napi_ok) return status;
+status = napi_create_int32(env, 456, &barValue);
+if (status != napi_ok) return status;
+
+// Set the properties
+napi_property_descriptor descriptors[] = {
+ { "foo", NULL, 0, 0, 0, fooValue, napi_default, 0 },
+ { "bar", NULL, 0, 0, 0, barValue, napi_default, 0 }
+}
+status = napi_define_properties(env,
+ obj,
+ sizeof(descriptors) / sizeof(descriptors[0]),
+ descriptors);
+if (status != napi_ok) return status;
+```
+
+### Structures
+#### napi_property_attributes
+```C
+typedef enum {
+ napi_default = 0,
+ napi_writable = 1 << 0,
+ napi_enumerable = 1 << 1,
+ napi_configurable = 1 << 2,
+
+ // Used with napi_define_class to distinguish static properties
+ // from instance properties. Ignored by napi_define_properties.
+ napi_static = 1 << 10,
+} napi_property_attributes;
+```
+
+`napi_property_attributes` are flags used to control the behavior of properties
+set on a JavaScript object. Other than `napi_static` they correspond to the
+attributes listed in [Section 6.1.7.1](https://tc39.github.io/ecma262/#table-2)
+of the [ECMAScript Language Specification](https://tc39.github.io/ecma262/).
+They can be one or more of the following bitflags:
+
+- `napi_default` - Used to indicate that no explicit attributes are set on the
+given property. By default, a property is read only, not enumerable and not
+configurable.
+- `napi_writable` - Used to indicate that a given property is writable.
+- `napi_enumerable` - Used to indicate that a given property is enumerable.
+- `napi_configurable` - Used to indicate that a given property is
+configurable, as defined in
+[Section 6.1.7.1](https://tc39.github.io/ecma262/#table-2) of the
+[ECMAScript Language Specification](https://tc39.github.io/ecma262/).
+- `napi_static` - Used to indicate that the property will be defined as
+a static property on a class as opposed to an instance property, which is the
+default. This is used only by [`napi_define_class`][]. It is ignored by
+`napi_define_properties`.
+
+#### napi_property_descriptor
+```C
+typedef struct {
+ // One of utf8name or name should be NULL.
+ const char* utf8name;
+ napi_value name;
+
+ napi_callback method;
+ napi_callback getter;
+ napi_callback setter;
+ napi_value value;
+
+ napi_property_attributes attributes;
+ void* data;
+} napi_property_descriptor;
+```
+
+- `utf8name`: Optional String describing the key for the property,
+encoded as UTF8. One of `utf8name` or `name` must be provided for the
+property.
+- `name`: Optional napi_value that points to a JavaScript string or symbol
+to be used as the key for the property. One of `utf8name` or `name` must
+be provided for the property.
+- `value`: The value that's retrieved by a get access of the property if the
+ property is a data property. If this is passed in, set `getter`, `setter`,
+ `method` and `data` to `NULL` (since these members won't be used).
+- `getter`: A function to call when a get access of the property is performed.
+If this is passed in, set `value` and `method` to `NULL` (since these members
+won't be used). The given function is called implicitly by the runtime when the
+property is accessed from JavaScript code (or if a get on the property is
+performed using a N-API call).
+- `setter`: A function to call when a set access of the property is performed.
+If this is passed in, set `value` and `method` to `NULL` (since these members
+won't be used). The given function is called implicitly by the runtime when the
+property is set from JavaScript code (or if a set on the property is
+performed using a N-API call).
+- `method`: Set this to make the property descriptor object's `value`
+property to be a JavaScript function represented by `method`. If this is
+passed in, set `value`, `getter` and `setter` to `NULL` (since these members
+won't be used).
+- `data`: The callback data passed into `method`, `getter` and `setter` if
+this function is invoked.
+- `attributes`: The attributes associated with the particular property.
+See [`napi_property_attributes`](#napi_property_attributes).
+
+### Functions
+#### napi_get_property_names
+
+```C
+napi_status napi_get_property_names(napi_env env,
+ napi_value object,
+ napi_value* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object from which to retrieve the properties.
+- `[out] result`: A `napi_value` representing an array of JavaScript values
+that represent the property names of the object. The API can be used to
+iterate over `result` using [`napi_get_array_length`][]
+and [`napi_get_element`][].
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns the array of properties for the Object passed in
+
+#### napi_set_property
+
+```C
+napi_status napi_set_property(napi_env env,
+ napi_value object,
+ napi_value key,
+ napi_value value);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object on which to set the property.
+- `[in] key`: The name of the property to set.
+- `[in] value`: The property value.
+
+Returns `napi_ok` if the API succeeded.
+
+This API set a property on the Object passed in.
+
+#### napi_get_property
+
+```C
+napi_status napi_get_property(napi_env env,
+ napi_value object,
+ napi_value key,
+ napi_value* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object from which to retrieve the property.
+- `[in] key`: The name of the property to retrieve.
+- `[out] result`: The value of the property.
+
+Returns `napi_ok` if the API succeeded.
+
+This API gets the requested property from the Object passed in.
+
+
+#### napi_has_property
+
+```C
+napi_status napi_has_property(napi_env env,
+ napi_value object,
+ napi_value key,
+ bool* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object to query.
+- `[in] key`: The name of the property whose existence to check.
+- `[out] result`: Whether the property exists on the object or not.
+
+Returns `napi_ok` if the API succeeded.
+
+This API checks if the Object passed in has the named property.
+
+
+#### napi_delete_property
+
+```C
+napi_status napi_delete_property(napi_env env,
+ napi_value object,
+ napi_value key,
+ bool* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object to query.
+- `[in] key`: The name of the property to delete.
+- `[out] result`: Whether the property deletion succeeded or not. `result` can
+optionally be ignored by passing `NULL`.
+
+Returns `napi_ok` if the API succeeded.
+
+This API attempts to delete the `key` own property from `object`.
+
+
+#### napi_has_own_property
+
+```C
+napi_status napi_has_own_property(napi_env env,
+ napi_value object,
+ napi_value key,
+ bool* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object to query.
+- `[in] key`: The name of the own property whose existence to check.
+- `[out] result`: Whether the own property exists on the object or not.
+
+Returns `napi_ok` if the API succeeded.
+
+This API checks if the Object passed in has the named own property. `key` must
+be a string or a Symbol, or an error will be thrown. N-API will not perform any
+conversion between data types.
+
+
+#### napi_set_named_property
+
+```C
+napi_status napi_set_named_property(napi_env env,
+ napi_value object,
+ const char* utf8Name,
+ napi_value value);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object on which to set the property.
+- `[in] utf8Name`: The name of the property to set.
+- `[in] value`: The property value.
+
+Returns `napi_ok` if the API succeeded.
+
+This method is equivalent to calling [`napi_set_property`][] with a `napi_value`
+created from the string passed in as `utf8Name`
+
+#### napi_get_named_property
+
+```C
+napi_status napi_get_named_property(napi_env env,
+ napi_value object,
+ const char* utf8Name,
+ napi_value* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object from which to retrieve the property.
+- `[in] utf8Name`: The name of the property to get.
+- `[out] result`: The value of the property.
+
+Returns `napi_ok` if the API succeeded.
+
+This method is equivalent to calling [`napi_get_property`][] with a `napi_value`
+created from the string passed in as `utf8Name`
+
+#### napi_has_named_property
+
+```C
+napi_status napi_has_named_property(napi_env env,
+ napi_value object,
+ const char* utf8Name,
+ bool* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object to query.
+- `[in] utf8Name`: The name of the property whose existence to check.
+- `[out] result`: Whether the property exists on the object or not.
+
+Returns `napi_ok` if the API succeeded.
+
+This method is equivalent to calling [`napi_has_property`][] with a `napi_value`
+created from the string passed in as `utf8Name`
+
+#### napi_set_element
+
+```C
+napi_status napi_set_element(napi_env env,
+ napi_value object,
+ uint32_t index,
+ napi_value value);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object from which to set the properties.
+- `[in] index`: The index of the property to set.
+- `[in] value`: The property value.
+
+Returns `napi_ok` if the API succeeded.
+
+This API sets and element on the Object passed in.
+
+#### napi_get_element
+
+```C
+napi_status napi_get_element(napi_env env,
+ napi_value object,
+ uint32_t index,
+ napi_value* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object from which to retrieve the property.
+- `[in] index`: The index of the property to get.
+- `[out] result`: The value of the property.
+
+Returns `napi_ok` if the API succeeded.
+
+This API gets the element at the requested index.
+
+#### napi_has_element
+
+```C
+napi_status napi_has_element(napi_env env,
+ napi_value object,
+ uint32_t index,
+ bool* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object to query.
+- `[in] index`: The index of the property whose existence to check.
+- `[out] result`: Whether the property exists on the object or not.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns if the Object passed in has an element at the
+requested index.
+
+#### napi_delete_element
+
+```C
+napi_status napi_delete_element(napi_env env,
+ napi_value object,
+ uint32_t index,
+ bool* result);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object to query.
+- `[in] index`: The index of the property to delete.
+- `[out] result`: Whether the element deletion succeeded or not. `result` can
+optionally be ignored by passing `NULL`.
+
+Returns `napi_ok` if the API succeeded.
+
+This API attempts to delete the specified `index` from `object`.
+
+#### napi_define_properties
+
+```C
+napi_status napi_define_properties(napi_env env,
+ napi_value object,
+ size_t property_count,
+ const napi_property_descriptor* properties);
+```
+
+- `[in] env`: The environment that the N-API call is invoked under.
+- `[in] object`: The object from which to retrieve the properties.
+- `[in] property_count`: The number of elements in the `properties` array.
+- `[in] properties`: The array of property descriptors.
+
+Returns `napi_ok` if the API succeeded.
+
+This method allows the efficient definition of multiple properties on a given
+object. The properties are defined using property descriptors (See
+[`napi_property_descriptor`][]). Given an array of such property descriptors, this
+API will set the properties on the object one at a time, as defined by
+DefineOwnProperty (described in [Section 9.1.6][] of the ECMA262 specification).
+
+## Working with JavaScript Functions
+
+N-API provides a set of APIs that allow JavaScript code to
+call back into native code. N-API APIs that support calling back
+into native code take in a callback functions represented by
+the `napi_callback` type. When the JavaScript VM calls back to
+native code, the `napi_callback` function provided is invoked. The APIs
+documented in this section allow the callback function to do the
+following:
+- Get information about the context in which the callback was invoked.
+- Get the arguments passed into the callback.
+- Return a `napi_value` back from the callback.
+
+Additionally, N-API provides a set of functions which allow calling
+JavaScript functions from native code. One can either call a function
+like a regular JavaScript function call, or as a constructor
+function.
+
+
+### napi_call_function
+
+```C
+napi_status napi_call_function(napi_env env,
+ napi_value recv,
+ napi_value func,
+ int argc,
+ const napi_value* argv,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] recv`: The `this` object passed to the called function.
+- `[in] func`: `napi_value` representing the JavaScript function
+to be invoked.
+- `[in] argc`: The count of elements in the `argv` array.
+- `[in] argv`: Array of `napi_values` representing JavaScript values passed
+in as arguments to the function.
+- `[out] result`: `napi_value` representing the JavaScript object returned.
+
+Returns `napi_ok` if the API succeeded.
+
+This method allows a JavaScript function object to be called from a native
+add-on. This is the primary mechanism of calling back *from* the add-on's
+native code *into* JavaScript. For the special case of calling into JavaScript
+after an async operation, see [`napi_make_callback`][].
+
+A sample use case might look as follows. Consider the following JavaScript
+snippet:
+```js
+function AddTwo(num) {
+ return num + 2;
+}
+```
+
+Then, the above function can be invoked from a native add-on using the
+following code:
+```C
+// Get the function named "AddTwo" on the global object
+napi_value global, add_two, arg;
+napi_status status = napi_get_global(env, &global);
+if (status != napi_ok) return;
+
+status = napi_get_named_property(env, global, "AddTwo", &add_two);
+if (status != napi_ok) return;
+
+// const arg = 1337
+status = napi_create_int32(env, 1337, &arg);
+if (status != napi_ok) return;
+
+napi_value* argv = &arg;
+size_t argc = 1;
+
+// AddTwo(arg);
+napi_value return_val;
+status = napi_call_function(env, global, add_two, argc, argv, &return_val);
+if (status != napi_ok) return;
+
+// Convert the result back to a native type
+int32_t result;
+status = napi_get_value_int32(env, return_val, &result);
+if (status != napi_ok) return;
+```
+
+### napi_create_function
+
+```C
+napi_status napi_create_function(napi_env env,
+ const char* utf8name,
+ napi_callback cb,
+ void* data,
+ napi_value* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] utf8Name`: The name of the function encoded as UTF8. This is visible
+within JavaScript as the new function object's `name` property.
+- `[in] cb`: The native function which should be called when this function
+object is invoked.
+- `[in] data`: User-provided data context. This will be passed back into the
+function when invoked later.
+- `[out] result`: `napi_value` representing the JavaScript function object for
+the newly created function.
+
+Returns `napi_ok` if the API succeeded.
+
+This API allows an add-on author to create a function object in native code.
+This is the primary mechanism to allow calling *into* the add-on's native code
+*from* JavaScript.
+
+**Note:** The newly created function is not automatically visible from
+script after this call. Instead, a property must be explicitly set on any
+object that is visible to JavaScript, in order for the function to be accessible
+from script.
+
+In order to expose a function as part of the
+add-on's module exports, set the newly created function on the exports
+object. A sample module might look as follows:
+```C
+napi_value SayHello(napi_env env, napi_callback_info info) {
+ printf("Hello\n");
+ return NULL;
+}
+
+napi_value Init(napi_env env, napi_value exports) {
+ napi_status status;
+
+ napi_value fn;
+ status = napi_create_function(env, NULL, 0, SayHello, NULL, &fn);
+ if (status != napi_ok) return NULL;
+
+ status = napi_set_named_property(env, exports, "sayHello", fn);
+ if (status != napi_ok) return NULL;
+
+ return exports;
+}
+
+NAPI_MODULE(addon, Init)
+```
+
+Given the above code, the add-on can be used from JavaScript as follows:
+```js
+const myaddon = require('./addon');
+myaddon.sayHello();
+```
+
+**Note:** The string passed to require is not necessarily the name passed into
+`NAPI_MODULE` in the earlier snippet but the name of the target in `binding.gyp`
+responsible for creating the `.node` file.
+
+### napi_get_cb_info
+
+```C
+napi_status napi_get_cb_info(napi_env env,
+ napi_callback_info cbinfo,
+ size_t* argc,
+ napi_value* argv,
+ napi_value* thisArg,
+ void** data)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] cbinfo`: The callback info passed into the callback function.
+- `[in-out] argc`: Specifies the size of the provided `argv` array
+and receives the actual count of arguments.
+- `[out] argv`: Buffer to which the `napi_value` representing the
+arguments are copied. If there are more arguments than the provided
+count, only the requested number of arguments are copied. If there are fewer
+arguments provided than claimed, the rest of `argv` is filled with `napi_value`
+values that represent `undefined`.
+- `[out] this`: Receives the JavaScript `this` argument for the call.
+- `[out] data`: Receives the data pointer for the callback.
+
+Returns `napi_ok` if the API succeeded.
+
+This method is used within a callback function to retrieve details about the
+call like the arguments and the `this` pointer from a given callback info.
+
+### napi_get_new_target
+
+```C
+napi_status napi_get_new_target(napi_env env,
+ napi_callback_info cbinfo,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] cbinfo`: The callback info passed into the callback function.
+- `[out] result`: The `new.target` of the constructor call.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns the `new.target` of the constructor call. If the current
+callback is not a constructor call, the result is `NULL`.
+
+### napi_new_instance
+
+```C
+napi_status napi_new_instance(napi_env env,
+ napi_value cons,
+ size_t argc,
+ napi_value* argv,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] cons`: `napi_value` representing the JavaScript function
+to be invoked as a constructor.
+- `[in] argc`: The count of elements in the `argv` array.
+- `[in] argv`: Array of JavaScript values as `napi_value`
+representing the arguments to the constructor.
+- `[out] result`: `napi_value` representing the JavaScript object returned,
+which in this case is the constructed object.
+
+This method is used to instantiate a new JavaScript value using a given
+`napi_value` that represents the constructor for the object. For example,
+consider the following snippet:
+```js
+function MyObject(param) {
+ this.param = param;
+}
+
+const arg = 'hello';
+const value = new MyObject(arg);
+```
+
+The following can be approximated in N-API using the following snippet:
+```C
+// Get the constructor function MyObject
+napi_value global, constructor, arg, value;
+napi_status status = napi_get_global(env, &global);
+if (status != napi_ok) return;
+
+status = napi_get_named_property(env, global, "MyObject", &constructor);
+if (status != napi_ok) return;
+
+// const arg = "hello"
+status = napi_create_string_utf8(env, "hello", NAPI_AUTO_LENGTH, &arg);
+if (status != napi_ok) return;
+
+napi_value* argv = &arg;
+size_t argc = 1;
+
+// const value = new MyObject(arg)
+status = napi_new_instance(env, constructor, argc, argv, &value);
+```
+
+Returns `napi_ok` if the API succeeded.
+
+## Object Wrap
+
+N-API offers a way to "wrap" C++ classes and instances so that the class
+constructor and methods can be called from JavaScript.
+
+ 1. The [`napi_define_class`][] API defines a JavaScript class with constructor,
+ static properties and methods, and instance properties and methods that
+ correspond to the C++ class.
+ 2. When JavaScript code invokes the constructor, the constructor callback
+ uses [`napi_wrap`][] to wrap a new C++ instance in a JavaScript object,
+ then returns the wrapper object.
+ 3. When JavaScript code invokes a method or property accessor on the class,
+ the corresponding `napi_callback` C++ function is invoked. For an instance
+ callback, [`napi_unwrap`][] obtains the C++ instance that is the target of
+ the call.
+
+For wrapped objects it may be difficult to distinguish between a function
+called on a class prototype and a function called on an instance of a class.
+A common pattern used to address this problem is to save a persistent
+reference to the class constructor for later `instanceof` checks.
+
+As an example:
+
+```C
+napi_value MyClass_constructor = NULL;
+status = napi_get_reference_value(env, MyClass::es_constructor, &MyClass_constructor);
+assert(napi_ok == status);
+bool is_instance = false;
+status = napi_instanceof(env, es_this, MyClass_constructor, &is_instance);
+assert(napi_ok == status);
+if (is_instance) {
+ // napi_unwrap() ...
+} else {
+ // otherwise...
+}
+```
+
+The reference must be freed once it is no longer needed.
+
+### napi_define_class
+
+```C
+napi_status napi_define_class(napi_env env,
+ const char* utf8name,
+ size_t length,
+ napi_callback constructor,
+ void* data,
+ size_t property_count,
+ const napi_property_descriptor* properties,
+ napi_value* result);
+```
+
+ - `[in] env`: The environment that the API is invoked under.
+ - `[in] utf8name`: Name of the JavaScript constructor function; this is
+ not required to be the same as the C++ class name, though it is recommended
+ for clarity.
+ - `[in] length`: The length of the utf8name in bytes, or `NAPI_AUTO_LENGTH`
+if it is null-terminated.
+ - `[in] constructor`: Callback function that handles constructing instances
+ of the class. (This should be a static method on the class, not an actual
+ C++ constructor function.)
+ - `[in] data`: Optional data to be passed to the constructor callback as
+ the `data` property of the callback info.
+ - `[in] property_count`: Number of items in the `properties` array argument.
+ - `[in] properties`: Array of property descriptors describing static and
+ instance data properties, accessors, and methods on the class
+ See `napi_property_descriptor`.
+ - `[out] result`: A `napi_value` representing the constructor function for
+ the class.
+
+Returns `napi_ok` if the API succeeded.
+
+Defines a JavaScript class that corresponds to a C++ class, including:
+ - A JavaScript constructor function that has the class name and invokes the
+ provided C++ constructor callback.
+ - Properties on the constructor function corresponding to _static_ data
+ properties, accessors, and methods of the C++ class (defined by
+ property descriptors with the `napi_static` attribute).
+ - Properties on the constructor function's `prototype` object corresponding to
+ _non-static_ data properties, accessors, and methods of the C++ class
+ (defined by property descriptors without the `napi_static` attribute).
+
+The C++ constructor callback should be a static method on the class that calls
+the actual class constructor, then wraps the new C++ instance in a JavaScript
+object, and returns the wrapper object. See `napi_wrap()` for details.
+
+The JavaScript constructor function returned from [`napi_define_class`][] is
+often saved and used later, to construct new instances of the class from native
+code, and/or check whether provided values are instances of the class. In that
+case, to prevent the function value from being garbage-collected, create a
+persistent reference to it using [`napi_create_reference`][] and ensure the
+reference count is kept >= 1.
+
+### napi_wrap
+
+```C
+napi_status napi_wrap(napi_env env,
+ napi_value js_object,
+ void* native_object,
+ napi_finalize finalize_cb,
+ void* finalize_hint,
+ napi_ref* result);
+```
+
+ - `[in] env`: The environment that the API is invoked under.
+ - `[in] js_object`: The JavaScript object that will be the wrapper for the
+ native object. This object _must_ have been created from the `prototype` of
+ a constructor that was created using `napi_define_class()`.
+ - `[in] native_object`: The native instance that will be wrapped in the
+ JavaScript object.
+ - `[in] finalize_cb`: Optional native callback that can be used to free the
+ native instance when the JavaScript object is ready for garbage-collection.
+ - `[in] finalize_hint`: Optional contextual hint that is passed to the
+ finalize callback.
+ - `[out] result`: Optional reference to the wrapped object.
+
+Returns `napi_ok` if the API succeeded.
+
+Wraps a native instance in a JavaScript object. The native instance can be
+retrieved later using `napi_unwrap()`.
+
+When JavaScript code invokes a constructor for a class that was defined using
+`napi_define_class()`, the `napi_callback` for the constructor is invoked.
+After constructing an instance of the native class, the callback must then call
+`napi_wrap()` to wrap the newly constructed instance in the already-created
+JavaScript object that is the `this` argument to the constructor callback.
+(That `this` object was created from the constructor function's `prototype`,
+so it already has definitions of all the instance properties and methods.)
+
+Typically when wrapping a class instance, a finalize callback should be
+provided that simply deletes the native instance that is received as the `data`
+argument to the finalize callback.
+
+The optional returned reference is initially a weak reference, meaning it
+has a reference count of 0. Typically this reference count would be incremented
+temporarily during async operations that require the instance to remain valid.
+
+*Caution*: The optional returned reference (if obtained) should be deleted via
+[`napi_delete_reference`][] ONLY in response to the finalize callback
+invocation. (If it is deleted before then, then the finalize callback may never
+be invoked.) Therefore, when obtaining a reference a finalize callback is also
+required in order to enable correct proper of the reference.
+
+*Note*: This API may modify the prototype chain of the wrapper object.
+Afterward, additional manipulation of the wrapper's prototype chain may cause
+`napi_unwrap()` to fail.
+
+Calling napi_wrap() a second time on an object will return an error. To associate
+another native instance with the object, use napi_remove_wrap() first.
+
+### napi_unwrap
+
+```C
+napi_status napi_unwrap(napi_env env,
+ napi_value js_object,
+ void** result);
+```
+
+ - `[in] env`: The environment that the API is invoked under.
+ - `[in] js_object`: The object associated with the native instance.
+ - `[out] result`: Pointer to the wrapped native instance.
+
+Returns `napi_ok` if the API succeeded.
+
+Retrieves a native instance that was previously wrapped in a JavaScript
+object using `napi_wrap()`.
+
+When JavaScript code invokes a method or property accessor on the class, the
+corresponding `napi_callback` is invoked. If the callback is for an instance
+method or accessor, then the `this` argument to the callback is the wrapper
+object; the wrapped C++ instance that is the target of the call can be obtained
+then by calling `napi_unwrap()` on the wrapper object.
+
+### napi_remove_wrap
+
+```C
+napi_status napi_remove_wrap(napi_env env,
+ napi_value js_object,
+ void** result);
+```
+
+ - `[in] env`: The environment that the API is invoked under.
+ - `[in] js_object`: The object associated with the native instance.
+ - `[out] result`: Pointer to the wrapped native instance.
+
+Returns `napi_ok` if the API succeeded.
+
+Retrieves a native instance that was previously wrapped in the JavaScript
+object `js_object` using `napi_wrap()` and removes the wrapping, thereby
+restoring the JavaScript object's prototype chain. If a finalize callback was
+associated with the wrapping, it will no longer be called when the JavaScript
+object becomes garbage-collected.
+
+## Simple Asynchronous Operations
+
+Addon modules often need to leverage async helpers from libuv as part of their
+implementation. This allows them to schedule work to be executed asynchronously
+so that their methods can return in advance of the work being completed. This
+is important in order to allow them to avoid blocking overall execution
+of the Node.js application.
+
+N-API provides an ABI-stable interface for these
+supporting functions which covers the most common asynchronous use cases.
+
+N-API defines the `napi_work` structure which is used to manage
+asynchronous workers. Instances are created/deleted with
+[`napi_create_async_work`][] and [`napi_delete_async_work`][].
+
+The `execute` and `complete` callbacks are functions that will be
+invoked when the executor is ready to execute and when it completes its
+task respectively. These functions implement the following interfaces:
+
+```C
+typedef void (*napi_async_execute_callback)(napi_env env,
+ void* data);
+typedef void (*napi_async_complete_callback)(napi_env env,
+ napi_status status,
+ void* data);
+```
+
+
+When these methods are invoked, the `data` parameter passed will be the
+addon-provided void* data that was passed into the
+`napi_create_async_work` call.
+
+Once created the async worker can be queued
+for execution using the [`napi_queue_async_work`][] function:
+
+```C
+napi_status napi_queue_async_work(napi_env env,
+ napi_async_work work);
+```
+
+[`napi_cancel_async_work`][] can be used if the work needs
+to be cancelled before the work has started execution.
+
+After calling [`napi_cancel_async_work`][], the `complete` callback
+will be invoked with a status value of `napi_cancelled`.
+The work should not be deleted before the `complete`
+callback invocation, even when it was cancelled.
+
+### napi_create_async_work
+
+```C
+napi_status napi_create_async_work(napi_env env,
+ napi_value async_resource,
+ napi_value async_resource_name,
+ napi_async_execute_callback execute,
+ napi_async_complete_callback complete,
+ void* data,
+ napi_async_work* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] async_resource`: An optional object associated with the async work
+ that will be passed to possible async_hooks [`init` hooks][].
+- `[in] async_resource_name`: Identifier for the kind of resource that is
+being provided for diagnostic information exposed by the `async_hooks` API.
+- `[in] execute`: The native function which should be called to execute
+the logic asynchronously. The given function is called from a worker pool
+thread and can execute in parallel with the main event loop thread.
+- `[in] complete`: The native function which will be called when the
+asynchronous logic is completed or is cancelled. The given function is called
+from the main event loop thread.
+- `[in] data`: User-provided data context. This will be passed back into the
+execute and complete functions.
+- `[out] result`: `napi_async_work*` which is the handle to the newly created
+async work.
+
+Returns `napi_ok` if the API succeeded.
+
+This API allocates a work object that is used to execute logic asynchronously.
+It should be freed using [`napi_delete_async_work`][] once the work is no longer
+required.
+
+`async_resource_name` should be a null-terminated, UTF-8-encoded string.
+
+*Note*: The `async_resource_name` identifier is provided by the user and should
+be representative of the type of async work being performed. It is also
+recommended to apply namespacing to the identifier, e.g. by including the
+module name. See the [`async_hooks` documentation][async_hooks `type`]
+for more information.
+
+### napi_delete_async_work
+
+```C
+napi_status napi_delete_async_work(napi_env env,
+ napi_async_work work);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] work`: The handle returned by the call to `napi_create_async_work`.
+
+Returns `napi_ok` if the API succeeded.
+
+This API frees a previously allocated work object.
+
+This API can be called even if there is a pending JavaScript exception.
+
+### napi_queue_async_work
+
+```C
+napi_status napi_queue_async_work(napi_env env,
+ napi_async_work work);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] work`: The handle returned by the call to `napi_create_async_work`.
+
+Returns `napi_ok` if the API succeeded.
+
+This API requests that the previously allocated work be scheduled
+for execution.
+
+### napi_cancel_async_work
+
+```C
+napi_status napi_cancel_async_work(napi_env env,
+ napi_async_work work);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] work`: The handle returned by the call to `napi_create_async_work`.
+
+Returns `napi_ok` if the API succeeded.
+
+This API cancels queued work if it has not yet
+been started. If it has already started executing, it cannot be
+cancelled and `napi_generic_failure` will be returned. If successful,
+the `complete` callback will be invoked with a status value of
+`napi_cancelled`. The work should not be deleted before the `complete`
+callback invocation, even if it has been successfully cancelled.
+
+This API can be called even if there is a pending JavaScript exception.
+
+## Custom Asynchronous Operations
+The simple asynchronous work APIs above may not be appropriate for every
+scenario. When using any other asynchronous mechanism, the following APIs
+are necessary to ensure an asynchronous operation is properly tracked by
+the runtime.
+
+### napi_async_init
+
+```C
+napi_status napi_async_init(napi_env env,
+ napi_value async_resource,
+ napi_value async_resource_name,
+ napi_async_context* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] async_resource`: An optional object associated with the async work
+ that will be passed to possible `async_hooks` [`init` hooks][].
+- `[in] async_resource_name`: Identifier for the kind of resource
+ that is being provided for diagnostic information exposed by the
+ `async_hooks` API.
+- `[out] result`: The initialized async context.
+
+Returns `napi_ok` if the API succeeded.
+
+### napi_async_destroy
+
+```C
+napi_status napi_async_destroy(napi_env env,
+ napi_async_context async_context);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] async_context`: The async context to be destroyed.
+
+Returns `napi_ok` if the API succeeded.
+
+This API can be called even if there is a pending JavaScript exception.
+
+### napi_make_callback
+
+```C
+napi_status napi_make_callback(napi_env env,
+ napi_async_context async_context,
+ napi_value recv,
+ napi_value func,
+ int argc,
+ const napi_value* argv,
+ napi_value* result)
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] async_context`: Context for the async operation that is
+ invoking the callback. This should normally be a value previously
+ obtained from [`napi_async_init`][]. However `NULL` is also allowed,
+ which indicates the current async context (if any) is to be used
+ for the callback.
+- `[in] recv`: The `this` object passed to the called function.
+- `[in] func`: `napi_value` representing the JavaScript function
+to be invoked.
+- `[in] argc`: The count of elements in the `argv` array.
+- `[in] argv`: Array of JavaScript values as `napi_value`
+representing the arguments to the function.
+- `[out] result`: `napi_value` representing the JavaScript object returned.
+
+Returns `napi_ok` if the API succeeded.
+
+This method allows a JavaScript function object to be called from a native
+add-on. This API is similar to `napi_call_function`. However, it is used to call
+*from* native code back *into* JavaScript *after* returning from an async
+operation (when there is no other script on the stack). It is a fairly simple
+wrapper around `node::MakeCallback`.
+
+Note it is *not* necessary to use `napi_make_callback` from within a
+`napi_async_complete_callback`; in that situation the callback's async
+context has already been set up, so a direct call to `napi_call_function`
+is sufficient and appropriate. Use of the `napi_make_callback` function
+may be required when implementing custom async behavior that does not use
+`napi_create_async_work`.
+
+### *napi_open_callback_scope*
+
+```C
+NAPI_EXTERN napi_status napi_open_callback_scope(napi_env env,
+ napi_value resource_object,
+ napi_async_context context,
+ napi_callback_scope* result)
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] resource_object`: An optional object associated with the async work
+ that will be passed to possible async_hooks [`init` hooks][].
+- `[in] context`: Context for the async operation that is
+invoking the callback. This should be a value previously obtained
+from [`napi_async_init`][].
+- `[out] result`: The newly created scope.
+
+There are cases (for example resolving promises) where it is
+necessary to have the equivalent of the scope associated with a callback
+in place when making certain N-API calls. If there is no other script on
+the stack the [`napi_open_callback_scope`][] and
+[`napi_close_callback_scope`][] functions can be used to open/close
+the required scope.
+
+### *napi_close_callback_scope*
+
+```C
+NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env,
+ napi_callback_scope scope)
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] scope`: The scope to be closed.
+
+This API can be called even if there is a pending JavaScript exception.
+
+## Version Management
+
+### napi_get_node_version
+
+
+```C
+typedef struct {
+ uint32_t major;
+ uint32_t minor;
+ uint32_t patch;
+ const char* release;
+} napi_node_version;
+
+napi_status napi_get_node_version(napi_env env,
+ const napi_node_version** version);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] version`: A pointer to version information for Node itself.
+
+Returns `napi_ok` if the API succeeded.
+
+This function fills the `version` struct with the major, minor and patch version
+of Node that is currently running, and the `release` field with the
+value of [`process.release.name`][`process.release`].
+
+The returned buffer is statically allocated and does not need to be freed.
+
+### napi_get_version
+
+```C
+napi_status napi_get_version(napi_env env,
+ uint32_t* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] result`: The highest version of N-API supported.
+
+Returns `napi_ok` if the API succeeded.
+
+This API returns the highest N-API version supported by the
+Node.js runtime. N-API is planned to be additive such that
+newer releases of Node.js may support additional API functions.
+In order to allow an addon to use a newer function when running with
+versions of Node.js that support it, while providing
+fallback behavior when running with Node.js versions that don't
+support it:
+
+* Call `napi_get_version()` to determine if the API is available.
+* If available, dynamically load a pointer to the function using `uv_dlsym()`.
+* Use the dynamically loaded pointer to invoke the function.
+* If the function is not available, provide an alternate implementation
+ that does not use the function.
+
+## Memory Management
+
+### napi_adjust_external_memory
+
+```C
+NAPI_EXTERN napi_status napi_adjust_external_memory(napi_env env,
+ int64_t change_in_bytes,
+ int64_t* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] change_in_bytes`: The change in externally allocated memory that is
+kept alive by JavaScript objects.
+- `[out] result`: The adjusted value
+
+Returns `napi_ok` if the API succeeded.
+
+This function gives V8 an indication of the amount of externally allocated
+memory that is kept alive by JavaScript objects (i.e. a JavaScript object
+that points to its own memory allocated by a native module). Registering
+externally allocated memory will trigger global garbage collections more
+often than it would otherwise.
+
+
+
+## Promises
+
+N-API provides facilities for creating `Promise` objects as described in
+[Section 25.4][] of the ECMA specification. It implements promises as a pair of
+objects. When a promise is created by `napi_create_promise()`, a "deferred"
+object is created and returned alongside the `Promise`. The deferred object is
+bound to the created `Promise` and is the only means to resolve or reject the
+`Promise` using `napi_resolve_deferred()` or `napi_reject_deferred()`. The
+deferred object that is created by `napi_create_promise()` is freed by
+`napi_resolve_deferred()` or `napi_reject_deferred()`. The `Promise` object may
+be returned to JavaScript where it can be used in the usual fashion.
+
+For example, to create a promise and pass it to an asynchronous worker:
+```c
+napi_deferred deferred;
+napi_value promise;
+napi_status status;
+
+// Create the promise.
+status = napi_create_promise(env, &deferred, &promise);
+if (status != napi_ok) return NULL;
+
+// Pass the deferred to a function that performs an asynchronous action.
+do_something_asynchronous(deferred);
+
+// Return the promise to JS
+return promise;
+```
+
+The above function `do_something_asynchronous()` would perform its asynchronous
+action and then it would resolve or reject the deferred, thereby concluding the
+promise and freeing the deferred:
+```c
+napi_deferred deferred;
+napi_value undefined;
+napi_status status;
+
+// Create a value with which to conclude the deferred.
+status = napi_get_undefined(env, &undefined);
+if (status != napi_ok) return NULL;
+
+// Resolve or reject the promise associated with the deferred depending on
+// whether the asynchronous action succeeded.
+if (asynchronous_action_succeeded) {
+ status = napi_resolve_deferred(env, deferred, undefined);
+} else {
+ status = napi_reject_deferred(env, deferred, undefined);
+}
+if (status != napi_ok) return NULL;
+
+// At this point the deferred has been freed, so we should assign NULL to it.
+deferred = NULL;
+```
+
+### napi_create_promise
+
+```C
+napi_status napi_create_promise(napi_env env,
+ napi_deferred* deferred,
+ napi_value* promise);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] deferred`: A newly created deferred object which can later be passed to
+`napi_resolve_deferred()` or `napi_reject_deferred()` to resolve resp. reject
+the associated promise.
+- `[out] promise`: The JavaScript promise associated with the deferred object.
+
+Returns `napi_ok` if the API succeeded.
+
+This API creates a deferred object and a JavaScript promise.
+
+### napi_resolve_deferred
+
+```C
+napi_status napi_resolve_deferred(napi_env env,
+ napi_deferred deferred,
+ napi_value resolution);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] deferred`: The deferred object whose associated promise to resolve.
+- `[in] resolution`: The value with which to resolve the promise.
+
+This API resolves a JavaScript promise by way of the deferred object
+with which it is associated. Thus, it can only be used to resolve JavaScript
+promises for which the corresponding deferred object is available. This
+effectively means that the promise must have been created using
+`napi_create_promise()` and the deferred object returned from that call must
+have been retained in order to be passed to this API.
+
+The deferred object is freed upon successful completion.
+
+### napi_reject_deferred
+
+```C
+napi_status napi_reject_deferred(napi_env env,
+ napi_deferred deferred,
+ napi_value rejection);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] deferred`: The deferred object whose associated promise to resolve.
+- `[in] rejection`: The value with which to reject the promise.
+
+This API rejects a JavaScript promise by way of the deferred object
+with which it is associated. Thus, it can only be used to reject JavaScript
+promises for which the corresponding deferred object is available. This
+effectively means that the promise must have been created using
+`napi_create_promise()` and the deferred object returned from that call must
+have been retained in order to be passed to this API.
+
+The deferred object is freed upon successful completion.
+
+### napi_is_promise
+
+```C
+napi_status napi_is_promise(napi_env env,
+ napi_value promise,
+ bool* is_promise);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] promise`: The promise to examine
+- `[out] is_promise`: Flag indicating whether `promise` is a native promise
+object - that is, a promise object created by the underlying engine.
+
+## Script execution
+
+N-API provides an API for executing a string containing JavaScript using the
+underlying JavaScript engine.
+
+### napi_run_script
+
+```C
+NAPI_EXTERN napi_status napi_run_script(napi_env env,
+ napi_value script,
+ napi_value* result);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] script`: A JavaScript string containing the script to execute.
+- `[out] result`: The value resulting from having executed the script.
+
+## libuv event loop
+
+N-API provides a function for getting the current event loop associated with
+a specific `napi_env`.
+
+### napi_get_uv_event_loop
+
+```C
+NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env,
+ uv_loop_t** loop);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[out] loop`: The current libuv loop instance.
+
+[Promises]: #n_api_promises
+[Simple Asynchronous Operations]: #n_api_simple_asynchronous_operations
+[Custom Asynchronous Operations]: #n_api_custom_asynchronous_operations
+[Basic N-API Data Types]: #n_api_basic_n_api_data_types
+[ECMAScript Language Specification]: https://tc39.github.io/ecma262/
+[Error Handling]: #n_api_error_handling
+[Module Registration]: #n_api_module_registration
+[Native Abstractions for Node.js]: https://github.com/nodejs/nan
+[Object Lifetime Management]: #n_api_object_lifetime_management
+[Object Wrap]: #n_api_object_wrap
+[Script Execution]: #n_api_script_execution
+[Section 9.1.6]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc
+[Section 12.5.5]: https://tc39.github.io/ecma262/#sec-typeof-operator
+[Section 24.3]: https://tc39.github.io/ecma262/#sec-dataview-objects
+[Section 25.4]: https://tc39.github.io/ecma262/#sec-promise-objects
+[Working with JavaScript Functions]: #n_api_working_with_javascript_functions
+[Working with JavaScript Properties]: #n_api_working_with_javascript_properties
+[Working with JavaScript Values]: #n_api_working_with_javascript_values
+[Working with JavaScript Values - Abstract Operations]: #n_api_working_with_javascript_values_abstract_operations
+
+[`napi_async_init`]: #n_api_napi_async_init
+[`napi_cancel_async_work`]: #n_api_napi_cancel_async_work
+[`napi_close_escapable_handle_scope`]: #n_api_napi_close_escapable_handle_scope
+[`napi_close_callback_scope`]: #n_api_napi_close_callback_scope
+[`napi_close_handle_scope`]: #n_api_napi_close_handle_scope
+[`napi_create_async_work`]: #n_api_napi_create_async_work
+[`napi_create_error`]: #n_api_napi_create_error
+[`napi_create_external_arraybuffer`]: #n_api_napi_create_external_arraybuffer
+[`napi_create_range_error`]: #n_api_napi_create_range_error
+[`napi_create_reference`]: #n_api_napi_create_reference
+[`napi_create_type_error`]: #n_api_napi_create_type_error
+[`napi_define_class`]: #n_api_napi_define_class
+[`napi_delete_async_work`]: #n_api_napi_delete_async_work
+[`napi_define_class`]: #n_api_napi_define_class
+[`napi_delete_element`]: #n_api_napi_delete_element
+[`napi_delete_property`]: #n_api_napi_delete_property
+[`napi_delete_reference`]: #n_api_napi_delete_reference
+[`napi_escape_handle`]: #n_api_napi_escape_handle
+[`napi_get_array_length`]: #n_api_napi_get_array_length
+[`napi_get_element`]: #n_api_napi_get_element
+[`napi_get_property`]: #n_api_napi_get_property
+[`napi_has_property`]: #n_api_napi_has_property
+[`napi_has_own_property`]: #n_api_napi_has_own_property
+[`napi_set_property`]: #n_api_napi_set_property
+[`napi_get_reference_value`]: #n_api_napi_get_reference_value
+[`napi_is_error`]: #n_api_napi_is_error
+[`napi_is_exception_pending`]: #n_api_napi_is_exception_pending
+[`napi_get_last_error_info`]: #n_api_napi_get_last_error_info
+[`napi_get_and_clear_last_exception`]: #n_api_napi_get_and_clear_last_exception
+[`napi_make_callback`]: #n_api_napi_make_callback
+[`napi_open_callback_scope`]: #n_api_napi_open_callback_scope
+[`napi_open_escapable_handle_scope`]: #n_api_napi_open_escapable_handle_scope
+[`napi_open_handle_scope`]: #n_api_napi_open_handle_scope
+[`napi_property_descriptor`]: #n_api_napi_property_descriptor
+[`napi_queue_async_work`]: #n_api_napi_queue_async_work
+[`napi_reference_ref`]: #n_api_napi_reference_ref
+[`napi_reference_unref`]: #n_api_napi_reference_unref
+[`napi_throw`]: #n_api_napi_throw
+[`napi_throw_error`]: #n_api_napi_throw_error
+[`napi_throw_range_error`]: #n_api_napi_throw_range_error
+[`napi_throw_type_error`]: #n_api_napi_throw_type_error
+[`napi_unwrap`]: #n_api_napi_unwrap
+[`napi_wrap`]: #n_api_napi_wrap
+
+[`process.release`]: process.html#process_process_release
+[`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource
+[async_hooks `type`]: async_hooks.html#async_hooks_type
diff --git a/doc/api/net.md b/doc/api/net.md
index 8e40c2297df77a..0c9adf4bd1ab9d 100644
--- a/doc/api/net.md
+++ b/doc/api/net.md
@@ -121,7 +121,7 @@ connections use asynchronous `server.getConnections` instead.
added: v0.9.7
-->
-* Returns {net.Server}
+* Returns: {net.Server}
Asynchronously get the number of concurrent connections on the server. Works
when sockets were sent to forks.
@@ -147,7 +147,7 @@ already been bound to a port or domain socket.
Listening on a file descriptor is not supported on Windows.
-This function is asynchronous. When the server has been bound,
+This function is asynchronous. When the server has been bound,
[`'listening'`][] event will be emitted.
The last parameter `callback` will be added as a listener for the
[`'listening'`][] event.
@@ -203,8 +203,8 @@ added: v0.1.90
Start a local socket server listening for connections on the given `path`.
-This function is asynchronous. When the server has been bound,
-[`'listening'`][] event will be emitted. The last parameter `callback`
+This function is asynchronous. When the server has been bound,
+[`'listening'`][] event will be emitted. The last parameter `callback`
will be added as a listener for the [`'listening'`][] event.
On UNIX, the local domain is usually known as the UNIX domain. The path is a
@@ -218,7 +218,7 @@ unlinked*.
On Windows, the local domain is implemented using a named pipe. The path *must*
refer to an entry in `\\?\pipe\` or `\\.\pipe\`. Any characters are permitted,
but the latter may do some processing of pipe names, such as resolving `..`
-sequences. Despite appearances, the pipe name space is flat. Pipes will *not
+sequences. Despite appearances, the pipe name space is flat. Pipes will *not
persist*, they are removed when the last reference to them is closed. Do not
forget JavaScript string escaping requires paths to be specified with
double-backslashes, such as:
@@ -252,8 +252,8 @@ The actual length will be determined by the OS through sysctl settings such as
`tcp_max_syn_backlog` and `somaxconn` on Linux. The default value of this
parameter is 511 (not 512).
-This function is asynchronous. When the server has been bound,
-[`'listening'`][] event will be emitted. The last parameter `callback`
+This function is asynchronous. When the server has been bound,
+[`'listening'`][] event will be emitted. The last parameter `callback`
will be added as a listener for the [`'listening'`][] event.
One issue some users run into is getting `EADDRINUSE` errors. This means that
@@ -323,8 +323,8 @@ active server in the event system. If the server is already `unref`d calling
added: v0.3.4
-->
-This object is an abstraction of a TCP or local socket. `net.Socket`
-instances implement a duplex Stream interface. They can be created by the
+This object is an abstraction of a TCP or local socket. `net.Socket`
+instances implement a duplex Stream interface. They can be created by the
user and used as a client (with [`connect()`][]) or they can be created by Node.js
and passed to the user through the `'connection'` event of a server.
@@ -379,8 +379,8 @@ added: v0.1.90
* {Buffer}
-Emitted when data is received. The argument `data` will be a `Buffer` or
-`String`. Encoding of data is set by `socket.setEncoding()`.
+Emitted when data is received. The argument `data` will be a `Buffer` or
+`String`. Encoding of data is set by `socket.setEncoding()`.
(See the [Readable Stream][] section for more information.)
Note that the **data will be lost** if there is no listener when a `Socket`
@@ -403,7 +403,7 @@ added: v0.1.90
Emitted when the other end of the socket sends a FIN packet.
By default (`allowHalfOpen == false`) the socket will destroy its file
-descriptor once it has written out its pending write queue. However, by
+descriptor once it has written out its pending write queue. However, by
setting `allowHalfOpen == true` the socket will not automatically `end()`
its side allowing the user to write arbitrary amounts of data, with the
caveat that the user is required to `end()` their side now.
@@ -415,7 +415,7 @@ added: v0.1.90
* {Error}
-Emitted when an error occurs. The `'close'` event will be called directly
+Emitted when an error occurs. The `'close'` event will be called directly
following this event.
### Event: 'lookup'
@@ -426,9 +426,9 @@ added: v0.11.3
Emitted after resolving the hostname but before connecting.
Not applicable to UNIX sockets.
-* `err` {Error|null} The error object. See [`dns.lookup()`][].
+* `err` {Error|null} The error object. See [`dns.lookup()`][].
* `address` {string} The IP address.
-* `family` {string|null} The address type. See [`dns.lookup()`][].
+* `family` {string|null} The address type. See [`dns.lookup()`][].
* `host` {string} The hostname.
### Event: 'timeout'
@@ -718,7 +718,7 @@ added: v0.1.90
-->
Sends data on the socket. The second parameter specifies the encoding in the
-case of a string--it defaults to UTF8 encoding.
+case of a string — it defaults to UTF8 encoding.
Returns `true` if the entire data was flushed successfully to the kernel
buffer. Returns `false` if all or part of the data was queued in user memory.
diff --git a/doc/api/os.md b/doc/api/os.md
index 011ce5e2bf1742..b8f5c76ce00793 100644
--- a/doc/api/os.md
+++ b/doc/api/os.md
@@ -225,7 +225,7 @@ The `os.loadavg()` method returns an array containing the 1, 5, and 15 minute
load averages.
The load average is a measure of system activity, calculated by the operating
-system and expressed as a fractional number. As a rule of thumb, the load
+system and expressed as a fractional number. As a rule of thumb, the load
average should ideally be less than the number of logical CPUs in the system.
The load average is a UNIX-specific concept with no real equivalent on
@@ -392,7 +392,7 @@ added: v6.0.0
* Returns: {Object}
The `os.userInfo()` method returns information about the currently effective
-user -- on POSIX platforms, this is typically a subset of the password file. The
+user — on POSIX platforms, this is typically a subset of the password file. The
returned object includes the `username`, `uid`, `gid`, `shell`, and `homedir`.
On Windows, the `uid` and `gid` fields are `-1`, and `shell` is `null`.
diff --git a/doc/api/path.md b/doc/api/path.md
index 807cf9b88c9869..7ab4dabb79e04f 100644
--- a/doc/api/path.md
+++ b/doc/api/path.md
@@ -145,7 +145,7 @@ added: v0.1.25
The `path.extname()` method returns the extension of the `path`, from the last
occurrence of the `.` (period) character to end of string in the last portion of
-the `path`. If there is no `.` in the last portion of the `path`, or if the
+the `path`. If there is no `.` in the last portion of the `path`, or if the
first character of the basename of `path` (see `path.basename()`) is `.`, then
an empty string is returned.
@@ -380,7 +380,7 @@ path.parse('/home/user/dir/file.txt');
│ root │ │ name │ ext │
" / home/user/dir / file .txt "
└──────┴──────────────┴──────┴─────┘
-(all spaces in the "" line should be ignored -- they are purely for formatting)
+(all spaces in the "" line should be ignored — they are purely for formatting)
```
On Windows:
@@ -404,7 +404,7 @@ path.parse('C:\\path\\dir\\file.txt');
│ root │ │ name │ ext │
" C:\ path\dir \ file .txt "
└──────┴──────────────┴──────┴─────┘
-(all spaces in the "" line should be ignored -- they are purely for formatting)
+(all spaces in the "" line should be ignored — they are purely for formatting)
```
A [`TypeError`][] is thrown if `path` is not a string.
diff --git a/doc/api/process.md b/doc/api/process.md
index c9aebfa8d2cce4..af20ddb1f751b1 100644
--- a/doc/api/process.md
+++ b/doc/api/process.md
@@ -189,7 +189,7 @@ process will exit with a non-zero exit code and the stack trace will be printed.
This is to avoid infinite recursion.
Attempting to resume normally after an uncaught exception can be similar to
-pulling out of the power cord when upgrading a computer -- nine out of ten
+pulling out of the power cord when upgrading a computer — nine out of ten
times nothing happens - but the 10th time, the system becomes corrupted.
The correct use of `'uncaughtException'` is to perform synchronous cleanup
@@ -388,7 +388,7 @@ For example:
process.stdin.resume();
process.on('SIGINT', () => {
- console.log('Received SIGINT. Press Control-D to exit.');
+ console.log('Received SIGINT. Press Control-D to exit.');
});
```
@@ -397,7 +397,7 @@ terminal programs.
It is important to take note of the following:
-* `SIGUSR1` is reserved by Node.js to start the debugger. It's possible to
+* `SIGUSR1` is reserved by Node.js to start the debugger. It's possible to
install a listener but doing so will _not_ stop the debugger from starting.
* `SIGTERM` and `SIGINT` have default handlers on non-Windows platforms that
resets the terminal mode before exiting with code `128 + signal number`. If
@@ -470,7 +470,7 @@ added: v0.1.27
The `process.argv` property returns an array containing the command line
arguments passed when the Node.js process was launched. The first element will
be [`process.execPath`]. See `process.argv0` if access to the original value of
-`argv[0]` is needed. The second element will be the path to the JavaScript
+`argv[0]` is needed. The second element will be the path to the JavaScript
file being executed. The remaining elements will be any additional command line
arguments.
@@ -890,7 +890,7 @@ added: v0.1.13
The `process.exit()` method instructs Node.js to terminate the process
synchronously with an exit status of `code`. If `code` is omitted, exit uses
either the 'success' code `0` or the value of `process.exitCode` if it has been
-set. Node.js will not terminate until all the [`'exit'`] event listeners are
+set. Node.js will not terminate until all the [`'exit'`] event listeners are
called.
To exit with a 'failure' code:
@@ -1129,7 +1129,7 @@ Windows platforms will throw an error if the `pid` is used to kill a process
group.
*Note*:Even though the name of this function is `process.kill()`, it is really
-just a signal sender, like the `kill` system call. The signal sent may do
+just a signal sender, like the `kill` system call. The signal sent may do
something other than kill the target process.
For example:
@@ -1219,7 +1219,7 @@ Once the current turn of the event loop turn runs to completion, all callbacks
currently in the next tick queue will be called.
This is *not* a simple alias to [`setTimeout(fn, 0)`][]. It is much more
-efficient. It runs before any additional I/O events (including
+efficient. It runs before any additional I/O events (including
timers) fire in subsequent ticks of the event loop.
```js
@@ -1254,7 +1254,7 @@ thing.getReadyForStuff();
```
It is very important for APIs to be either 100% synchronous or 100%
-asynchronous. Consider this example:
+asynchronous. Consider this example:
```js
// WARNING! DO NOT USE! BAD UNSAFE HAZARD!
@@ -1296,7 +1296,7 @@ function definitelyAsync(arg, cb) {
```
*Note*: the next tick queue is completely drained on each pass of the
-event loop **before** additional I/O is processed. As a result,
+event loop **before** additional I/O is processed. As a result,
recursively setting nextTick callbacks will block any I/O from
happening, just like a `while(true);` loop.
@@ -1371,8 +1371,8 @@ tarball.
Support) line the current release is part of. This property only exists for
LTS releases and is `undefined` for all other release types, including stable
releases. Current valid values are:
- - `"Argon"` for the v4.x LTS line beginning with v4.2.0.
- - `"Boron"` for the v6.x LTS line beginning with v6.9.0.
+ - `'Argon'` for the v4.x LTS line beginning with v4.2.0.
+ - `'Boron'` for the v6.x LTS line beginning with v6.9.0.
* `sourceUrl` {string} an absolute URL pointing to a _`.tar.gz`_ file containing
the source code of the current release.
* `headersUrl`{string} an absolute URL pointing to a _`.tar.gz`_ file containing
@@ -1461,7 +1461,7 @@ added: v2.0.0
The `process.seteuid()` method sets the effective user identity of the process.
(See seteuid(2).) The `id` can be passed as either a numeric ID or a username
-string. If a username is specified, the method blocks while resolving the
+string. If a username is specified, the method blocks while resolving the
associated numeric ID.
```js
@@ -1487,7 +1487,7 @@ added: v0.1.31
* `id` {string|number} The group name or ID
The `process.setgid()` method sets the group identity of the process. (See
-setgid(2).) The `id` can be passed as either a numeric ID or a group name
+setgid(2).) The `id` can be passed as either a numeric ID or a group name
string. If a group name is specified, this method blocks while resolving the
associated numeric ID.
@@ -1528,7 +1528,7 @@ added: v0.1.28
-->
The `process.setuid(id)` method sets the user identity of the process. (See
-setuid(2).) The `id` can be passed as either a numeric ID or a username string.
+setuid(2).) The `id` can be passed as either a numeric ID or a username string.
If a username is specified, the method blocks while resolving the associated
numeric ID.
@@ -1790,7 +1790,7 @@ Will generate an object similar to:
## Exit Codes
Node.js will normally exit with a `0` status code when no more async
-operations are pending. The following status codes are used in other
+operations are pending. The following status codes are used in other
cases:
* `1` **Uncaught Fatal Exception** - There was an uncaught exception,
@@ -1798,12 +1798,12 @@ cases:
handler.
* `2` - Unused (reserved by Bash for builtin misuse)
* `3` **Internal JavaScript Parse Error** - The JavaScript source code
- internal in Node.js's bootstrapping process caused a parse error. This
+ internal in Node.js's bootstrapping process caused a parse error. This
is extremely rare, and generally can only happen during development
of Node.js itself.
* `4` **Internal JavaScript Evaluation Failure** - The JavaScript
source code internal in Node.js's bootstrapping process failed to
- return a function value when evaluated. This is extremely rare, and
+ return a function value when evaluated. This is extremely rare, and
generally can only happen during development of Node.js itself.
* `5` **Fatal Error** - There was a fatal unrecoverable error in V8.
Typically a message will be printed to stderr with the prefix `FATAL
@@ -1813,23 +1813,23 @@ cases:
function was somehow set to a non-function, and could not be called.
* `7` **Internal Exception Handler Run-Time Failure** - There was an
uncaught exception, and the internal fatal exception handler
- function itself threw an error while attempting to handle it. This
+ function itself threw an error while attempting to handle it. This
can happen, for example, if a [`'uncaughtException'`][] or
`domain.on('error')` handler throws an error.
-* `8` - Unused. In previous versions of Node.js, exit code 8 sometimes
+* `8` - Unused. In previous versions of Node.js, exit code 8 sometimes
indicated an uncaught exception.
* `9` - **Invalid Argument** - Either an unknown option was specified,
or an option requiring a value was provided without a value.
* `10` **Internal JavaScript Run-Time Failure** - The JavaScript
source code internal in Node.js's bootstrapping process threw an error
- when the bootstrapping function was called. This is extremely rare,
+ when the bootstrapping function was called. This is extremely rare,
and generally can only happen during development of Node.js itself.
* `12` **Invalid Debug Argument** - The `--debug`, `--inspect` and/or
`--debug-brk` options were set, but the port number chosen was invalid
or unavailable.
* `>128` **Signal Exits** - If Node.js receives a fatal signal such as
`SIGKILL` or `SIGHUP`, then its exit code will be `128` plus the
- value of the signal code. This is a standard POSIX practice, since
+ value of the signal code. This is a standard POSIX practice, since
exit codes are defined to be 7-bit integers, and signal exits set
the high-order bit, and then contain the value of the signal code.
diff --git a/doc/api/readline.md b/doc/api/readline.md
index b88c37e5bdbfa3..d31af7ff3f6b02 100644
--- a/doc/api/readline.md
+++ b/doc/api/readline.md
@@ -295,7 +295,7 @@ added: v0.1.98
* `shift` {boolean} `true` to indicate the `` key.
* `name` {string} The name of the a key.
-The `rl.write()` method will write either `data` or a key sequence identified
+The `rl.write()` method will write either `data` or a key sequence identified
by `key` to the `output`. The `key` argument is supported only if `output` is
a [TTY][] text terminal.
@@ -323,7 +323,7 @@ Interface's `input` *as if it were provided by the user*.
added: v0.7.7
-->
-* `stream` {Writable}
+* `stream` {stream.Writable}
* `dir` {number}
* `-1` - to the left from cursor
* `1` - to the right from cursor
@@ -338,7 +338,7 @@ in a specified direction identified by `dir`.
added: v0.7.7
-->
-* `stream` {Writable}
+* `stream` {stream.Writable}
The `readline.clearScreenDown()` method clears the given [TTY][] stream from
the current position of the cursor down.
@@ -349,9 +349,9 @@ added: v0.1.98
-->
* `options` {Object}
- * `input` {Readable} The [Readable][] stream to listen to. This option is
+ * `input` {stream.Readable} The [Readable][] stream to listen to. This option is
*required*.
- * `output` {Writable} The [Writable][] stream to write readline data to.
+ * `output` {stream.Writable} The [Writable][] stream to write readline data to.
* `completer` {Function} An optional function used for Tab autocompletion.
* `terminal` {boolean} `true` if the `input` and `output` streams should be
treated like a TTY, and have ANSI/VT100 escape codes written to it.
@@ -431,7 +431,7 @@ function completer(linePartial, callback) {
added: v0.7.7
-->
-* `stream` {Writable}
+* `stream` {stream.Writable}
* `x` {number}
* `y` {number}
@@ -443,7 +443,7 @@ given [TTY][] `stream`.
added: v0.7.7
-->
-* `stream` {Readable}
+* `stream` {stream.Readable}
* `interface` {readline.Interface}
The `readline.emitKeypressEvents()` method causes the given [Readable][]
@@ -469,7 +469,7 @@ if (process.stdin.isTTY)
added: v0.7.7
-->
-* `stream` {Writable}
+* `stream` {stream.Writable}
* `dx` {number}
* `dy` {number}
diff --git a/doc/api/repl.md b/doc/api/repl.md
index 69f709a1be874b..e8c87240b1a579 100644
--- a/doc/api/repl.md
+++ b/doc/api/repl.md
@@ -96,7 +96,7 @@ declared either implicitly or using the `var` keyword are declared at the
The default evaluator provides access to any variables that exist in the global
scope. It is possible to expose a variable to the REPL explicitly by assigning
-it to the `context` object associated with each `REPLServer`. For example:
+it to the `context` object associated with each `REPLServer`. For example:
```js
const repl = require('repl');
@@ -381,9 +381,9 @@ added: v0.1.91
* `options` {Object | string}
* `prompt` {string} The input prompt to display. Defaults to `> `.
- * `input` {Readable} The Readable stream from which REPL input will be read.
+ * `input` {stream.Readable} The Readable stream from which REPL input will be read.
Defaults to `process.stdin`.
- * `output` {Writable} The Writable stream to which REPL output will be
+ * `output` {stream.Writable} The Writable stream to which REPL output will be
written. Defaults to `process.stdout`.
* `terminal` {boolean} If `true`, specifies that the `output` should be
treated as a TTY terminal, and have ANSI/VT100 escape codes written to it.
@@ -391,7 +391,7 @@ added: v0.1.91
stream upon instantiation.
* `eval` {Function} The function to be used when evaluating each given line
of input. Defaults to an async wrapper for the JavaScript `eval()`
- function. An `eval` function can error with `repl.Recoverable` to indicate
+ function. An `eval` function can error with `repl.Recoverable` to indicate
the input was incomplete and prompt for additional lines.
* `useColors` {boolean} If `true`, specifies that the default `writer`
function should include ANSI color styling to REPL output. If a custom
@@ -414,7 +414,7 @@ added: v0.1.91
* `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is
equivalent to prefacing every repl statement with `'use strict'`.
* `repl.REPL_MODE_MAGIC` - attempt to evaluates expressions in default
- mode. If expressions fail to parse, re-try in strict mode.
+ mode. If expressions fail to parse, re-try in strict mode.
* `breakEvalOnSigint` - Stop evaluating the current piece of code when
`SIGINT` is received, i.e. `Ctrl+C` is pressed. This cannot be used together
with a custom `eval` function. Defaults to `false`.
@@ -456,7 +456,7 @@ environment variables:
- `NODE_REPL_HISTORY` - When a valid path is given, persistent REPL history
will be saved to the specified file rather than `.node_repl_history` in the
- user's home directory. Setting this value to `""` will disable persistent
+ user's home directory. Setting this value to `''` will disable persistent
REPL history. Whitespace will be trimmed from the value.
- `NODE_REPL_HISTORY_SIZE` - Defaults to `1000`. Controls how many lines of
history will be persisted if history is available. Must be a positive number.
@@ -469,7 +469,7 @@ environment variables:
By default, the Node.js REPL will persist history between `node` REPL sessions
by saving inputs to a `.node_repl_history` file located in the user's home
directory. This can be disabled by setting the environment variable
-`NODE_REPL_HISTORY=""`.
+`NODE_REPL_HISTORY=''`.
#### NODE_REPL_HISTORY_FILE
* `encoding` {string} The new default encoding
-* Returns: `this`
+* Returns: {this}
The `writable.setDefaultEncoding()` method sets the default `encoding` for a
[Writable][] stream.
@@ -771,7 +771,7 @@ readable.isPaused(); // === false
added: v0.9.4
-->
-* Returns: `this`
+* Returns: {this}
The `readable.pause()` method will cause a stream in flowing mode to stop
emitting [`'data'`][] events, switching out of flowing mode. Any data that
@@ -854,7 +854,7 @@ added: v0.9.4
-->
* `size` {number} Optional argument to specify how much data to read.
-* Return {string|Buffer|null}
+* Returns: {string|Buffer|null}
The `readable.read()` method pulls some data out of the internal buffer and
returns it. If no data available to be read, `null` is returned. By default,
@@ -903,7 +903,7 @@ event has been emitted will return `null`. No runtime error will be raised.
added: v0.9.4
-->
-* Returns: `this`
+* Returns: {this}
The `readable.resume()` method causes an explicitly paused Readable stream to
resume emitting [`'data'`][] events, switching the stream into flowing mode.
@@ -926,7 +926,7 @@ added: v0.9.4
-->
* `encoding` {string} The encoding to use.
-* Returns: `this`
+* Returns: {this}
The `readable.setEncoding()` method sets the character encoding for
data read from the Readable stream.
@@ -1364,7 +1364,7 @@ It is recommended that errors occurring during the processing of the
the callback and passing the error as the first argument. This will cause an
`'error'` event to be emitted by the Writable. Throwing an Error from within
`writable._write()` can result in unexpected and inconsistent behavior depending
-on how the stream is being used. Using the callback ensures consistent and
+on how the stream is being used. Using the callback ensures consistent and
predictable handling of errors.
```js
@@ -1543,7 +1543,7 @@ user programs.
#### readable.push(chunk[, encoding])
* `chunk` {Buffer|null|string} Chunk of data to push into the read queue
-* `encoding` {string} Encoding of String chunks. Must be a valid
+* `encoding` {string} Encoding of String chunks. Must be a valid
Buffer encoding, such as `'utf8'` or `'ascii'`
* Returns: {boolean} `true` if additional chunks of data may continued to be
pushed; `false` otherwise.
@@ -1963,7 +1963,7 @@ The `transform._transform()` method is prefixed with an underscore because it
is internal to the class that defines it, and should never be called directly by
user programs.
-`transform._transform()` is never called in parallel; streams implement a
+`transform._transform()` is never called in parallel; streams implement a
queue mechanism, and to receive the next chunk, `callback` must be
called, either synchronously or asynchronously.
diff --git a/doc/api/synopsis.md b/doc/api/synopsis.md
index 6aaf54edff89a2..aa28b043438c41 100644
--- a/doc/api/synopsis.md
+++ b/doc/api/synopsis.md
@@ -9,9 +9,58 @@ Please see the [Command Line Options][] document for information about
different options and ways to run scripts with Node.js.
## Example
-
An example of a [web server][] written with Node.js which responds with
-`'Hello World'`:
+`'Hello World!'`:
+
+Commands displayed in this document are shown starting with `$` or `>`
+to replicate how they would appear in a user's terminal.
+Do not include the `$` and `>` character they are there to
+indicate the start of each command.
+
+There are many tutorials and examples that follow this
+convention: `$` or `>` for commands run as a regular user, and `#`
+for commands that should be executed as an administrator.
+
+Lines that don’t start with `$` or `>` character are typically showing
+the output of the previous command.
+
+Firstly, make sure to have downloaded and installed Node.js.
+See [this guide][] for further install information.
+
+Now, create an empty project folder called `projects`, navigate into it:
+Project folder can be named base on user's current project title but
+this example will use `projects` as the project folder.
+
+Linux and Mac:
+
+```console
+$ mkdir ~/projects
+$ cd ~/projects
+```
+
+Windows CMD:
+
+```console
+> mkdir %USERPROFILE%\projects
+> cd %USERPROFILE%\projects
+```
+
+Windows PowerShell:
+
+```console
+> mkdir $env:USERPROFILE\projects
+> cd $env:USERPROFILE\projects
+```
+
+Next, create a new source file in the `projects`
+ folder and call it `hello-world.js`.
+
+In Node.js it is considered good style to use
+hyphens (`-`) or underscores (`_`) to separate
+ multiple words in filenames.
+
+Open `hello-world.js` in any preferred text editor and
+paste in the following content.
```js
const http = require('http');
@@ -22,7 +71,7 @@ const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
- res.end('Hello World\n');
+ res.end('Hello World!\n');
});
server.listen(port, hostname, () => {
@@ -30,15 +79,26 @@ server.listen(port, hostname, () => {
});
```
-To run the server, put the code into a file called `example.js` and execute
-it with Node.js:
+Save the file, go back to the terminal window enter the following command:
-```txt
-$ node example.js
-Server running at http://127.0.0.1:3000/
+```console
+$ node hello-world.js
```
+An output like this should appear in the terminal to indicate Node.js
+server is running:
+
+ ```console
+ Server running at http://127.0.0.1:3000/
+ ````
+
+Now, open any preferred web browser and visit `http://127.0.0.1:3000`.
+
+If the browser displays the string `Hello, world!`, that indicates
+the server is working.
+
Many of the examples in the documentation can be run similarly.
[Command Line Options]: cli.html#cli_command_line_options
[web server]: http.html
+[this guide]: https://nodejs.org/en/download/package-manager/
diff --git a/doc/api/tls.md b/doc/api/tls.md
index d307b376ef58e2..9b6027ab11f278 100644
--- a/doc/api/tls.md
+++ b/doc/api/tls.md
@@ -374,7 +374,7 @@ added: v0.6.0
-->
Returns the bound address, the address family name, and port of the
-server as reported by the operating system. See [`net.Server.address()`][] for
+server as reported by the operating system. See [`net.Server.address()`][] for
more information.
### server.close([callback])
@@ -472,7 +472,7 @@ added: v0.11.4
* `options` {Object}
* `isServer`: The SSL/TLS protocol is asymmetrical, TLSSockets must know if
they are to behave as a server or a client. If `true` the TLS socket will be
- instantiated as a server. Defaults to `false`.
+ instantiated as a server. Defaults to `false`.
* `server` {net.Server} An optional [`net.Server`][] instance.
* `requestCert`: Whether to authenticate the remote peer by requesting a
certificate. Clients always request a server certificate. Servers
@@ -624,7 +624,7 @@ For example:
{ ... another certificate, possibly with a .issuerCertificate ... },
raw: < RAW DER buffer >,
valid_from: 'Nov 11 09:52:22 2009 GMT',
- valid_to: 'Nov 6 09:52:22 2029 GMT',
+ valid_to: 'Nov 6 09:52:22 2029 GMT',
fingerprint: '2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF',
serialNumber: 'B9B0D332A1AA5635' }
```
@@ -795,7 +795,7 @@ changes:
rather than creating a new socket. Typically, this is an instance of
[`net.Socket`][], but any `Duplex` stream is allowed.
If this option is specified, `path`, `host` and `port` are ignored,
- except for certificate validation. Usually, a socket is already connected
+ except for certificate validation. Usually, a socket is already connected
when passed to `tls.connect()`, but it can be connected later. Note that
connection/disconnection/destruction of `socket` is the user's
responsibility, calling `tls.connect()` will not cause `net.connect()` to be
@@ -910,7 +910,7 @@ added: v0.11.13
to decrypt it.
* `key` {string|string[]|Buffer|Buffer[]|Object[]} Optional private keys in
PEM format. PEM allows the option of private keys being encrypted. Encrypted
- keys will be decrypted with `options.passphrase`. Multiple keys using
+ keys will be decrypted with `options.passphrase`. Multiple keys using
different algorithms can be provided either as an array of unencrypted key
strings or buffers, or an array of objects in the form `{pem:
[, passphrase: ]}`. The object form can only occur in
@@ -923,7 +923,7 @@ added: v0.11.13
consist of the PEM formatted certificate for a provided private `key`,
followed by the PEM formatted intermediate certificates (if any), in order,
and not including the root CA (the root CA must be pre-known to the peer,
- see `ca`). When providing multiple cert chains, they do not have to be in
+ see `ca`). When providing multiple cert chains, they do not have to be in
the same order as their private keys in `key`. If the intermediate
certificates are not provided, the peer will not be able to validate the
certificate, and the handshake will fail.
@@ -933,7 +933,7 @@ added: v0.11.13
using this option. The value can be a string or Buffer, or an Array of
strings and/or Buffers. Any string or Buffer can contain multiple PEM CAs
concatenated together. The peer's certificate must be chainable to a CA
- trusted by the server for the connection to be authenticated. When using
+ trusted by the server for the connection to be authenticated. When using
certificates that are not chainable to a well-known CA, the certificate's CA
must be explicitly specified as a trusted or the connection will fail to
authenticate.
@@ -945,7 +945,7 @@ added: v0.11.13
* `crl` {string|string[]|Buffer|Buffer[]} Optional PEM formatted
CRLs (Certificate Revocation Lists).
* `ciphers` {string} Optional cipher suite specification, replacing the
- default. For more information, see [modifying the default cipher suite][].
+ default. For more information, see [modifying the default cipher suite][].
* `honorCipherOrder` {boolean} Attempt to use the server's cipher suite
preferences instead of the client's. When `true`, causes
`SSL_OP_CIPHER_SERVER_PREFERENCE` to be set in `secureOptions`, see
@@ -954,7 +954,7 @@ added: v0.11.13
APIs that create secure contexts leave it unset.
* `ecdhCurve` {string} A string describing a named curve to use for ECDH key
agreement or `false` to disable ECDH. Defaults to
- [`tls.DEFAULT_ECDH_CURVE`]. Use [`crypto.getCurves()`][] to obtain a list
+ [`tls.DEFAULT_ECDH_CURVE`]. Use [`crypto.getCurves()`][] to obtain a list
of available curve names. On recent releases, `openssl ecparam -list_curves`
will also display the name and description of each available elliptic curve.
* `dhparam` {string|Buffer} Diffie Hellman parameters, required for
@@ -964,8 +964,8 @@ added: v0.11.13
for stronger security. If omitted or invalid, the parameters are silently
discarded and DHE ciphers will not be available.
* `secureProtocol` {string} Optional SSL method to use, default is
- `"SSLv23_method"`. The possible values are listed as [SSL_METHODS][], use
- the function names as strings. For example, `"SSLv3_method"` to force SSL
+ `'SSLv23_method'`. The possible values are listed as [SSL_METHODS][], use
+ the function names as strings. For example, `'SSLv3_method'` to force SSL
version 3.
* `secureOptions` {number} Optionally affect the OpenSSL protocol behavior,
which is not usually necessary. This should be used carefully if at all!
@@ -1027,7 +1027,7 @@ added: v0.3.2
servers, the identity options (`pfx` or `key`/`cert`) are usually required.
* `secureConnectionListener` {Function}
-Creates a new [tls.Server][]. The `secureConnectionListener`, if provided, is
+Creates a new [tls.Server][]. The `secureConnectionListener`, if provided, is
automatically set as a listener for the [`'secureConnection'`][] event.
The following illustrates a simple echo server:
diff --git a/doc/api/url.md b/doc/api/url.md
index 599f0cbf0905eb..5b9c3c23f43426 100644
--- a/doc/api/url.md
+++ b/doc/api/url.md
@@ -51,7 +51,7 @@ properties of a WHATWG `URL` object.
├─────────────┴─────────────────────┴─────────────────────┴──────────┴────────────────┴───────┤
│ href │
└─────────────────────────────────────────────────────────────────────────────────────────────┘
-(all spaces in the "" line should be ignored -- they are purely for formatting)
+(all spaces in the "" line should be ignored — they are purely for formatting)
```
Parsing the URL string using the WHATWG API:
@@ -555,7 +555,7 @@ Instantiate a new `URLSearchParams` object with an iterable map in a way that
is similar to [`Map`][]'s constructor. `iterable` can be an Array or any
iterable object. That means `iterable` can be another `URLSearchParams`, in
which case the constructor will simply create a clone of the provided
-`URLSearchParams`. Elements of `iterable` are key-value pairs, and can
+`URLSearchParams`. Elements of `iterable` are key-value pairs, and can
themselves be any iterable object.
Duplicate keys are allowed.
@@ -984,6 +984,11 @@ The formatting process operates as follows:
### url.parse(urlString[, parseQueryString[, slashesDenoteHost]])
* `urlString` {string} The URL string to parse.
diff --git a/doc/api/util.md b/doc/api/util.md
index 9e29cfc073ccc5..e1ad92095539bb 100644
--- a/doc/api/util.md
+++ b/doc/api/util.md
@@ -23,9 +23,9 @@ added: v0.11.3
The `util.debuglog()` method is used to create a function that conditionally
writes debug messages to `stderr` based on the existence of the `NODE_DEBUG`
-environment variable. If the `section` name appears within the value of that
+environment variable. If the `section` name appears within the value of that
environment variable, then the returned function operates similar to
-[`console.error()`][]. If not, then the returned function is a no-op.
+[`console.error()`][]. If not, then the returned function is a no-op.
For example:
@@ -43,7 +43,7 @@ it will output something like:
FOO 3245: hello from foo [123]
```
-where `3245` is the process id. If it is not run with that
+where `3245` is the process id. If it is not run with that
environment variable set, then it will not print anything.
Multiple comma-separated `section` names may be specified in the `NODE_DEBUG`
@@ -108,7 +108,7 @@ corresponding argument. Supported placeholders are:
* `%d` - Number (integer or floating point value).
* `%i` - Integer.
* `%f` - Floating point value.
-* `%j` - JSON. Replaced with the string `'[Circular]'` if the argument
+* `%j` - JSON. Replaced with the string `'[Circular]'` if the argument
contains circular references.
* `%%` - single percent sign (`'%'`). This does not consume an argument.
@@ -157,7 +157,7 @@ the two styles are [semantically incompatible][]._
* `constructor` {Function}
* `superConstructor` {Function}
-Inherit the prototype methods from one [constructor][] into another. The
+Inherit the prototype methods from one [constructor][] into another. The
prototype of `constructor` will be set to a new object created from
`superConstructor`.
diff --git a/doc/api/v8.md b/doc/api/v8.md
index 234835376bd3e0..a74bf64e535108 100644
--- a/doc/api/v8.md
+++ b/doc/api/v8.md
@@ -110,7 +110,7 @@ after the VM has started may result in unpredictable behavior, including
crashes and data loss; or it may simply do nothing.
The V8 options available for a version of Node.js may be determined by running
-`node --v8-options`. An unofficial, community-maintained list of options
+`node --v8-options`. An unofficial, community-maintained list of options
and their effects is available [here][].
Usage:
diff --git a/doc/api/vm.md b/doc/api/vm.md
index 8c196f1d1a682f..9aab34f20b86c2 100644
--- a/doc/api/vm.md
+++ b/doc/api/vm.md
@@ -108,7 +108,7 @@ added: v0.3.1
will be thrown.
* `breakOnSigint`: if `true`, the execution will be terminated when
`SIGINT` (Ctrl+C) is received. Existing handlers for the
- event that have been attached via `process.on("SIGINT")` will be disabled
+ event that have been attached via `process.on('SIGINT')` will be disabled
during script execution, but will continue to work after that.
If execution is terminated, an [`Error`][] will be thrown.
diff --git a/doc/api/zlib.md b/doc/api/zlib.md
index 6cef23824977c9..19ab15231913c3 100644
--- a/doc/api/zlib.md
+++ b/doc/api/zlib.md
@@ -57,8 +57,8 @@ header is used to identify the compression encodings actually applied to a
message.
**Note: the examples given below are drastically simplified to show
-the basic concept.** Using `zlib` encoding can be expensive, and the results
-ought to be cached. See [Memory Usage Tuning][] for more information
+the basic concept.** Using `zlib` encoding can be expensive, and the results
+ought to be cached. See [Memory Usage Tuning][] for more information
on the speed/memory/compression tradeoffs involved in `zlib` usage.
```js
@@ -157,7 +157,7 @@ The memory requirements for deflate are (in bytes):
(1 << (windowBits + 2)) + (1 << (memLevel + 9));
```
-That is: 128K for windowBits=15 + 128K for memLevel = 8
+That is: 128K for windowBits = 15 + 128K for memLevel = 8
(default values) plus a few kilobytes for small objects.
For example, to reduce the default memory requirements from 256K to 128K, the
@@ -175,20 +175,20 @@ The memory requirements for inflate are (in bytes)
1 << windowBits;
```
-That is, 32K for windowBits=15 (default value) plus a few kilobytes
+That is, 32K for windowBits = 15 (default value) plus a few kilobytes
for small objects.
This is in addition to a single internal output slab buffer of size
`chunkSize`, which defaults to 16K.
The speed of `zlib` compression is affected most dramatically by the
-`level` setting. A higher level will result in better compression, but
-will take longer to complete. A lower level will result in less
+`level` setting. A higher level will result in better compression, but
+will take longer to complete. A lower level will result in less
compression, but will be much faster.
In general, greater memory usage options will mean that Node.js has to make
fewer calls to `zlib` because it will be able to process more data on
-each `write` operation. So, this is another factor that affects the
+each `write` operation. So, this is another factor that affects the
speed, at the cost of memory usage.
## Flushing
@@ -231,7 +231,7 @@ added: v0.5.8
All of the constants defined in `zlib.h` are also defined on `require('zlib')`.
In the normal course of operations, it will not be necessary to use these
constants. They are documented so that their presence is not surprising. This
-section is taken almost directly from the [zlib documentation][]. See
+section is taken almost directly from the [zlib documentation][]. See
for more details.
Allowed flush values.
@@ -288,14 +288,14 @@ added: v0.11.1
-Each class takes an `options` object. All options are optional.
+Each class takes an `options` object. All options are optional.
Note that some options are only relevant when compressing, and are
ignored by the decompression classes.
* `flush` (default: `zlib.Z_NO_FLUSH`)
* `finishFlush` (default: `zlib.Z_FINISH`)
-* `chunkSize` (default: 16*1024)
+* `chunkSize` (default: `16 * 1024`)
* `windowBits`
* `level` (compression only)
* `memLevel` (compression only)
diff --git a/doc/changelogs/CHANGELOG_V6.md b/doc/changelogs/CHANGELOG_V6.md
index f84e43d8398c85..5b1a998e3f6034 100644
--- a/doc/changelogs/CHANGELOG_V6.md
+++ b/doc/changelogs/CHANGELOG_V6.md
@@ -7,6 +7,7 @@
+6.14.2 6.14.1 6.14.0 6.13.1
@@ -62,6 +63,244 @@
[Node.js Long Term Support Plan](https://github.com/nodejs/LTS) and
will be supported actively until April 2018 and maintained until April 2019.
+
+## 2018-04-30, Version 6.14.2 'Boron' (LTS), @MylesBorins
+
+### Notable Changes
+
+* **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](https://github.com/nodejs/node/pull/19447)
+
+### Commits
+
+* [[`6ba38e8c2b`](https://github.com/nodejs/node/commit/6ba38e8c2b)] - **N-API**: Reuse ObjectTemplate instances (Gabriel Schulhof) [#13999](https://github.com/nodejs/node/pull/13999)
+* [[`49d8c2e8ae`](https://github.com/nodejs/node/commit/49d8c2e8ae)] - **build**: refine static and shared lib build (Yihong Wang) [#17604](https://github.com/nodejs/node/pull/17604)
+* [[`cc7469eec8`](https://github.com/nodejs/node/commit/cc7469eec8)] - **build**: allow x86\_64 as a dest\_cpu alias for x64 (Rod Vagg) [#18052](https://github.com/nodejs/node/pull/18052)
+* [[`969398d08e`](https://github.com/nodejs/node/commit/969398d08e)] - **crypto**: reuse variable instead of reevaluation (Tobias Nießen) [#17735](https://github.com/nodejs/node/pull/17735)
+* [[`71acb5205a`](https://github.com/nodejs/node/commit/71acb5205a)] - **doc**: Add a missing comma (jiangq) [#19555](https://github.com/nodejs/node/pull/19555)
+* [[`b9b752ef07`](https://github.com/nodejs/node/commit/b9b752ef07)] - **doc**: fix typos on n-api (Kyle Robinson Young) [#19385](https://github.com/nodejs/node/pull/19385)
+* [[`10fe65a0d5`](https://github.com/nodejs/node/commit/10fe65a0d5)] - **doc**: fix n-api asynchronous threading docs (Eric Bickle) [#19073](https://github.com/nodejs/node/pull/19073)
+* [[`8826f185b0`](https://github.com/nodejs/node/commit/8826f185b0)] - **doc**: mark NAPI\_AUTO\_LENGTH as code (Tobias Nießen) [#18697](https://github.com/nodejs/node/pull/18697)
+* [[`e9e5d56121`](https://github.com/nodejs/node/commit/e9e5d56121)] - **doc**: fix exporting a function example (Aonghus O Nia) [#18661](https://github.com/nodejs/node/pull/18661)
+* [[`9719b831a3`](https://github.com/nodejs/node/commit/9719b831a3)] - **doc**: fix typo in n-api.md (Vse Mozhet Byt) [#18590](https://github.com/nodejs/node/pull/18590)
+* [[`fdd50fb35f`](https://github.com/nodejs/node/commit/fdd50fb35f)] - **doc**: small typo in n-api.md (iskore) [#18555](https://github.com/nodejs/node/pull/18555)
+* [[`24a2791173`](https://github.com/nodejs/node/commit/24a2791173)] - **doc**: remove usage of you in n-api doc (Michael Dawson) [#18528](https://github.com/nodejs/node/pull/18528)
+* [[`74086e19f2`](https://github.com/nodejs/node/commit/74086e19f2)] - **doc**: remove uannecessary Require (Michael Dawson) [#18184](https://github.com/nodejs/node/pull/18184)
+* [[`fed2136857`](https://github.com/nodejs/node/commit/fed2136857)] - **doc**: napi: make header style consistent (Ali Ijaz Sheikh) [#18122](https://github.com/nodejs/node/pull/18122)
+* [[`e04386a363`](https://github.com/nodejs/node/commit/e04386a363)] - **doc**: napi: fix unbalanced emphasis (Ali Ijaz Sheikh) [#18122](https://github.com/nodejs/node/pull/18122)
+* [[`3d8e1aaf48`](https://github.com/nodejs/node/commit/3d8e1aaf48)] - **doc**: updates examples to use NULL (Michael Dawson) [#18008](https://github.com/nodejs/node/pull/18008)
+* [[`173f29763e`](https://github.com/nodejs/node/commit/173f29763e)] - **doc**: update example in module registration (Franziska Hinkelmann) [#17424](https://github.com/nodejs/node/pull/17424)
+* [[`c6852126fd`](https://github.com/nodejs/node/commit/c6852126fd)] - **doc**: use "JavaScript" instead of "Javascript" (Rich Trott) [#17163](https://github.com/nodejs/node/pull/17163)
+* [[`35dc8bab9e`](https://github.com/nodejs/node/commit/35dc8bab9e)] - **doc**: document common pattern for instanceof checks (Michael Dawson) [#16699](https://github.com/nodejs/node/pull/16699)
+* [[`22490dcb91`](https://github.com/nodejs/node/commit/22490dcb91)] - **doc**: fix typos in N-API (Swathi Kalahastri) [#16911](https://github.com/nodejs/node/pull/16911)
+* [[`55fabd7337`](https://github.com/nodejs/node/commit/55fabd7337)] - **doc**: fix a typo in n-api documentation (Vipin Menon) [#16879](https://github.com/nodejs/node/pull/16879)
+* [[`0c67f21bcf`](https://github.com/nodejs/node/commit/0c67f21bcf)] - **doc**: update to use NAPI\_AUTO\_LENGTH (Michael Dawson) [#16187](https://github.com/nodejs/node/pull/16187)
+* [[`5c2bba0931`](https://github.com/nodejs/node/commit/5c2bba0931)] - **doc**: fix some links (Vse Mozhet Byt) [#16202](https://github.com/nodejs/node/pull/16202)
+* [[`e9a6dffc65`](https://github.com/nodejs/node/commit/e9a6dffc65)] - **doc**: fix outdated code sample in n-api.md (rebornix) [#15581](https://github.com/nodejs/node/pull/15581)
+* [[`ca69f1dfe7`](https://github.com/nodejs/node/commit/ca69f1dfe7)] - **doc**: fix new nits in links (Vse Mozhet Byt) [#15449](https://github.com/nodejs/node/pull/15449)
+* [[`a766802bee`](https://github.com/nodejs/node/commit/a766802bee)] - **doc**: fix doc for napi\_get\_value\_string\_utf8 (Daniel Taveras) [#14529](https://github.com/nodejs/node/pull/14529)
+* [[`b0f09a2ee6`](https://github.com/nodejs/node/commit/b0f09a2ee6)] - **doc**: added napi\_get\_value\_string\_latin1 (Kyle Farnung) [#14678](https://github.com/nodejs/node/pull/14678)
+* [[`fbcc962727`](https://github.com/nodejs/node/commit/fbcc962727)] - **doc**: delint (Refael Ackermann) [#14707](https://github.com/nodejs/node/pull/14707)
+* [[`831de617b0`](https://github.com/nodejs/node/commit/831de617b0)] - **doc**: document napi\_finalize() signature (cjihrig) [#14230](https://github.com/nodejs/node/pull/14230)
+* [[`4b9773effa`](https://github.com/nodejs/node/commit/4b9773effa)] - **doc**: fix some links (Vse Mozhet Byt) [#14400](https://github.com/nodejs/node/pull/14400)
+* [[`36185b343b`](https://github.com/nodejs/node/commit/36185b343b)] - **doc**: doc lifetime of n-api last error info (Michael Dawson) [#13939](https://github.com/nodejs/node/pull/13939)
+* [[`cc3a4af7c8`](https://github.com/nodejs/node/commit/cc3a4af7c8)] - **doc**: fix a few n-api doc issues (Michael Dawson) [#13650](https://github.com/nodejs/node/pull/13650)
+* [[`1e91d5804d`](https://github.com/nodejs/node/commit/1e91d5804d)] - **doc**: fix out of date napi\_callback doc (XadillaX) [#13570](https://github.com/nodejs/node/pull/13570)
+* [[`c5ae39e401`](https://github.com/nodejs/node/commit/c5ae39e401)] - **doc**: fix napi\_create\_\*\_error signatures in n-api (Jamen Marzonie) [#13544](https://github.com/nodejs/node/pull/13544)
+* [[`35a3cbb5dd`](https://github.com/nodejs/node/commit/35a3cbb5dd)] - **doc**: fix out of date sections in n-api doc (Michael Dawson) [#13508](https://github.com/nodejs/node/pull/13508)
+* [[`a06cc4684f`](https://github.com/nodejs/node/commit/a06cc4684f)] - **doc**: fix typo "ndapi" in n-api.md (Jamen Marz) [#13484](https://github.com/nodejs/node/pull/13484)
+* [[`82f31ff4af`](https://github.com/nodejs/node/commit/82f31ff4af)] - **doc**: add ref to option to enable n-api (Michael Dawson) [#13406](https://github.com/nodejs/node/pull/13406)
+* [[`17fe21e83d`](https://github.com/nodejs/node/commit/17fe21e83d)] - **doc**: fix typo in n-api.md (JongChan Choi) [#13323](https://github.com/nodejs/node/pull/13323)
+* [[`2e2905266e`](https://github.com/nodejs/node/commit/2e2905266e)] - **doc**: fix title/function name mismatch (Michael Dawson) [#13123](https://github.com/nodejs/node/pull/13123)
+* [[`75e91fe5c8`](https://github.com/nodejs/node/commit/75e91fe5c8)] - **doc**: add reference to node\_api.h in docs (Michael Dawson) [#13084](https://github.com/nodejs/node/pull/13084)
+* [[`0f74ee5cbf`](https://github.com/nodejs/node/commit/0f74ee5cbf)] - **doc**: clarify operation of napi\_cancel\_async\_work (Michael Dawson) [#12974](https://github.com/nodejs/node/pull/12974)
+* [[`5b045374ed`](https://github.com/nodejs/node/commit/5b045374ed)] - **doc**: clarify node.js addons are c++ (Beth Griggs) [#12898](https://github.com/nodejs/node/pull/12898)
+* [[`6bcd6d49d5`](https://github.com/nodejs/node/commit/6bcd6d49d5)] - **doc**: fix broken links in n-api doc (Michael Dawson) [#12889](https://github.com/nodejs/node/pull/12889)
+* [[`3e388cf819`](https://github.com/nodejs/node/commit/3e388cf819)] - **doc**: Add initial documentation for N-API (Michael Dawson) [#12549](https://github.com/nodejs/node/pull/12549)
+* [[`4d67369c1b`](https://github.com/nodejs/node/commit/4d67369c1b)] - **doc**: fix various nits (Vse Mozhet Byt) [#19743](https://github.com/nodejs/node/pull/19743)
+* [[`057c80b088`](https://github.com/nodejs/node/commit/057c80b088)] - **doc**: move Fedor to TSC Emeritus (Myles Borins) [#18752](https://github.com/nodejs/node/pull/18752)
+* [[`bf72ee667e`](https://github.com/nodejs/node/commit/bf72ee667e)] - **doc**: add mmarchini to collaborators (Matheus Marchini) [#18740](https://github.com/nodejs/node/pull/18740)
+* [[`280af052d8`](https://github.com/nodejs/node/commit/280af052d8)] - **doc**: add history for url.parse (Steven) [#18685](https://github.com/nodejs/node/pull/18685)
+* [[`29b0d3b104`](https://github.com/nodejs/node/commit/29b0d3b104)] - **doc**: add devsnek to collaborators (Gus Caplan) [#18679](https://github.com/nodejs/node/pull/18679)
+* [[`dc6dc8232f`](https://github.com/nodejs/node/commit/dc6dc8232f)] - **doc**: add section for strategic initiatives (Michael Dawson) [#17104](https://github.com/nodejs/node/pull/17104)
+* [[`6b348d4483`](https://github.com/nodejs/node/commit/6b348d4483)] - **doc**: modify the return value of request.write() (陈刚) [#18526](https://github.com/nodejs/node/pull/18526)
+* [[`dd4d075e51`](https://github.com/nodejs/node/commit/dd4d075e51)] - **doc**: be more explicit in the sypnosis (Tim O. Peters) [#17977](https://github.com/nodejs/node/pull/17977)
+* [[`0067bccf6f`](https://github.com/nodejs/node/commit/0067bccf6f)] - **doc**: fix description of createDecipheriv (Tobias Nießen) [#18651](https://github.com/nodejs/node/pull/18651)
+* [[`bc2f0a5120`](https://github.com/nodejs/node/commit/bc2f0a5120)] - **doc**: linkify missing types (Vse Mozhet Byt) [#18444](https://github.com/nodejs/node/pull/18444)
+* [[`32089bcbc1`](https://github.com/nodejs/node/commit/32089bcbc1)] - **doc**: streamline README intro (Rich Trott) [#18483](https://github.com/nodejs/node/pull/18483)
+* [[`43839f1601`](https://github.com/nodejs/node/commit/43839f1601)] - **doc**: move Brian White to TSC Emeriti list (Rich Trott) [#18482](https://github.com/nodejs/node/pull/18482)
+* [[`27d3c1a0f4`](https://github.com/nodejs/node/commit/27d3c1a0f4)] - **doc**: add Gibson Fahnestock to TSC (Rich Trott) [#18481](https://github.com/nodejs/node/pull/18481)
+* [[`67fd520539`](https://github.com/nodejs/node/commit/67fd520539)] - **doc**: reorder section on updating PR branch (Ali Ijaz Sheikh) [#18355](https://github.com/nodejs/node/pull/18355)
+* [[`f81a69aefe`](https://github.com/nodejs/node/commit/f81a69aefe)] - **fs**: fix `createReadStream(…, {end: n})` for non-seekable fds (Anna Henningsen) [#19329](https://github.com/nodejs/node/pull/19329)
+* [[`18acad349c`](https://github.com/nodejs/node/commit/18acad349c)] - **http**: make socketPath work with no agent (Luigi Pinca) [#19425](https://github.com/nodejs/node/pull/19425)
+* [[`1edadebaa0`](https://github.com/nodejs/node/commit/1edadebaa0)] - **http**: allow \_httpMessage to be GC'ed (Luigi Pinca) [#18865](https://github.com/nodejs/node/pull/18865)
+* [[`dbe70b744c`](https://github.com/nodejs/node/commit/dbe70b744c)] - **http**: free the parser before emitting 'upgrade' (Luigi Pinca) [#18209](https://github.com/nodejs/node/pull/18209)
+* [[`77a405b92f`](https://github.com/nodejs/node/commit/77a405b92f)] - **lib**: set process.execPath on OpenBSD (Aaron Bieber) [#18543](https://github.com/nodejs/node/pull/18543)
+* [[`3aa5b7d939`](https://github.com/nodejs/node/commit/3aa5b7d939)] - **n-api**: add more `int64\_t` tests (Kyle Farnung) [#19402](https://github.com/nodejs/node/pull/19402)
+* [[`abd9fd6797`](https://github.com/nodejs/node/commit/abd9fd6797)] - **n-api**: back up env before finalize (Gabriel Schulhof) [#19718](https://github.com/nodejs/node/pull/19718)
+* [[`e6ccdfbde3`](https://github.com/nodejs/node/commit/e6ccdfbde3)] - **n-api**: ensure in-module exceptions are propagated (Gabriel Schulhof) [#19537](https://github.com/nodejs/node/pull/19537)
+* [[`c6d0a66ef2`](https://github.com/nodejs/node/commit/c6d0a66ef2)] - **n-api**: bump version of n-api supported (Michael Dawson) [#19497](https://github.com/nodejs/node/pull/19497)
+* [[`c16a705416`](https://github.com/nodejs/node/commit/c16a705416)] - **n-api**: re-write test\_make\_callback (Gabriel Schulhof) [#19448](https://github.com/nodejs/node/pull/19448)
+* [[`49cd4fad89`](https://github.com/nodejs/node/commit/49cd4fad89)] - **n-api**: add napi\_fatal\_exception (Mathias Buus) [#19337](https://github.com/nodejs/node/pull/19337)
+* [[`eb29266878`](https://github.com/nodejs/node/commit/eb29266878)] - **n-api**: add missing exception checking (Michael Dawson) [#19362](https://github.com/nodejs/node/pull/19362)
+* [[`2c1190a93d`](https://github.com/nodejs/node/commit/2c1190a93d)] - **n-api**: take n-api out of experimental (Michael Dawson) [#19262](https://github.com/nodejs/node/pull/19262)
+* [[`ce1447920e`](https://github.com/nodejs/node/commit/ce1447920e)] - **n-api**: resolve promise in test (Gabriel Schulhof) [#19245](https://github.com/nodejs/node/pull/19245)
+* [[`a8237efaf1`](https://github.com/nodejs/node/commit/a8237efaf1)] - **n-api**: update documentation (Gabriel Schulhof) [#19078](https://github.com/nodejs/node/pull/19078)
+* [[`af62c8fff7`](https://github.com/nodejs/node/commit/af62c8fff7)] - **n-api**: update reference test (Gabriel Schulhof) [#19086](https://github.com/nodejs/node/pull/19086)
+* [[`d2463745a7`](https://github.com/nodejs/node/commit/d2463745a7)] - **n-api**: fix object test (Gabriel Schulhof) [#19039](https://github.com/nodejs/node/pull/19039)
+* [[`516c287f8e`](https://github.com/nodejs/node/commit/516c287f8e)] - **n-api**: remove extra reference from test (Gabriel Schulhof) [#18542](https://github.com/nodejs/node/pull/18542)
+* [[`a8dec487f7`](https://github.com/nodejs/node/commit/a8dec487f7)] - **n-api**: add methods to open/close callback scope (Michael Dawson) [#18089](https://github.com/nodejs/node/pull/18089)
+* [[`c09a7134e7`](https://github.com/nodejs/node/commit/c09a7134e7)] - **n-api**: wrap control flow macro in do/while (Ben Noordhuis) [#18532](https://github.com/nodejs/node/pull/18532)
+* [[`b565ba2d82`](https://github.com/nodejs/node/commit/b565ba2d82)] - **n-api**: implement wrapping using private properties (Gabriel Schulhof) [#18311](https://github.com/nodejs/node/pull/18311)
+* [[`d9df8cfe77`](https://github.com/nodejs/node/commit/d9df8cfe77)] - **n-api**: change assert ok check to notStrictEqual. (Aaron Kau) [#18414](https://github.com/nodejs/node/pull/18414)
+* [[`2e24a0bfe7`](https://github.com/nodejs/node/commit/2e24a0bfe7)] - **n-api**: throw RangeError napi\_create\_typedarray() (Jinho Bang) [#18037](https://github.com/nodejs/node/pull/18037)
+* [[`62427bbed9`](https://github.com/nodejs/node/commit/62427bbed9)] - **n-api**: expose n-api version in process.versions (Michael Dawson) [#18067](https://github.com/nodejs/node/pull/18067)
+* [[`bb99f31f30`](https://github.com/nodejs/node/commit/bb99f31f30)] - **n-api**: throw RangeError in napi\_create\_dataview() with invalid range (Jinho Bang) [#17869](https://github.com/nodejs/node/pull/17869)
+* [[`65ea7abd55`](https://github.com/nodejs/node/commit/65ea7abd55)] - **n-api**: fix memory leak in napi\_async\_destroy() (alnyan) [#17714](https://github.com/nodejs/node/pull/17714)
+* [[`d4284a464b`](https://github.com/nodejs/node/commit/d4284a464b)] - **n-api**: use nullptr instead of NULL in node\_api.cc (Daniel Bevenius) [#17276](https://github.com/nodejs/node/pull/17276)
+* [[`f4391b95ee`](https://github.com/nodejs/node/commit/f4391b95ee)] - **n-api**: add helper for addons to get the event loop (Anna Henningsen) [#17109](https://github.com/nodejs/node/pull/17109)
+* [[`3c84db624a`](https://github.com/nodejs/node/commit/3c84db624a)] - **n-api**: unexpose symbols and remove EXTERNAL\_NAPI (Gabriel Schulhof) [#16234](https://github.com/nodejs/node/pull/16234)
+* [[`55aab6bf01`](https://github.com/nodejs/node/commit/55aab6bf01)] - **n-api**: check against invalid handle scope usage (Anna Henningsen) [#16201](https://github.com/nodejs/node/pull/16201)
+* [[`169b53e788`](https://github.com/nodejs/node/commit/169b53e788)] - **n-api**: use module name macro (Michael Dawson) [#16185](https://github.com/nodejs/node/pull/16185)
+* [[`32412a8ded`](https://github.com/nodejs/node/commit/32412a8ded)] - **n-api**: make changes for source compatibility (Gabriel Schulhof) [#16102](https://github.com/nodejs/node/pull/16102)
+* [[`00d094f9c3`](https://github.com/nodejs/node/commit/00d094f9c3)] - **n-api**: add check for large strings (Michael Dawson) [#15611](https://github.com/nodejs/node/pull/15611)
+* [[`2bc8a59915`](https://github.com/nodejs/node/commit/2bc8a59915)] - **n-api**: fix warning about size\_t compare with int (Sampson Gao) [#15508](https://github.com/nodejs/node/pull/15508)
+* [[`5e29823d1d`](https://github.com/nodejs/node/commit/5e29823d1d)] - **n-api**: remove n-api module loading flag (Gabriel Schulhof) [#14902](https://github.com/nodejs/node/pull/14902)
+* [[`f31b50cfc7`](https://github.com/nodejs/node/commit/f31b50cfc7)] - **n-api**: add optional string length parameters (Sampson Gao) [#15343](https://github.com/nodejs/node/pull/15343)
+* [[`fe87a5944b`](https://github.com/nodejs/node/commit/fe87a5944b)] - **n-api**: napi\_is\_construct\_call-\>napi\_get\_new\_target (Sampson Gao) [#14698](https://github.com/nodejs/node/pull/14698)
+* [[`5eadd6249d`](https://github.com/nodejs/node/commit/5eadd6249d)] - **n-api**: Context for custom async operations (Jason Ginchereau) [#15189](https://github.com/nodejs/node/pull/15189)
+* [[`50cb48b55c`](https://github.com/nodejs/node/commit/50cb48b55c)] - **n-api**: refactor napi\_addon\_register\_func (Taylor Woll) [#15088](https://github.com/nodejs/node/pull/15088)
+* [[`156a8b6069`](https://github.com/nodejs/node/commit/156a8b6069)] - **n-api**: change async resource name to napi\_value (Jason Ginchereau) [#14697](https://github.com/nodejs/node/pull/14697)
+* [[`7588eead2a`](https://github.com/nodejs/node/commit/7588eead2a)] - **n-api**: use AsyncResource for Work tracking (Anna Henningsen) [#14697](https://github.com/nodejs/node/pull/14697)
+* [[`676cff48bd`](https://github.com/nodejs/node/commit/676cff48bd)] - **n-api**: stop creating references to primitives (Gabriel Schulhof) [#15289](https://github.com/nodejs/node/pull/15289)
+* [[`3b4708b025`](https://github.com/nodejs/node/commit/3b4708b025)] - **n-api**: implement napi\_run\_script (Gabriel Schulhof) [#15216](https://github.com/nodejs/node/pull/15216)
+* [[`ac5b904808`](https://github.com/nodejs/node/commit/ac5b904808)] - **n-api**: adds function to adjust external memory (Chris Young) [#14310](https://github.com/nodejs/node/pull/14310)
+* [[`278a2d069f`](https://github.com/nodejs/node/commit/278a2d069f)] - **n-api**: implement promise (Gabriel Schulhof) [#14365](https://github.com/nodejs/node/pull/14365)
+* [[`73cc251f50`](https://github.com/nodejs/node/commit/73cc251f50)] - **n-api**: add ability to remove a wrapping (Gabriel Schulhof) [#14658](https://github.com/nodejs/node/pull/14658)
+* [[`951adbef3d`](https://github.com/nodejs/node/commit/951adbef3d)] - **n-api**: add napi\_get\_node\_version (Anna Henningsen) [#14696](https://github.com/nodejs/node/pull/14696)
+* [[`b29eb693a0`](https://github.com/nodejs/node/commit/b29eb693a0)] - **n-api**: optimize number API performance (Jason Ginchereau) [#14573](https://github.com/nodejs/node/pull/14573)
+* [[`bd032a158a`](https://github.com/nodejs/node/commit/bd032a158a)] - **n-api**: add support for DataView (Shivanth MP) [#14382](https://github.com/nodejs/node/pull/14382)
+* [[`86b101cb60`](https://github.com/nodejs/node/commit/86b101cb60)] - **n-api**: re-use napi\_env between modules (Gabriel Schulhof) [#14217](https://github.com/nodejs/node/pull/14217)
+* [[`1acab66df4`](https://github.com/nodejs/node/commit/1acab66df4)] - **n-api**: directly create Local from Persistent (Kyle Farnung) [#14211](https://github.com/nodejs/node/pull/14211)
+* [[`f4d1cae634`](https://github.com/nodejs/node/commit/f4d1cae634)] - **n-api**: add fast paths for integer getters (Anna Henningsen) [#14393](https://github.com/nodejs/node/pull/14393)
+* [[`aad36b2cd4`](https://github.com/nodejs/node/commit/aad36b2cd4)] - **n-api**: add napi\_fatal\_error API (Kyle Farnung) [#13971](https://github.com/nodejs/node/pull/13971)
+* [[`57be12ed97`](https://github.com/nodejs/node/commit/57be12ed97)] - **n-api**: add code parameter to error helpers (Michael Dawson) [#13988](https://github.com/nodejs/node/pull/13988)
+* [[`cd3015408e`](https://github.com/nodejs/node/commit/cd3015408e)] - **n-api**: wrap test macros in do/while (Kyle Farnung) [#14095](https://github.com/nodejs/node/pull/14095)
+* [[`7973bd3e63`](https://github.com/nodejs/node/commit/7973bd3e63)] - **n-api**: Implement stricter wrapping (Gabriel Schulhof) [#13872](https://github.com/nodejs/node/pull/13872)
+* [[`5b0c57cfeb`](https://github.com/nodejs/node/commit/5b0c57cfeb)] - **n-api**: fix warning in test\_general (Daniel Bevenius) [#14104](https://github.com/nodejs/node/pull/14104)
+* [[`a5517d80bb`](https://github.com/nodejs/node/commit/a5517d80bb)] - **n-api**: add napi\_has\_own\_property() (cjihrig) [#14063](https://github.com/nodejs/node/pull/14063)
+* [[`8e2a26d3d0`](https://github.com/nodejs/node/commit/8e2a26d3d0)] - **n-api**: fix -Wmaybe-uninitialized compiler warning (Ben Noordhuis) [#14053](https://github.com/nodejs/node/pull/14053)
+* [[`33821c3087`](https://github.com/nodejs/node/commit/33821c3087)] - **n-api**: use Maybe version of Object::SetPrototype() (Ben Noordhuis) [#14053](https://github.com/nodejs/node/pull/14053)
+* [[`80cf25a8a5`](https://github.com/nodejs/node/commit/80cf25a8a5)] - **n-api**: add napi\_delete\_property() (cjihrig) [#13934](https://github.com/nodejs/node/pull/13934)
+* [[`cadec3b37e`](https://github.com/nodejs/node/commit/cadec3b37e)] - **n-api**: add napi\_delete\_element() (cjihrig) [#13949](https://github.com/nodejs/node/pull/13949)
+* [[`97b628ba8e`](https://github.com/nodejs/node/commit/97b628ba8e)] - **n-api**: fix section title typo (Kyle Farnung) [#13972](https://github.com/nodejs/node/pull/13972)
+* [[`c3eb187bd9`](https://github.com/nodejs/node/commit/c3eb187bd9)] - **n-api**: avoid crash in napi\_escape\_scope() (Michael Dawson) [#13651](https://github.com/nodejs/node/pull/13651)
+* [[`919556f27a`](https://github.com/nodejs/node/commit/919556f27a)] - **n-api**: enable napi\_wrap() to work with any object (Jason Ginchereau) [#13250](https://github.com/nodejs/node/pull/13250)
+* [[`86c0ebf4e2`](https://github.com/nodejs/node/commit/86c0ebf4e2)] - **n-api**: add napi\_get\_version (Michael Dawson) [#13207](https://github.com/nodejs/node/pull/13207)
+* [[`70281ba1be`](https://github.com/nodejs/node/commit/70281ba1be)] - **n-api**: Retain last code when getting error info (Jason Ginchereau) [#13087](https://github.com/nodejs/node/pull/13087)
+* [[`8d3162d9e6`](https://github.com/nodejs/node/commit/8d3162d9e6)] - **n-api**: remove compiler warning (Anna Henningsen) [#13014](https://github.com/nodejs/node/pull/13014)
+* [[`a128219a48`](https://github.com/nodejs/node/commit/a128219a48)] - **n-api**: Handle fatal exception in async callback (Jason Ginchereau) [#12838](https://github.com/nodejs/node/pull/12838)
+* [[`2e36365d56`](https://github.com/nodejs/node/commit/2e36365d56)] - **n-api**: napi\_get\_cb\_info should fill array (Jason Ginchereau) [#12863](https://github.com/nodejs/node/pull/12863)
+* [[`7507d1e0e6`](https://github.com/nodejs/node/commit/7507d1e0e6)] - **n-api**: remove unnecessary try-catch bracket from certain APIs (Gabriel Schulhof) [#12705](https://github.com/nodejs/node/pull/12705)
+* [[`49d74c648d`](https://github.com/nodejs/node/commit/49d74c648d)] - **n-api**: Sync with back-compat changes (Jason Ginchereau) [#12674](https://github.com/nodejs/node/pull/12674)
+* [[`bc252509ca`](https://github.com/nodejs/node/commit/bc252509ca)] - **n-api**: Reference and external tests (Jason Ginchereau) [#12551](https://github.com/nodejs/node/pull/12551)
+* [[`c560db9ece`](https://github.com/nodejs/node/commit/c560db9ece)] - **n-api**: Enable scope and ref APIs during exception (Jason Ginchereau) [#12524](https://github.com/nodejs/node/pull/12524)
+* [[`8287e7671a`](https://github.com/nodejs/node/commit/8287e7671a)] - **n-api**: tighten null-checking and clean up last error (Gabriel Schulhof) [#12539](https://github.com/nodejs/node/pull/12539)
+* [[`f5cfa09ca4`](https://github.com/nodejs/node/commit/f5cfa09ca4)] - **n-api**: remove napi\_get\_value\_string\_length() (Jason Ginchereau) [#12496](https://github.com/nodejs/node/pull/12496)
+* [[`c44f6ffc3c`](https://github.com/nodejs/node/commit/c44f6ffc3c)] - **n-api**: fix coverity scan report (Michael Dawson) [#12365](https://github.com/nodejs/node/pull/12365)
+* [[`9bf8e9d48c`](https://github.com/nodejs/node/commit/9bf8e9d48c)] - **n-api**: add string api for latin1 encoding (Sampson Gao) [#12368](https://github.com/nodejs/node/pull/12368)
+* [[`eb51d42d2b`](https://github.com/nodejs/node/commit/eb51d42d2b)] - **n-api**: fix -Wmismatched-tags compiler warning (Ben Noordhuis) [#12333](https://github.com/nodejs/node/pull/12333)
+* [[`d82fd2a9a0`](https://github.com/nodejs/node/commit/d82fd2a9a0)] - **n-api**: implement async helper methods (taylor.woll) [#12250](https://github.com/nodejs/node/pull/12250)
+* [[`c127b71526`](https://github.com/nodejs/node/commit/c127b71526)] - **n-api**: change napi\_callback to return napi\_value (Taylor Woll) [#12248](https://github.com/nodejs/node/pull/12248)
+* [[`2a726223ea`](https://github.com/nodejs/node/commit/2a726223ea)] - **n-api**: cache Symbol.hasInstance (Gabriel Schulhof) [#12246](https://github.com/nodejs/node/pull/12246)
+* [[`db36ca5f91`](https://github.com/nodejs/node/commit/db36ca5f91)] - **n-api**: Update property attrs enum to match JS spec (Jason Ginchereau) [#12240](https://github.com/nodejs/node/pull/12240)
+* [[`1e6d3bb841`](https://github.com/nodejs/node/commit/1e6d3bb841)] - **n-api**: create napi\_env as a real structure (Gabriel Schulhof) [#12195](https://github.com/nodejs/node/pull/12195)
+* [[`f1bdbd17d0`](https://github.com/nodejs/node/commit/f1bdbd17d0)] - **n-api**: break dep between v8 and napi attributes (Michael Dawson) [#12191](https://github.com/nodejs/node/pull/12191)
+* [[`a9562fe30c`](https://github.com/nodejs/node/commit/a9562fe30c)] - **n-api**: add support for abi stable module API (Jason Ginchereau) [#11975](https://github.com/nodejs/node/pull/11975)
+* [[`aa0fb7761e`](https://github.com/nodejs/node/commit/aa0fb7761e)] - **n-api,test**: add int64 bounds tests (Kyle Farnung) [#19309](https://github.com/nodejs/node/pull/19309)
+* [[`3f6d80e25c`](https://github.com/nodejs/node/commit/3f6d80e25c)] - **n-api,test**: add a new.target test to addons-napi (Taylor Woll) [#19236](https://github.com/nodejs/node/pull/19236)
+* [[`011b53e28f`](https://github.com/nodejs/node/commit/011b53e28f)] - **n-api,test**: use module name macro (Gabriel Schulhof) [#16146](https://github.com/nodejs/node/pull/16146)
+* [[`a6af97f76c`](https://github.com/nodejs/node/commit/a6af97f76c)] - **napi**: initialize and check status properly (Gabriel Schulhof) [#12283](https://github.com/nodejs/node/pull/12283)
+* [[`9b36811d8e`](https://github.com/nodejs/node/commit/9b36811d8e)] - **napi**: supress invalid coverity leak message (Michael Dawson) [#12192](https://github.com/nodejs/node/pull/12192)
+* [[`269c2f3ad9`](https://github.com/nodejs/node/commit/269c2f3ad9)] - **net**: remove redundant code from \_writeGeneric() (Luigi Pinca) [#18429](https://github.com/nodejs/node/pull/18429)
+* [[`988cca841e`](https://github.com/nodejs/node/commit/988cca841e)] - **process**: fix reading zero-length env vars on win32 (Anna Henningsen) [#18463](https://github.com/nodejs/node/pull/18463)
+* [[`72a5710b71`](https://github.com/nodejs/node/commit/72a5710b71)] - **readline**: update references to archived repository (Tobias Nießen) [#17924](https://github.com/nodejs/node/pull/17924)
+* [[`b20c278a7c`](https://github.com/nodejs/node/commit/b20c278a7c)] - **src**: add napi\_handle\_scope\_mismatch to msg list (neta) [#17161](https://github.com/nodejs/node/pull/17161)
+* [[`0ef0b342e9`](https://github.com/nodejs/node/commit/0ef0b342e9)] - **src**: replace assert with CHECK\_LE in node\_api.cc (Ben Noordhuis) [#14514](https://github.com/nodejs/node/pull/14514)
+* [[`a8c73748db`](https://github.com/nodejs/node/commit/a8c73748db)] - **src**: correct endif comment SRC\_NODE\_API\_H\_\_ (Daniel Bevenius) [#13190](https://github.com/nodejs/node/pull/13190)
+* [[`0ca2dad3a6`](https://github.com/nodejs/node/commit/0ca2dad3a6)] - **src**: free memory before re-setting URLHost value (Ivan Filenko) [#18357](https://github.com/nodejs/node/pull/18357)
+* [[`e54b8e8184`](https://github.com/nodejs/node/commit/e54b8e8184)] - **stream**: cleanup() when unpiping all streams. (陈刚) [#18266](https://github.com/nodejs/node/pull/18266)
+* [[`8ab8d6afd6`](https://github.com/nodejs/node/commit/8ab8d6afd6)] - **stream**: fix y.pipe(x)+y.pipe(x)+y.unpipe(x) (Anna Henningsen) [#12746](https://github.com/nodejs/node/pull/12746)
+* [[`8f830ca896`](https://github.com/nodejs/node/commit/8f830ca896)] - **stream**: remove unreachable code (Luigi Pinca) [#18239](https://github.com/nodejs/node/pull/18239)
+* [[`64c83d7da9`](https://github.com/nodejs/node/commit/64c83d7da9)] - **stream**: simplify `src.\_readableState` to `state` (陈刚) [#18264](https://github.com/nodejs/node/pull/18264)
+* [[`7c58045470`](https://github.com/nodejs/node/commit/7c58045470)] - **test**: remove unnecessary timer (cjihrig) [#18719](https://github.com/nodejs/node/pull/18719)
+* [[`c90b77ed5d`](https://github.com/nodejs/node/commit/c90b77ed5d)] - **test**: convert new tests to use error types (Jack Horton) [#18581](https://github.com/nodejs/node/pull/18581)
+* [[`7f37dc9c48`](https://github.com/nodejs/node/commit/7f37dc9c48)] - **test**: improve error message output (Bhavani Shankar) [#18498](https://github.com/nodejs/node/pull/18498)
+* [[`59249a1768`](https://github.com/nodejs/node/commit/59249a1768)] - **test**: show pending exception error in napi tests (Ben Wilcox) [#18413](https://github.com/nodejs/node/pull/18413)
+* [[`eceb70b584`](https://github.com/nodejs/node/commit/eceb70b584)] - **test**: refactor addons-napi/test\_exception/test.js (Rich Trott) [#18340](https://github.com/nodejs/node/pull/18340)
+* [[`b3806ecd39`](https://github.com/nodejs/node/commit/b3806ecd39)] - **test**: fixed typos in napi test (furstenheim) [#18148](https://github.com/nodejs/node/pull/18148)
+* [[`a6c277e2eb`](https://github.com/nodejs/node/commit/a6c277e2eb)] - **test**: remove ambiguous error messages from test\_error (Nicholas Drane) [#17812](https://github.com/nodejs/node/pull/17812)
+* [[`412cc17748`](https://github.com/nodejs/node/commit/412cc17748)] - **test**: remove literals that obscure assert messages (Rich Trott) [#17642](https://github.com/nodejs/node/pull/17642)
+* [[`86ddd03608`](https://github.com/nodejs/node/commit/86ddd03608)] - **test**: add unhandled rejection guard (babygoat) [#17275](https://github.com/nodejs/node/pull/17275)
+* [[`e54b58c024`](https://github.com/nodejs/node/commit/e54b58c024)] - **test**: replace assert.throws with common.expectsError (Leko) [#17445](https://github.com/nodejs/node/pull/17445)
+* [[`976f32d189`](https://github.com/nodejs/node/commit/976f32d189)] - **test**: refactor addons-napi/test\_promise/test.js (ka3e) [#16814](https://github.com/nodejs/node/pull/16814)
+* [[`2476ab9619`](https://github.com/nodejs/node/commit/2476ab9619)] - **test**: improve error emssage reporting in testNapiRun.js (Paul Ashfield) [#16821](https://github.com/nodejs/node/pull/16821)
+* [[`d4c04e05f7`](https://github.com/nodejs/node/commit/d4c04e05f7)] - **test**: improve assert messages in napi exception test (Paul Blanche) [#16820](https://github.com/nodejs/node/pull/16820)
+* [[`c14207c77b`](https://github.com/nodejs/node/commit/c14207c77b)] - **test**: add detailed message for assertion failure (Attila Gonda) [#16812](https://github.com/nodejs/node/pull/16812)
+* [[`d31792fcbe`](https://github.com/nodejs/node/commit/d31792fcbe)] - **test**: use default assertion messages (John Byrne) [#16808](https://github.com/nodejs/node/pull/16808)
+* [[`087d213f67`](https://github.com/nodejs/node/commit/087d213f67)] - **test**: include actual value in assertion message (Matthew Cantelon) [#15935](https://github.com/nodejs/node/pull/15935)
+* [[`9cc435dc85`](https://github.com/nodejs/node/commit/9cc435dc85)] - **test**: improve message for assert.strictEqual() (Jayson D. Henkel) [#16013](https://github.com/nodejs/node/pull/16013)
+* [[`ebbd07dd27`](https://github.com/nodejs/node/commit/ebbd07dd27)] - **test**: remove redundant error messages (Christina Chan) [#16043](https://github.com/nodejs/node/pull/16043)
+* [[`5bba809e01`](https://github.com/nodejs/node/commit/5bba809e01)] - **test**: cleaned up assert messages (mrgorbo) [#16032](https://github.com/nodejs/node/pull/16032)
+* [[`53bd313739`](https://github.com/nodejs/node/commit/53bd313739)] - **test**: fix race condition in addon test (Kinnan Kwok) [#16037](https://github.com/nodejs/node/pull/16037)
+* [[`37acd806be`](https://github.com/nodejs/node/commit/37acd806be)] - **test**: remove template literal (Emily Ford) [#15953](https://github.com/nodejs/node/pull/15953)
+* [[`31c97178c1`](https://github.com/nodejs/node/commit/31c97178c1)] - **test**: remove unused parameters (Daniil Shakir) [#14968](https://github.com/nodejs/node/pull/14968)
+* [[`b59eddd082`](https://github.com/nodejs/node/commit/b59eddd082)] - **test**: use regular expressions in throw assertions (Vincent Xue) [#14318](https://github.com/nodejs/node/pull/14318)
+* [[`06b1273464`](https://github.com/nodejs/node/commit/06b1273464)] - **test**: changed error message validator (Pratik Jain) [#14443](https://github.com/nodejs/node/pull/14443)
+* [[`3f3eaf9961`](https://github.com/nodejs/node/commit/3f3eaf9961)] - **test**: replace string concat with template literal (Song, Bintao Garfield) [#14269](https://github.com/nodejs/node/pull/14269)
+* [[`48274213b1`](https://github.com/nodejs/node/commit/48274213b1)] - **test**: handle missing V8 tests in n-api test (cjihrig) [#14123](https://github.com/nodejs/node/pull/14123)
+* [[`7f126c2069`](https://github.com/nodejs/node/commit/7f126c2069)] - **test**: add coverage for napi\_typeof (Michael Dawson) [#13990](https://github.com/nodejs/node/pull/13990)
+* [[`a0cf9b7a73`](https://github.com/nodejs/node/commit/a0cf9b7a73)] - **test**: verify napi\_get\_property() walks prototype (cjihrig) [#13961](https://github.com/nodejs/node/pull/13961)
+* [[`1e25062fa1`](https://github.com/nodejs/node/commit/1e25062fa1)] - **test**: add coverage for napi\_property\_descriptor (Michael Dawson) [#13510](https://github.com/nodejs/node/pull/13510)
+* [[`eb422796cd`](https://github.com/nodejs/node/commit/eb422796cd)] - **test**: fix build warning in addons-napi/test\_object (Jason Ginchereau) [#13412](https://github.com/nodejs/node/pull/13412)
+* [[`9d70b43bdc`](https://github.com/nodejs/node/commit/9d70b43bdc)] - **test**: consolidate n-api test addons - part2 (Michael Dawson) [#13380](https://github.com/nodejs/node/pull/13380)
+* [[`06cf9480d3`](https://github.com/nodejs/node/commit/06cf9480d3)] - **test**: consolidate n-api test addons (Michael Dawson) [#13317](https://github.com/nodejs/node/pull/13317)
+* [[`652d3218fe`](https://github.com/nodejs/node/commit/652d3218fe)] - **test**: Make N-API weak-ref GC tests asynchronous (Jason Ginchereau) [#13121](https://github.com/nodejs/node/pull/13121)
+* [[`0dac33d4f2`](https://github.com/nodejs/node/commit/0dac33d4f2)] - **test**: improve n-api coverage for typed arrays (Michael Dawson) [#13244](https://github.com/nodejs/node/pull/13244)
+* [[`1829d25907`](https://github.com/nodejs/node/commit/1829d25907)] - **test**: add coverage for napi\_has\_named\_property (Michael Dawson) [#13178](https://github.com/nodejs/node/pull/13178)
+* [[`d89afe8685`](https://github.com/nodejs/node/commit/d89afe8685)] - **test**: increase n-api constructor coverage (Michael Dawson) [#13124](https://github.com/nodejs/node/pull/13124)
+* [[`71aa251671`](https://github.com/nodejs/node/commit/71aa251671)] - **test**: Improve N-API test coverage (Michael Dawson) [#13044](https://github.com/nodejs/node/pull/13044)
+* [[`314f22dcf4`](https://github.com/nodejs/node/commit/314f22dcf4)] - **test**: improve N-API test coverage (Michael Dawson) [#13006](https://github.com/nodejs/node/pull/13006)
+* [[`263a633d5e`](https://github.com/nodejs/node/commit/263a633d5e)] - **test**: add common.mustCall() to NAPI exception test (Rich Trott) [#12959](https://github.com/nodejs/node/pull/12959)
+* [[`5936f7c9bb`](https://github.com/nodejs/node/commit/5936f7c9bb)] - **test**: improve n-api array func coverage (Michael Dawson) [#12890](https://github.com/nodejs/node/pull/12890)
+* [[`ce03977f30`](https://github.com/nodejs/node/commit/ce03977f30)] - **test**: fix napi test\_reference for recent V8 (Michaël Zasso) [#12864](https://github.com/nodejs/node/pull/12864)
+* [[`dd7665a68e`](https://github.com/nodejs/node/commit/dd7665a68e)] - **test**: port test for make\_callback to n-api (Hitesh Kanwathirtha) [#12409](https://github.com/nodejs/node/pull/12409)
+* [[`f09677fdba`](https://github.com/nodejs/node/commit/f09677fdba)] - **test**: add coverage for error apis (Michael Dawson) [#12729](https://github.com/nodejs/node/pull/12729)
+* [[`1785f3cf44`](https://github.com/nodejs/node/commit/1785f3cf44)] - **test**: fix warning in n-api reference test (Michael Dawson) [#12730](https://github.com/nodejs/node/pull/12730)
+* [[`5d2afb2174`](https://github.com/nodejs/node/commit/5d2afb2174)] - **test**: replace indexOf with includes (gwer) [#12604](https://github.com/nodejs/node/pull/12604)
+* [[`fcb019f6ea`](https://github.com/nodejs/node/commit/fcb019f6ea)] - **test**: add coverage for napi\_cancel\_async\_work (Michael Dawson) [#12575](https://github.com/nodejs/node/pull/12575)
+* [[`72c5d976f1`](https://github.com/nodejs/node/commit/72c5d976f1)] - **test**: test doc'd napi\_get\_value\_int32 behaviour (Michael Dawson) [#12633](https://github.com/nodejs/node/pull/12633)
+* [[`d9f3e0dd83`](https://github.com/nodejs/node/commit/d9f3e0dd83)] - ***Revert*** "**test**: port test for make\_callback to n-api" (James M Snell) [#12475](https://github.com/nodejs/node/pull/12475)
+* [[`a003777d96`](https://github.com/nodejs/node/commit/a003777d96)] - **test**: port test for make\_callback to n-api (Hitesh Kanwathirtha) [#12409](https://github.com/nodejs/node/pull/12409)
+* [[`577f327d2c`](https://github.com/nodejs/node/commit/577f327d2c)] - **test**: fix compiler warning in n-api test (Anna Henningsen) [#12318](https://github.com/nodejs/node/pull/12318)
+* [[`f8c2585fe0`](https://github.com/nodejs/node/commit/f8c2585fe0)] - **test**: add second argument to assert.throws (Michaël Zasso) [#12270](https://github.com/nodejs/node/pull/12270)
+* [[`6bf3d04d6c`](https://github.com/nodejs/node/commit/6bf3d04d6c)] - **test**: improve test coverage for n-api (Michael Dawson) [#12327](https://github.com/nodejs/node/pull/12327)
+* [[`d799b1cb61`](https://github.com/nodejs/node/commit/d799b1cb61)] - **test**: update a few tests to work on OpenBSD (Aaron Bieber) [#18543](https://github.com/nodejs/node/pull/18543)
+* [[`bc883fb136`](https://github.com/nodejs/node/commit/bc883fb136)] - **test**: refactor test-http-abort-before-end (cjihrig) [#18508](https://github.com/nodejs/node/pull/18508)
+* [[`44ab85018c`](https://github.com/nodejs/node/commit/44ab85018c)] - **test**: fix flaky timers-block-eventloop test (Anatoli Papirovski) [#18567](https://github.com/nodejs/node/pull/18567)
+* [[`5bcf668f42`](https://github.com/nodejs/node/commit/5bcf668f42)] - **test**: use correct size in test-stream-buffer-list (Luigi Pinca) [#18239](https://github.com/nodejs/node/pull/18239)
+* [[`f3c6febedf`](https://github.com/nodejs/node/commit/f3c6febedf)] - **test**: update references to archived repository (Tobias Nießen) [#17924](https://github.com/nodejs/node/pull/17924)
+* [[`b2a2a55271`](https://github.com/nodejs/node/commit/b2a2a55271)] - **test**: verify the shell option works properly on execFile (jvelezpo) [#18384](https://github.com/nodejs/node/pull/18384)
+* [[`fd7d1990db`](https://github.com/nodejs/node/commit/fd7d1990db)] - **test**: remove orphaned entries from status (Kyle Farnung) [#19042](https://github.com/nodejs/node/pull/19042)
+* [[`5ca8dee8cb`](https://github.com/nodejs/node/commit/5ca8dee8cb)] - **test**: remove n-api intermediate files (Gabriel Schulhof) [#19375](https://github.com/nodejs/node/pull/19375)
+* [[`46aed5800f`](https://github.com/nodejs/node/commit/46aed5800f)] - **test**: make common.mustNotCall show file:linenumber (Lance Ball) [#17257](https://github.com/nodejs/node/pull/17257)
+* [[`4d2efa2415`](https://github.com/nodejs/node/commit/4d2efa2415)] - **test**: remove mark flaky for moved test (Beth Griggs) [#19069](https://github.com/nodejs/node/pull/19069)
+* [[`502781c1d7`](https://github.com/nodejs/node/commit/502781c1d7)] - **test**: fix spelling in test case comments (Tobias Nießen) [#18018](https://github.com/nodejs/node/pull/18018)
+* [[`b2bf6c873f`](https://github.com/nodejs/node/commit/b2bf6c873f)] - **test,lib,doc**: use function declarations (Rich Trott) [#12711](https://github.com/nodejs/node/pull/12711)
+* [[`a91b1b928c`](https://github.com/nodejs/node/commit/a91b1b928c)] - **win, build**: fix intl-none option (Birunthan Mohanathas) [#18292](https://github.com/nodejs/node/pull/18292)
+* [[`6ff763bd66`](https://github.com/nodejs/node/commit/6ff763bd66)] - **win, build**: fix without-intl option (Bartosz Sosnowski) [#17614](https://github.com/nodejs/node/pull/17614)
+
## 2018-03-29, Version 6.14.1 'Boron' (LTS), @MylesBorins
diff --git a/doc/guides/writing-tests.md b/doc/guides/writing-tests.md
index aac098640aec9e..cc87886656c06d 100644
--- a/doc/guides/writing-tests.md
+++ b/doc/guides/writing-tests.md
@@ -92,7 +92,7 @@ The test checks functionality in the `http` module.
Most tests use the `assert` module to confirm expectations of the test.
The require statements are sorted in
-[ASCII](http://man7.org/linux/man-pages/man7/ascii.7.html) order (digits, upper
+[ASCII][] order (digits, upper
case, `_`, lower case).
### **Lines 10-21**
@@ -252,9 +252,9 @@ assert.throws(
For performance considerations, we only use a selected subset of ES.Next
features in JavaScript code in the `lib` directory. However, when writing
tests, for the ease of backporting, it is encouraged to use those ES.Next
-features that can be used directly without a flag in [all maintained branches]
-(https://github.com/nodejs/lts). [node.green](http://node.green/) lists
-available features in each release.
+features that can be used directly without a flag in
+[all maintained branches][]. [node.green][] lists available features
+in each release.
For example:
@@ -279,8 +279,7 @@ functions worked correctly with the `beforeExit` event, then it might be named
### Web Platform Tests
Some of the tests for the WHATWG URL implementation (named
-`test-whatwg-url-*.js`) are imported from the
-[Web Platform Tests Project](https://github.com/w3c/web-platform-tests/tree/master/url).
+`test-whatwg-url-*.js`) are imported from the [Web Platform Tests Project][].
These imported tests will be wrapped like this:
```js
diff --git a/doc/node.1 b/doc/node.1
index 1e1877376dc3aa..b36f176983787f 100644
--- a/doc/node.1
+++ b/doc/node.1
@@ -108,6 +108,11 @@ Throw errors for deprecations.
.BR \-\-no\-warnings
Silence all process warnings (including deprecations).
+.TP
+.BR \-\-napi\-modules
+Enable loading native modules compiled with the ABI-stable Node.js API (N-API)
+(experimental).
+
.TP
.BR \-\-trace\-warnings
Print stack traces for process warnings (including deprecations).
diff --git a/lib/_http_agent.js b/lib/_http_agent.js
index f11fa9fd6d2f5f..ce4cd05005e211 100644
--- a/lib/_http_agent.js
+++ b/lib/_http_agent.js
@@ -249,6 +249,7 @@ function installListeners(agent, s, options) {
s.removeListener('close', onClose);
s.removeListener('free', onFree);
s.removeListener('agentRemove', onRemove);
+ s._httpMessage = null;
}
s.on('agentRemove', onRemove);
}
diff --git a/lib/_http_client.js b/lib/_http_client.js
index 4d71ec594743f4..ea181cff31a482 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -138,7 +138,11 @@ function ClientRequest(options, cb) {
timeout: self.timeout,
rejectUnauthorized: !!options.rejectUnauthorized
};
- const newSocket = self.agent.createConnection(optionsPath, oncreate);
+ const newSocket = self.agent
+ ? self.agent.createConnection(optionsPath, oncreate)
+ : typeof options.createConnection === 'function'
+ ? options.createConnection(optionsPath, oncreate)
+ : net.createConnection(optionsPath);
if (newSocket && !called) {
called = true;
self.onSocket(newSocket);
@@ -376,6 +380,7 @@ function socketOnData(d) {
socket.removeListener('data', socketOnData);
socket.removeListener('end', socketOnEnd);
parser.finish();
+ freeParser(parser, req, socket);
var bodyHead = d.slice(bytesParsed, d.length);
@@ -398,7 +403,6 @@ function socketOnData(d) {
// Got Upgrade header or CONNECT method, but have no handler.
socket.destroy();
}
- freeParser(parser, req, socket);
} else if (parser.incoming && parser.incoming.complete &&
// When the status code is 100 (Continue), the server will
// send a final response after this client sends a request
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 541ef1c305d8bf..21268eacd02748 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -499,10 +499,13 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
src.once('end', endFn);
dest.on('unpipe', onunpipe);
- function onunpipe(readable) {
+ function onunpipe(readable, unpipeInfo) {
debug('onunpipe');
if (readable === src) {
- cleanup();
+ if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
+ unpipeInfo.hasUnpiped = true;
+ cleanup();
+ }
}
}
@@ -561,8 +564,8 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
if (((state.pipesCount === 1 && state.pipes === dest) ||
(state.pipesCount > 1 && state.pipes.indexOf(dest) !== -1)) &&
!cleanedUp) {
- debug('false write response, pause', src._readableState.awaitDrain);
- src._readableState.awaitDrain++;
+ debug('false write response, pause', state.awaitDrain);
+ state.awaitDrain++;
increasedAwaitDrain = true;
}
src.pause();
@@ -628,6 +631,7 @@ function pipeOnDrain(src) {
Readable.prototype.unpipe = function(dest) {
var state = this._readableState;
+ var unpipeInfo = { hasUnpiped: false };
// if we're not piping anywhere, then do nothing.
if (state.pipesCount === 0)
@@ -647,7 +651,7 @@ Readable.prototype.unpipe = function(dest) {
state.pipesCount = 0;
state.flowing = false;
if (dest)
- dest.emit('unpipe', this);
+ dest.emit('unpipe', this, unpipeInfo);
return this;
}
@@ -662,7 +666,7 @@ Readable.prototype.unpipe = function(dest) {
state.flowing = false;
for (var i = 0; i < len; i++)
- dests[i].emit('unpipe', this);
+ dests[i].emit('unpipe', this, { hasUnpiped: false });
return this;
}
@@ -676,7 +680,7 @@ Readable.prototype.unpipe = function(dest) {
if (state.pipesCount === 1)
state.pipes = state.pipes[0];
- dest.emit('unpipe', this);
+ dest.emit('unpipe', this, unpipeInfo);
return this;
};
diff --git a/lib/fs.js b/lib/fs.js
index 5efccceb544d20..b0d117673d6bfc 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1919,8 +1919,7 @@ function ReadStream(path, options) {
this.flags = options.flags === undefined ? 'r' : options.flags;
this.mode = options.mode === undefined ? 0o666 : options.mode;
- this.start = typeof this.fd !== 'number' && options.start === undefined ?
- 0 : options.start;
+ this.start = options.start;
this.end = options.end;
this.autoClose = options.autoClose === undefined ? true : options.autoClose;
this.pos = undefined;
@@ -1943,6 +1942,12 @@ function ReadStream(path, options) {
this.pos = this.start;
}
+ // Backwards compatibility: Make sure `end` is a number regardless of `start`.
+ // TODO(addaleax): Make the above typecheck not depend on `start` instead.
+ // (That is a semver-major change).
+ if (typeof this.end !== 'number')
+ this.end = Infinity;
+
if (typeof this.fd !== 'number')
this.open();
@@ -1996,6 +2001,8 @@ ReadStream.prototype._read = function(n) {
if (this.pos !== undefined)
toRead = Math.min(this.end - this.pos + 1, toRead);
+ else
+ toRead = Math.min(this.end - this.bytesRead + 1, toRead);
// already read everything we were supposed to read!
// treat as EOF.
diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js
index 4b5a500adc598e..3cadf1e399e51b 100644
--- a/lib/internal/bootstrap_node.js
+++ b/lib/internal/bootstrap_node.js
@@ -66,6 +66,13 @@
// URL::ToObject() method is used.
NativeModule.require('internal/url');
+ // On OpenBSD process.execPath will be relative unless we
+ // get the full path before process.execPath is used.
+ if (process.platform === 'openbsd') {
+ const { realpathSync } = NativeModule.require('fs');
+ process.execPath = realpathSync.native(process.execPath);
+ }
+
Object.defineProperty(process, 'argv0', {
enumerable: true,
configurable: false,
diff --git a/lib/internal/streams/BufferList.js b/lib/internal/streams/BufferList.js
index 76da94bc83d977..9d3badf5b378bd 100644
--- a/lib/internal/streams/BufferList.js
+++ b/lib/internal/streams/BufferList.js
@@ -58,8 +58,6 @@ BufferList.prototype.join = function(s) {
BufferList.prototype.concat = function(n) {
if (this.length === 0)
return Buffer.alloc(0);
- if (this.length === 1)
- return this.head.data;
const ret = Buffer.allocUnsafe(n >>> 0);
var p = this.head;
var i = 0;
diff --git a/lib/net.js b/lib/net.js
index ac036534d6b402..e91542fb2467a9 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -710,13 +710,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
// Retain chunks
if (err === 0) req._chunks = chunks;
} else {
- var enc;
- if (data instanceof Buffer) {
- enc = 'buffer';
- } else {
- enc = encoding;
- }
- err = createWriteReq(req, this._handle, data, enc);
+ err = createWriteReq(req, this._handle, data, encoding);
}
if (err)
diff --git a/lib/readline.js b/lib/readline.js
index ca99fe15c0a593..a3a3452abacc8c 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -700,7 +700,8 @@ Interface.prototype._moveCursor = function(dx) {
Interface.prototype._ttyWrite = function(s, key) {
key = key || {};
- // Ignore escape key - Fixes #2876
+ // Ignore escape key, fixes
+ // https://github.com/nodejs/node-v0.x-archive/issues/2876.
if (key.name === 'escape') return;
if (key.ctrl && key.shift) {
diff --git a/node.gyp b/node.gyp
index 8a7af9bfd1e50a..7458e84621b983 100644
--- a/node.gyp
+++ b/node.gyp
@@ -21,6 +21,8 @@
'node_v8_options%': '',
'node_enable_v8_vtunejit%': 'false',
'node_core_target_name%': 'node',
+ 'node_lib_target_name%': 'node_lib',
+ 'node_intermediate_lib_type%': 'static_library',
'library_files': [
'lib/internal/bootstrap_node.js',
'lib/_debug_agent.js',
@@ -111,6 +113,17 @@
'conditions': [
[ 'node_shared=="true"', {
'node_target_type%': 'shared_library',
+ 'conditions': [
+ ['OS=="aix"', {
+ # For AIX, always generate static library first,
+ # It needs an extra step to generate exp and
+ # then use both static lib and exp to create
+ # shared lib.
+ 'node_intermediate_lib_type': 'static_library',
+ }, {
+ 'node_intermediate_lib_type': 'shared_library',
+ }],
+ ],
}, {
'node_target_type%': 'executable',
}],
@@ -127,7 +140,81 @@
'targets': [
{
'target_name': '<(node_core_target_name)',
- 'type': '<(node_target_type)',
+ 'type': 'executable',
+ 'sources': [
+ 'src/node_main.cc'
+ ],
+ 'include_dirs': [
+ 'src',
+ 'deps/v8/include',
+ ],
+ 'conditions': [
+ [ 'node_intermediate_lib_type=="static_library" and '
+ 'node_shared=="true" and OS=="aix"', {
+ # For AIX, shared lib is linked by static lib and .exp. In the
+ # case here, the executable needs to link to shared lib.
+ # Therefore, use 'node_aix_shared' target to generate the
+ # shared lib and then executable.
+ 'dependencies': [ 'node_aix_shared' ],
+ }, {
+ 'dependencies': [ '<(node_lib_target_name)' ],
+ }],
+ [ 'node_intermediate_lib_type=="static_library" and '
+ 'node_shared=="false"', {
+ 'includes': [
+ 'node.gypi'
+ ],
+ 'xcode_settings': {
+ 'OTHER_LDFLAGS': [
+ '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)'
+ '<(node_core_target_name)<(STATIC_LIB_SUFFIX)',
+ ],
+ },
+ 'msvs_settings': {
+ 'VCLinkerTool': {
+ 'AdditionalOptions': [
+ '/WHOLEARCHIVE:<(PRODUCT_DIR)\\lib\\'
+ '<(node_core_target_name)<(STATIC_LIB_SUFFIX)',
+ ],
+ },
+ },
+ 'conditions': [
+ ['OS in "linux freebsd openbsd solaris android"', {
+ 'ldflags': [
+ '-Wl,--whole-archive,<(OBJ_DIR)/<(STATIC_LIB_PREFIX)'
+ '<(node_core_target_name)<(STATIC_LIB_SUFFIX)',
+ '-Wl,--no-whole-archive',
+ ],
+ }],
+ [ 'OS=="win"', {
+ 'sources': [ 'src/res/node.rc' ],
+ 'conditions': [
+ [ 'node_use_etw=="true"', {
+ 'sources': [
+ 'tools/msvs/genfiles/node_etw_provider.rc'
+ ],
+ }],
+ [ 'node_use_perfctr=="true"', {
+ 'sources': [
+ 'tools/msvs/genfiles/node_perfctr_provider.rc',
+ ],
+ }]
+ ],
+ }],
+ ],
+ }],
+ [ 'node_intermediate_lib_type=="shared_library" and OS=="win"', {
+ # On Windows, having the same name for both executable and shared
+ # lib causes filename collision. Need a different PRODUCT_NAME for
+ # the executable and rename it back to node.exe later
+ 'product_name': '<(node_core_target_name)-win',
+ }],
+ ],
+ },
+ {
+ 'target_name': '<(node_lib_target_name)',
+ 'type': '<(node_intermediate_lib_type)',
+ 'product_name': '<(node_core_target_name)',
'dependencies': [
'node_js2c#host',
@@ -139,7 +226,6 @@
'include_dirs': [
'src',
- 'tools/msvs/genfiles',
'deps/uv/src/ares',
'<(SHARED_INTERMEDIATE_DIR)',
],
@@ -155,13 +241,16 @@
'src/handle_wrap.cc',
'src/js_stream.cc',
'src/node.cc',
+ 'src/node_api_backport.cc',
+ 'src/node_api.cc',
+ 'src/node_api.h',
+ 'src/node_api_types.h',
'src/node_buffer.cc',
'src/node_config.cc',
'src/node_constants.cc',
'src/node_contextify.cc',
'src/node_file.cc',
'src/node_http_parser.cc',
- 'src/node_main.cc',
'src/node_os.cc',
'src/node_revert.cc',
'src/node_url.cc',
@@ -249,7 +338,168 @@
'conditions': [
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
'product_extension': '<(shlib_suffix)',
- }]
+ }],
+ ['node_shared=="true" and OS=="aix"', {
+ 'product_name': 'node_base',
+ }],
+ [ 'v8_inspector=="true"', {
+ 'defines': [
+ 'HAVE_INSPECTOR=1',
+ ],
+ 'sources': [
+ 'src/inspector_agent.cc',
+ 'src/inspector_socket.cc',
+ 'src/inspector_agent.h',
+ 'src/inspector_socket.h',
+ ],
+ 'dependencies': [
+ 'deps/v8_inspector/third_party/v8_inspector/platform/'
+ 'v8_inspector/v8_inspector.gyp:v8_inspector_stl',
+ 'deps/v8_inspector/third_party/v8_inspector/platform/'
+ 'v8_inspector/v8_inspector.gyp:protocol_sources_stl',
+ 'v8_inspector_compress_protocol_json#host',
+ ],
+ 'include_dirs': [
+ 'deps/v8_inspector/third_party/v8_inspector',
+ '<(SHARED_INTERMEDIATE_DIR)/blink', # for inspector
+ ],
+ }, {
+ 'defines': [ 'HAVE_INSPECTOR=0' ]
+ }],
+ [ 'OS=="win"', {
+ 'sources': [
+ 'src/backtrace_win32.cc',
+ ],
+ 'conditions': [
+ [ 'node_intermediate_lib_type!="static_library"', {
+ 'sources': [
+ 'src/res/node.rc',
+ ],
+ }],
+ ],
+ 'defines!': [
+ 'NODE_PLATFORM="win"',
+ ],
+ 'defines': [
+ 'FD_SETSIZE=1024',
+ # we need to use node's preferred "win32" rather than gyp's preferred "win"
+ 'NODE_PLATFORM="win32"',
+ '_UNICODE=1',
+ ],
+ 'libraries': [ '-lpsapi.lib' ]
+ }, { # POSIX
+ 'defines': [ '__POSIX__' ],
+ 'sources': [ 'src/backtrace_posix.cc' ],
+ }],
+ [ 'node_use_etw=="true"', {
+ 'defines': [ 'HAVE_ETW=1' ],
+ 'dependencies': [ 'node_etw' ],
+ 'include_dirs': [
+ 'src',
+ 'tools/msvs/genfiles',
+ '<(SHARED_INTERMEDIATE_DIR)' # for node_natives.h
+ ],
+ 'sources': [
+ 'src/node_win32_etw_provider.h',
+ 'src/node_win32_etw_provider-inl.h',
+ 'src/node_win32_etw_provider.cc',
+ 'src/node_dtrace.cc',
+ 'tools/msvs/genfiles/node_etw_provider.h',
+ ],
+ 'conditions': [
+ ['node_intermediate_lib_type != "static_library"', {
+ 'sources': [
+ 'tools/msvs/genfiles/node_etw_provider.rc',
+ ],
+ }],
+ ],
+ }],
+ [ 'node_use_perfctr=="true"', {
+ 'defines': [ 'HAVE_PERFCTR=1' ],
+ 'dependencies': [ 'node_perfctr' ],
+ 'include_dirs': [
+ 'src',
+ 'tools/msvs/genfiles',
+ '<(SHARED_INTERMEDIATE_DIR)' # for node_natives.h
+ ],
+ 'sources': [
+ 'src/node_win32_perfctr_provider.h',
+ 'src/node_win32_perfctr_provider.cc',
+ 'src/node_counters.cc',
+ 'src/node_counters.h',
+ ],
+ 'conditions': [
+ ['node_intermediate_lib_type != "static_library"', {
+ 'sources': [
+ 'tools/msvs/genfiles/node_perfctr_provider.rc',
+ ],
+ }],
+ ],
+ }],
+ [ 'node_use_lttng=="true"', {
+ 'defines': [ 'HAVE_LTTNG=1' ],
+ 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
+ 'libraries': [ '-llttng-ust' ],
+ 'include_dirs': [
+ 'src',
+ 'tools/msvs/genfiles',
+ '<(SHARED_INTERMEDIATE_DIR)' # for node_natives.h
+ ],
+ 'sources': [
+ 'src/node_lttng.cc'
+ ],
+ }],
+ [ 'node_use_dtrace=="true"', {
+ 'defines': [ 'HAVE_DTRACE=1' ],
+ 'dependencies': [
+ 'node_dtrace_header',
+ 'specialize_node_d',
+ ],
+ 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
+ #
+ # DTrace is supported on linux, solaris, mac, and bsd. There are
+ # three object files associated with DTrace support, but they're
+ # not all used all the time:
+ #
+ # node_dtrace.o all configurations
+ # node_dtrace_ustack.o not supported on mac and linux
+ # node_dtrace_provider.o All except OS X. "dtrace -G" is not
+ # used on OS X.
+ #
+ # Note that node_dtrace_provider.cc and node_dtrace_ustack.cc do not
+ # actually exist. They're listed here to trick GYP into linking the
+ # corresponding object files into the final "node" executable. These
+ # object files are generated by "dtrace -G" using custom actions
+ # below, and the GYP-generated Makefiles will properly build them when
+ # needed.
+ #
+ 'sources': [ 'src/node_dtrace.cc' ],
+ 'conditions': [
+ [ 'OS=="linux"', {
+ 'sources': [
+ '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_provider.o'
+ ],
+ }],
+ [ 'OS!="mac" and OS!="linux"', {
+ 'sources': [
+ 'src/node_dtrace_ustack.cc',
+ 'src/node_dtrace_provider.cc',
+ ]
+ }
+ ] ]
+ } ],
+ [ 'node_use_openssl=="true"', {
+ 'sources': [
+ 'src/node_crypto.cc',
+ 'src/node_crypto_bio.cc',
+ 'src/node_crypto_clienthello.cc',
+ 'src/node_crypto.h',
+ 'src/node_crypto_bio.h',
+ 'src/node_crypto_clienthello.h',
+ 'src/tls_wrap.cc',
+ 'src/tls_wrap.h'
+ ],
+ }],
],
'direct_dependent_settings': {
'defines': [
@@ -398,7 +648,7 @@
[ 'node_use_dtrace=="false" and node_use_etw=="false"', {
'inputs': [ 'src/notrace_macros.py' ]
}],
- ['node_use_lttng=="false"', {
+ [ 'node_use_lttng=="false"', {
'inputs': [ 'src/nolttng_macros.py' ]
}],
[ 'node_use_perfctr=="false"', {
@@ -451,10 +701,10 @@
{
'action_name': 'node_dtrace_provider_o',
'inputs': [
- '<(OBJ_DIR)/node/src/node_dtrace.o',
+ '<(OBJ_DIR)/<(node_lib_target_name)/src/node_dtrace.o',
],
'outputs': [
- '<(OBJ_DIR)/node/src/node_dtrace_provider.o'
+ '<(OBJ_DIR)/<(node_lib_target_name)/src/node_dtrace_provider.o'
],
'action': [ 'dtrace', '-G', '-xnolibs', '-s', 'src/node_provider.d',
'<@(_inputs)', '-o', '<@(_outputs)' ]
@@ -504,7 +754,7 @@
'<(SHARED_INTERMEDIATE_DIR)/v8constants.h'
],
'outputs': [
- '<(OBJ_DIR)/node/src/node_dtrace_ustack.o'
+ '<(OBJ_DIR)/<(node_lib_target_name)/src/node_dtrace_ustack.o'
],
'conditions': [
[ 'target_arch=="ia32" or target_arch=="arm"', {
@@ -551,12 +801,41 @@
} ],
]
},
+ {
+ # When using shared lib to build executable in Windows, in order to avoid
+ # filename collision, the executable name is node-win.exe. Need to rename
+ # it back to node.exe
+ 'target_name': 'rename_node_bin_win',
+ 'type': 'none',
+ 'dependencies': [
+ '<(node_core_target_name)',
+ ],
+ 'conditions': [
+ [ 'OS=="win" and node_intermediate_lib_type=="shared_library"', {
+ 'actions': [
+ {
+ 'action_name': 'rename_node_bin_win',
+ 'inputs': [
+ '<(PRODUCT_DIR)/<(node_core_target_name)-win.exe'
+ ],
+ 'outputs': [
+ '<(PRODUCT_DIR)/<(node_core_target_name).exe',
+ ],
+ 'action': [
+ 'mv', '<@(_inputs)', '<@(_outputs)',
+ ],
+ },
+ ],
+ } ],
+ ]
+ },
{
'target_name': 'cctest',
'type': 'executable',
'dependencies': [
'<(node_core_target_name)',
+ 'rename_node_bin_win',
'deps/gtest/gtest.gyp:gtest',
'node_js2c#host',
'node_dtrace_header',
@@ -565,18 +844,18 @@
],
'variables': {
- 'OBJ_PATH': '<(OBJ_DIR)/node/src',
- 'OBJ_GEN_PATH': '<(OBJ_DIR)/node/gen',
+ 'OBJ_PATH': '<(OBJ_DIR)/<(node_lib_target_name)/src',
+ 'OBJ_GEN_PATH': '<(OBJ_DIR)/<(node_lib_target_name)/gen',
'OBJ_SUFFIX': 'o',
'conditions': [
['OS=="win"', {
- 'OBJ_PATH': '<(OBJ_DIR)/node',
- 'OBJ_GEN_PATH': '<(OBJ_DIR)/node',
+ 'OBJ_PATH': '<(OBJ_DIR)/<(node_lib_target_name)',
+ 'OBJ_GEN_PATH': '<(OBJ_DIR)/<(node_lib_target_name)',
'OBJ_SUFFIX': 'obj',
}],
['OS=="aix"', {
- 'OBJ_PATH': '<(OBJ_DIR)/node_base/src',
- 'OBJ_GEN_PATH': '<(OBJ_DIR)/node_base/gen',
+ 'OBJ_PATH': '<(OBJ_DIR)/<(node_lib_target_name)/src',
+ 'OBJ_GEN_PATH': '<(OBJ_DIR)/<(node_lib_target_name)/gen',
}],
],
},
@@ -628,41 +907,91 @@
'test/cctest/test_url.cc'
],
- 'sources!': [
- 'src/node_main.cc'
- ],
-
'conditions': [
+ [ 'node_use_openssl=="true"', {
+ 'conditions': [
+ ['node_target_type!="static_library"', {
+ 'libraries': [
+ '<(OBJ_PATH)/node_crypto.<(OBJ_SUFFIX)',
+ '<(OBJ_PATH)/node_crypto_bio.<(OBJ_SUFFIX)',
+ '<(OBJ_PATH)/node_crypto_clienthello.<(OBJ_SUFFIX)',
+ '<(OBJ_PATH)/tls_wrap.<(OBJ_SUFFIX)',
+ ],
+ }],
+ ],
+ 'defines': [
+ 'HAVE_OPENSSL=1',
+ ],
+ }],
+ [ 'node_use_perfctr=="true"', {
+ 'defines': [ 'HAVE_PERFCTR=1' ],
+ 'libraries': [
+ '<(OBJ_PATH)/node_counters.<(OBJ_SUFFIX)',
+ '<(OBJ_PATH)/node_win32_perfctr_provider.<(OBJ_SUFFIX)',
+ ],
+ }],
['v8_inspector=="true"', {
'sources': [
'test/cctest/test_inspector_socket.cc',
],
+ 'dependencies': [
+ 'deps/v8_inspector/third_party/v8_inspector/platform/'
+ 'v8_inspector/v8_inspector.gyp:v8_inspector_stl',
+ 'deps/v8_inspector/third_party/v8_inspector/platform/'
+ 'v8_inspector/v8_inspector.gyp:protocol_sources_stl',
+ 'v8_inspector_compress_protocol_json#host',
+ ],
+ 'include_dirs': [
+ 'deps/v8_inspector/third_party/v8_inspector',
+ '<(SHARED_INTERMEDIATE_DIR)/blink', # for inspector
+ ],
+ 'libraries': [
+ '<(OBJ_PATH)/inspector_agent.<(OBJ_SUFFIX)',
+ '<(OBJ_PATH)/inspector_socket.<(OBJ_SUFFIX)',
+ ],
'conditions': [
[ 'node_shared_openssl=="false" and node_shared=="false"', {
'dependencies': [
'deps/openssl/openssl.gyp:openssl'
]
}],
- [ 'node_shared_http_parser=="false"', {
- 'dependencies': [
- 'deps/http_parser/http_parser.gyp:http_parser'
+ ]
+ }],
+ [ 'node_use_dtrace=="true"', {
+ 'libraries': [
+ '<(OBJ_PATH)/node_dtrace.<(OBJ_SUFFIX)',
+ ],
+ 'conditions': [
+ ['OS!="mac" and OS!="linux"', {
+ 'libraries': [
+ '<(OBJ_PATH)/node_dtrace_provider.<(OBJ_SUFFIX)',
+ '<(OBJ_PATH)/node_dtrace_ustack.<(OBJ_SUFFIX)',
]
}],
- [ 'node_shared_libuv=="false"', {
- 'dependencies': [
- 'deps/uv/uv.gyp:libuv'
+ ['OS=="linux"', {
+ 'libraries': [
+ '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_provider.<(OBJ_SUFFIX)',
]
+ }],
+ ],
+ }, {
+ 'conditions': [
+ [ 'node_use_etw=="true" and OS=="win"', {
+ 'libraries': [
+ '<(OBJ_PATH)/node_dtrace.<(OBJ_SUFFIX)',
+ '<(OBJ_PATH)/node_win32_etw_provider.<(OBJ_SUFFIX)',
+ ],
}]
]
}],
- [ 'node_use_dtrace=="true" and OS!="mac" and OS!="linux"', {
- 'copies': [{
- 'destination': '<(OBJ_DIR)/cctest/src',
- 'files': [
- '<(OBJ_PATH)/node_dtrace_ustack.<(OBJ_SUFFIX)',
- '<(OBJ_PATH)/node_dtrace_provider.<(OBJ_SUFFIX)',
- '<(OBJ_PATH)/node_dtrace.<(OBJ_SUFFIX)',
- ]},
+ [ 'OS=="win"', {
+ 'libraries': [
+ '<(OBJ_PATH)/backtrace_win32.<(OBJ_SUFFIX)',
+ ],
+ }, { # POSIX
+ 'defines': [ '__POSIX__' ],
+ 'libraries': [
+ '<(OBJ_PATH)/backtrace_posix.<(OBJ_SUFFIX)',
],
}],
['OS=="solaris"', {
@@ -673,21 +1002,19 @@
], # end targets
'conditions': [
- ['OS=="aix"', {
+ [ 'OS=="aix" and node_shared=="true"', {
'targets': [
{
- 'target_name': 'node',
+ 'target_name': 'node_aix_shared',
+ 'type': 'shared_library',
+ 'product_name': '<(node_core_target_name)',
+ 'ldflags': [ '--shared' ],
+ 'product_extension': '<(shlib_suffix)',
'conditions': [
- ['node_shared=="true"', {
- 'type': 'shared_library',
- 'ldflags': ['--shared'],
- 'product_extension': '<(shlib_suffix)',
- }, {
- 'type': 'executable',
- }],
['target_arch=="ppc64"', {
'ldflags': [
- '-Wl,-blibpath:/usr/lib:/lib:/opt/freeware/lib/pthread/ppc64'
+ '-Wl,-blibpath:/usr/lib:/lib:'
+ '/opt/freeware/lib/pthread/ppc64'
],
}],
['target_arch=="ppc"', {
@@ -696,45 +1023,20 @@
],
}]
],
- 'dependencies': ['<(node_core_target_name)', 'node_exp'],
-
+ 'includes': [
+ 'node.gypi'
+ ],
+ 'dependencies': [ '<(node_lib_target_name)' ],
'include_dirs': [
'src',
'deps/v8/include',
],
-
'sources': [
- 'src/node_main.cc',
'<@(library_files)',
- # node.gyp is added to the project by default.
'common.gypi',
],
-
- 'ldflags': ['-Wl,-bE:<(PRODUCT_DIR)/node.exp'],
},
- {
- 'target_name': 'node_exp',
- 'type': 'none',
- 'dependencies': [
- '<(node_core_target_name)',
- ],
- 'actions': [
- {
- 'action_name': 'expfile',
- 'inputs': [
- '<(OBJ_DIR)'
- ],
- 'outputs': [
- '<(PRODUCT_DIR)/node.exp'
- ],
- 'action': [
- 'sh', 'tools/create_expfile.sh',
- '<@(_inputs)', '<@(_outputs)'
- ],
- }
- ]
- }
- ], # end targets
+ ]
}], # end aix section
], # end conditions block
}
diff --git a/node.gypi b/node.gypi
index 3b3548fdab5308..baa7e139b525b8 100644
--- a/node.gypi
+++ b/node.gypi
@@ -1,4 +1,29 @@
{
+ # 'force_load' means to include the static libs into the shared lib or
+ # executable. Therefore, it is enabled when building:
+ # 1. The executable and it uses static lib (cctest and node)
+ # 2. The shared lib
+ # Linker optimizes out functions that are not used. When force_load=true,
+ # --whole-archive,force_load and /WHOLEARCHIVE are used to include
+ # all obj files in static libs into the executable or shared lib.
+ 'variables': {
+ 'variables': {
+ 'variables': {
+ 'force_load%': 'true',
+ 'current_type%': '<(_type)',
+ },
+ 'force_load%': '<(force_load)',
+ 'conditions': [
+ ['current_type=="static_library"', {
+ 'force_load': 'false',
+ }],
+ [ 'current_type=="executable" and node_target_type=="shared_library"', {
+ 'force_load': 'false',
+ }]
+ ],
+ },
+ 'force_load%': '<(force_load)',
+ },
'conditions': [
[ 'node_shared=="false"', {
'msvs_settings': {
@@ -36,12 +61,6 @@
[ 'node_v8_options!=""', {
'defines': [ 'NODE_V8_OPTIONS="<(node_v8_options)"'],
}],
- # No node_main.cc for anything except executable
- [ 'node_target_type!="executable"', {
- 'sources!': [
- 'src/node_main.cc',
- ],
- }],
[ 'node_release_urlbase!=""', {
'defines': [
'NODE_RELEASE_URLBASE="<(node_release_urlbase)"',
@@ -66,156 +85,6 @@
'deps/v8/src/third_party/vtune/v8vtune.gyp:v8_vtune'
],
}],
- ['v8_inspector=="true"', {
- 'defines': [
- 'HAVE_INSPECTOR=1',
- ],
- 'sources': [
- 'src/inspector_agent.cc',
- 'src/inspector_socket.cc',
- 'src/inspector_agent.h',
- 'src/inspector_socket.h',
- ],
- 'dependencies': [
- 'deps/v8_inspector/third_party/v8_inspector/platform/'
- 'v8_inspector/v8_inspector.gyp:v8_inspector_stl',
- 'v8_inspector_compress_protocol_json#host',
- ],
- 'include_dirs': [
- 'deps/v8_inspector/third_party/v8_inspector',
- '<(SHARED_INTERMEDIATE_DIR)/blink', # for inspector
- ],
- }, {
- 'defines': [ 'HAVE_INSPECTOR=0' ]
- }],
- [ 'node_use_openssl=="true"', {
- 'defines': [ 'HAVE_OPENSSL=1' ],
- 'sources': [
- 'src/node_crypto.cc',
- 'src/node_crypto_bio.cc',
- 'src/node_crypto_clienthello.cc',
- 'src/node_crypto.h',
- 'src/node_crypto_bio.h',
- 'src/node_crypto_clienthello.h',
- 'src/tls_wrap.cc',
- 'src/tls_wrap.h'
- ],
- 'conditions': [
- ['openssl_fips != ""', {
- 'defines': [ 'NODE_FIPS_MODE' ],
- }],
- [ 'node_shared_openssl=="false"', {
- 'dependencies': [
- './deps/openssl/openssl.gyp:openssl',
-
- # For tests
- './deps/openssl/openssl.gyp:openssl-cli',
- ],
- # Do not let unused OpenSSL symbols to slip away
- 'conditions': [
- # -force_load or --whole-archive are not applicable for
- # the static library
- [ 'node_target_type!="static_library"', {
- 'xcode_settings': {
- 'OTHER_LDFLAGS': [
- '-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)',
- ],
- },
- 'conditions': [
- ['OS in "linux freebsd" and node_shared=="false"', {
- 'ldflags': [
- '-Wl,--whole-archive,'
- '<(OBJ_DIR)/deps/openssl/'
- '<(OPENSSL_PRODUCT)',
- '-Wl,--no-whole-archive',
- ],
- }],
- # openssl.def is based on zlib.def, zlib symbols
- # are always exported.
- ['use_openssl_def==1', {
- 'sources': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'],
- }],
- ['OS=="win" and use_openssl_def==0', {
- 'sources': ['deps/zlib/win32/zlib.def'],
- }],
- ],
- }],
- ],
- }]]
- }, {
- 'defines': [ 'HAVE_OPENSSL=0' ]
- }],
- [ 'node_use_dtrace=="true"', {
- 'defines': [ 'HAVE_DTRACE=1' ],
- 'dependencies': [
- 'node_dtrace_header',
- 'specialize_node_d',
- ],
- 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
-
- #
- # DTrace is supported on linux, solaris, mac, and bsd. There are
- # three object files associated with DTrace support, but they're
- # not all used all the time:
- #
- # node_dtrace.o all configurations
- # node_dtrace_ustack.o not supported on mac and linux
- # node_dtrace_provider.o All except OS X. "dtrace -G" is not
- # used on OS X.
- #
- # Note that node_dtrace_provider.cc and node_dtrace_ustack.cc do not
- # actually exist. They're listed here to trick GYP into linking the
- # corresponding object files into the final "node" executable. These
- # object files are generated by "dtrace -G" using custom actions
- # below, and the GYP-generated Makefiles will properly build them when
- # needed.
- #
- 'sources': [ 'src/node_dtrace.cc' ],
- 'conditions': [
- [ 'OS=="linux"', {
- 'sources': [
- '<(SHARED_INTERMEDIATE_DIR)/node_dtrace_provider.o'
- ],
- }],
- [ 'OS!="mac" and OS!="linux"', {
- 'sources': [
- 'src/node_dtrace_ustack.cc',
- 'src/node_dtrace_provider.cc',
- ]
- }
- ] ]
- } ],
- [ 'node_use_lttng=="true"', {
- 'defines': [ 'HAVE_LTTNG=1' ],
- 'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
- 'libraries': [ '-llttng-ust' ],
- 'sources': [
- 'src/node_lttng.cc'
- ],
- } ],
- [ 'node_use_etw=="true"', {
- 'defines': [ 'HAVE_ETW=1' ],
- 'dependencies': [ 'node_etw' ],
- 'sources': [
- 'src/node_win32_etw_provider.h',
- 'src/node_win32_etw_provider-inl.h',
- 'src/node_win32_etw_provider.cc',
- 'src/node_dtrace.cc',
- 'tools/msvs/genfiles/node_etw_provider.h',
- 'tools/msvs/genfiles/node_etw_provider.rc',
- ]
- } ],
- [ 'node_use_perfctr=="true"', {
- 'defines': [ 'HAVE_PERFCTR=1' ],
- 'dependencies': [ 'node_perfctr' ],
- 'sources': [
- 'src/node_win32_perfctr_provider.h',
- 'src/node_win32_perfctr_provider.cc',
- 'src/node_counters.cc',
- 'src/node_counters.h',
- 'tools/msvs/genfiles/node_perfctr_provider.rc',
- ]
- } ],
[ 'node_no_browser_globals=="true"', {
'defines': [ 'NODE_NO_BROWSER_GLOBALS' ],
} ],
@@ -223,7 +92,7 @@
'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:postmortem-metadata' ],
'conditions': [
# -force_load is not applicable for the static library
- [ 'node_target_type!="static_library"', {
+ [ 'force_load=="true"', {
'xcode_settings': {
'OTHER_LDFLAGS': [
'-Wl,-force_load,<(V8_BASE)',
@@ -248,25 +117,6 @@
'dependencies': [ 'deps/uv/uv.gyp:libuv' ],
}],
- [ 'OS=="win"', {
- 'sources': [
- 'src/backtrace_win32.cc',
- 'src/res/node.rc',
- ],
- 'defines!': [
- 'NODE_PLATFORM="win"',
- ],
- 'defines': [
- 'FD_SETSIZE=1024',
- # we need to use node's preferred "win32" rather than gyp's preferred "win"
- 'NODE_PLATFORM="win32"',
- '_UNICODE=1',
- ],
- 'libraries': [ '-lpsapi.lib' ]
- }, { # POSIX
- 'defines': [ '__POSIX__' ],
- 'sources': [ 'src/backtrace_posix.cc' ],
- }],
[ 'OS=="mac"', {
# linking Corefoundation is needed since certain OSX debugging tools
# like Instruments require it for some features
@@ -289,6 +139,27 @@
'defines': [
'_LINUX_SOURCE_COMPAT',
],
+ 'conditions': [
+ [ 'force_load=="true"', {
+
+ 'actions': [
+ {
+ 'action_name': 'expfile',
+ 'inputs': [
+ '<(OBJ_DIR)'
+ ],
+ 'outputs': [
+ '<(PRODUCT_DIR)/node.exp'
+ ],
+ 'action': [
+ 'sh', 'tools/create_expfile.sh',
+ '<@(_inputs)', '<@(_outputs)'
+ ],
+ }
+ ],
+ 'ldflags': ['-Wl,-bE:<(PRODUCT_DIR)/node.exp', '-Wl,-brtl'],
+ }],
+ ],
}],
[ 'OS=="solaris"', {
'libraries': [
@@ -304,12 +175,14 @@
'NODE_PLATFORM="sunos"',
],
}],
- [ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="false"', {
+ [ '(OS=="freebsd" or OS=="linux") and node_shared=="false"'
+ ' and coverage=="false" and force_load=="true"', {
'ldflags': [ '-Wl,-z,noexecstack',
'-Wl,--whole-archive <(V8_BASE)',
'-Wl,--no-whole-archive' ]
}],
- [ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="true"', {
+ [ '(OS=="freebsd" or OS=="linux") and node_shared=="false"'
+ ' and coverage=="true" and force_load=="true"', {
'ldflags': [ '-Wl,-z,noexecstack',
'-Wl,--whole-archive <(V8_BASE)',
'-Wl,--no-whole-archive',
@@ -324,5 +197,54 @@
[ 'OS=="sunos"', {
'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ],
}],
+
+ [ 'node_use_openssl=="true"', {
+ 'defines': [ 'HAVE_OPENSSL=1' ],
+ 'conditions': [
+ ['openssl_fips != ""', {
+ 'defines': [ 'NODE_FIPS_MODE' ],
+ }],
+ [ 'node_shared_openssl=="false"', {
+ 'dependencies': [
+ './deps/openssl/openssl.gyp:openssl',
+
+ # For tests
+ './deps/openssl/openssl.gyp:openssl-cli',
+ ],
+ 'conditions': [
+ # -force_load or --whole-archive are not applicable for
+ # the static library
+ [ 'force_load=="true"', {
+ 'xcode_settings': {
+ 'OTHER_LDFLAGS': [
+ '-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)',
+ ],
+ },
+ 'conditions': [
+ ['OS in "linux freebsd" and node_shared=="false"', {
+ 'ldflags': [
+ '-Wl,--whole-archive,'
+ '<(OBJ_DIR)/deps/openssl/'
+ '<(OPENSSL_PRODUCT)',
+ '-Wl,--no-whole-archive',
+ ],
+ }],
+ # openssl.def is based on zlib.def, zlib symbols
+ # are always exported.
+ ['use_openssl_def==1', {
+ 'sources': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'],
+ }],
+ ['OS=="win" and use_openssl_def==0', {
+ 'sources': ['deps/zlib/win32/zlib.def'],
+ }],
+ ],
+ }],
+ ],
+ }]]
+
+ }, {
+ 'defines': [ 'HAVE_OPENSSL=0' ]
+ }],
+
],
}
diff --git a/src/env-inl.h b/src/env-inl.h
index 30d7950e93950d..a5e2e176c11df3 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -111,7 +111,7 @@ inline Environment::AsyncCallbackScope::~AsyncCallbackScope() {
env_->makecallback_cntr_--;
}
-inline bool Environment::AsyncCallbackScope::in_makecallback() {
+inline bool Environment::AsyncCallbackScope::in_makecallback() const {
return env_->makecallback_cntr_ > 1;
}
diff --git a/src/env.h b/src/env.h
index c4489857161b75..19c6e84642a963 100644
--- a/src/env.h
+++ b/src/env.h
@@ -62,6 +62,8 @@ namespace node {
V(npn_buffer_private_symbol, "node:npnBuffer") \
V(processed_private_symbol, "node:processed") \
V(selected_npn_buffer_private_symbol, "node:selectedNpnBuffer") \
+ V(napi_env, "node:napi:env") \
+ V(napi_wrapper, "node:napi:wrapper") \
// Strings are per-isolate primitives but Environment proxies them
// for the sake of convenience. Strings should be ASCII-only.
@@ -295,7 +297,7 @@ class Environment {
explicit AsyncCallbackScope(Environment* env);
~AsyncCallbackScope();
- inline bool in_makecallback();
+ inline bool in_makecallback() const;
private:
Environment* env_;
diff --git a/src/node.cc b/src/node.cc
index 8ab9e4d1f45f51..3f4c02413c9aa7 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -2500,7 +2500,9 @@ void DLOpen(const FunctionCallbackInfo& args) {
env->ThrowError("Module did not self-register.");
return;
}
- if (mp->nm_version != NODE_MODULE_VERSION) {
+
+ // -1 is used for N-API modules
+ if ((mp->nm_version != -1) && (mp->nm_version != NODE_MODULE_VERSION)) {
char errmsg[1024];
snprintf(errmsg,
sizeof(errmsg),
@@ -2799,6 +2801,7 @@ static void EnvGetter(Local property,
#else // _WIN32
String::Value key(property);
WCHAR buffer[32767]; // The maximum size allowed for environment variables.
+ SetLastError(ERROR_SUCCESS);
DWORD result = GetEnvironmentVariableW(reinterpret_cast(*key),
buffer,
arraysize(buffer));
@@ -2846,6 +2849,7 @@ static void EnvQuery(Local property,
#else // _WIN32
String::Value key(property);
WCHAR* key_ptr = reinterpret_cast(*key);
+ SetLastError(ERROR_SUCCESS);
if (GetEnvironmentVariableW(key_ptr, nullptr, 0) > 0 ||
GetLastError() == ERROR_SUCCESS) {
rc = 0;
@@ -3191,6 +3195,12 @@ void SetupProcessObject(Environment* env,
"modules",
FIXED_ONE_BYTE_STRING(env->isolate(), node_modules_version));
+ const char node_napi_version[] = NODE_STRINGIFY(NAPI_VERSION);
+ READONLY_PROPERTY(
+ versions,
+ "napi",
+ FIXED_ONE_BYTE_STRING(env->isolate(), node_napi_version));
+
// process._promiseRejectEvent
Local