diff --git a/configure b/configure index c04118e9832b0c..7d13d3c982fc00 100755 --- a/configure +++ b/configure @@ -1140,7 +1140,8 @@ def configure_v8(o): o['variables']['v8_no_strict_aliasing'] = 1 # Work around compiler bugs. o['variables']['v8_optimized_debug'] = 0 # Compile with -O0 in debug builds. o['variables']['v8_random_seed'] = 0 # Use a random seed for hash tables. - o['variables']['v8_promise_internal_field_count'] = 1 # Add internal field to promises for async hooks. + # Add internal field to promises for async hooks and unhandled rejections. + o['variables']['v8_promise_internal_field_count'] = 2 o['variables']['v8_use_snapshot'] = 'false' if options.without_snapshot else 'true' o['variables']['v8_trace_maps'] = 1 if options.trace_maps else 0 o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform) diff --git a/deps/v8/gypfiles/features.gypi b/deps/v8/gypfiles/features.gypi index 69ff763be04ab5..2388ba2729cf3e 100644 --- a/deps/v8/gypfiles/features.gypi +++ b/deps/v8/gypfiles/features.gypi @@ -105,7 +105,7 @@ 'defines': ['ENABLE_DISASSEMBLER',], }], ['v8_promise_internal_field_count!=0', { - 'defines': ['V8_PROMISE_INTERNAL_FIELD_COUNT','v8_promise_internal_field_count'], + 'defines': ['V8_PROMISE_INTERNAL_FIELD_COUNT=<(v8_promise_internal_field_count)'], }], ['v8_enable_gdbjit==1', { 'defines': ['ENABLE_GDB_JIT_INTERFACE',], diff --git a/doc/api/cli.md b/doc/api/cli.md index 637c1cd9050557..53ed119e721d41 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -277,6 +277,33 @@ Write process warnings to the given file instead of printing to stderr. The file will be created if it does not exist, and will be appended to if it does. If an error occurs while attempting to write the warning to the file, the warning will be written to stderr instead. + +### `--unhandled-rejections=mode` + + +See below .. + + + + + + + + + + + + + + + + + + + + ### `--throw-deprecation` + +Setting this environment variable allows fine grained control over the behavior +of unhandled rejections. This may be set to either one of `SILENT`, `WARN`, +`ERROR_ON_GC`, `ERROR` or `STRICT` while the default behavior without using the +environment variable is the same as `WARN`. `WARN` reflects the +[`unhandledRejection hook`][]. The [`unhandledRejection hook`][] functionality +is not influenced by any of these options. + +Setting the environment variable to `SILENT` prevents unhandled rejection +warnings from being logged, even if no [`unhandledRejection hook`][] is +attached. + +If set to `ERROR_ON_GC` unhandled rejections that are [garbage collected][] are +raised as uncaught exceptions. + +If set to `ERROR` all rejections that are not handled after a single +`nextTick()` has passed are raised as uncaught exception. + +If set to `STRICT` all rejections that are not handled synchronous are raised as +uncaught exception. + +Any rejection that is raised as exception can be caught by the +[`uncaughtException hook`][]. Handling promises can be done lazily by adding a +catch handler to the promise chain after the promise was already potentially +rejected. + ### `OPENSSL_CONF=file` +* `err` {Error} The uncaught exception. +* `errorOrigin` {string} Indicates if the exception originates from an + unhandled rejection or from synchronous errors. Can either be `'FROM_PROMISE'` + or `'FROM_ERROR'`. + The `'uncaughtException'` event is emitted when an uncaught JavaScript exception bubbles all the way back to the event loop. By default, Node.js handles such exceptions by printing the stack trace to `stderr` and exiting @@ -159,12 +168,13 @@ behavior. You may also change the [`process.exitCode`][] in provided exit code, otherwise in the presence of such handler the process will exit with 0. -The listener function is called with the `Error` object passed as the only -argument. - ```js -process.on('uncaughtException', (err) => { - fs.writeSync(1, `Caught exception: ${err}\n`); +process.on('uncaughtException', (err, errorOrigin) => { + fs.writeSync( + 1, + `Caught exception: ${err}\n` + + `Exception originated from unhandled rejection: ${errorOrigin}` + ); }); setTimeout(() => { @@ -216,6 +226,10 @@ changes: a process warning. --> +* `reason` {Error|any} The object with which the promise was rejected + (typically an [`Error`][] object). +* `promise` {Promise} The rejected promise. + The `'unhandledRejection'` event is emitted whenever a `Promise` is rejected and no error handler is attached to the promise within a turn of the event loop. When programming with Promises, exceptions are encapsulated as "rejected @@ -224,21 +238,15 @@ are propagated through a `Promise` chain. The `'unhandledRejection'` event is useful for detecting and keeping track of promises that were rejected whose rejections have not yet been handled. -The listener function is called with the following arguments: - -* `reason` {Error|any} The object with which the promise was rejected - (typically an [`Error`][] object). -* `p` the `Promise` that was rejected. - ```js -process.on('unhandledRejection', (reason, p) => { - console.log('Unhandled Rejection at:', p, 'reason:', reason); - // application specific logging, throwing an error, or other logic here +process.on('unhandledRejection', (reason, promise) => { + console.log('Unhandled Rejection at:', promise, 'reason:', reason); + // Application specific logging, throwing an error, or other logic here }); somePromise.then((res) => { - return reportToUser(JSON.pasre(res)); // note the typo (`pasre`) -}); // no `.catch()` or `.then()` + return reportToUser(JSON.pasre(res)); // Note the typo (`pasre`) +}); // No `.catch()` or `.then()` ``` The following will also trigger the `'unhandledRejection'` event to be @@ -251,7 +259,7 @@ function SomeResource() { } const resource = new SomeResource(); -// no .catch or .then on resource.loaded for at least a turn +// No .catch or .then on resource.loaded for at least a turn ``` In this example case, it is possible to track the rejection as a developer error @@ -259,7 +267,7 @@ as would typically be the case for other `'unhandledRejection'` events. To address such failures, a non-operational [`.catch(() => { })`][`promise.catch()`] handler may be attached to `resource.loaded`, which would prevent the `'unhandledRejection'` event from -being emitted. Alternatively, the [`'rejectionHandled'`][] event may be used. +being emitted. ### Event: 'warning'