summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGus Caplan <me@gus.host>2018-10-20 22:08:41 -0500
committerGus Caplan <me@gus.host>2018-10-23 13:05:57 -0500
commit2caf0793c1e60b37851753d2eb219034be57da5f (patch)
treee66d306c504b0c36014ca7079ca9a2fa4930f4dd /lib
parent3516052bee118dce767dd330fa857f6615c5b28a (diff)
downloadandroid-node-v8-2caf0793c1e60b37851753d2eb219034be57da5f.tar.gz
android-node-v8-2caf0793c1e60b37851753d2eb219034be57da5f.tar.bz2
android-node-v8-2caf0793c1e60b37851753d2eb219034be57da5f.zip
lib: trigger uncaught exception handler for microtasks
PR-URL: https://github.com/nodejs/node/pull/23794 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/bootstrap/node.js6
-rw-r--r--lib/internal/queue_microtask.js46
2 files changed, 31 insertions, 21 deletions
diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js
index 2d99885750..bc87801be2 100644
--- a/lib/internal/bootstrap/node.js
+++ b/lib/internal/bootstrap/node.js
@@ -24,7 +24,8 @@
_umask, _initgroups, _setegid, _seteuid,
_setgid, _setuid, _setgroups,
_shouldAbortOnUncaughtToggle },
- { internalBinding, NativeModule }) {
+ { internalBinding, NativeModule },
+ triggerFatalException) {
const exceptionHandlerState = { captureFn: null };
const isMainThread = internalBinding('worker').threadId === 0;
@@ -538,8 +539,9 @@
get: () => {
process.emitWarning('queueMicrotask() is experimental.',
'ExperimentalWarning');
- const { queueMicrotask } =
+ const { setupQueueMicrotask } =
NativeModule.require('internal/queue_microtask');
+ const queueMicrotask = setupQueueMicrotask(triggerFatalException);
Object.defineProperty(global, 'queueMicrotask', {
value: queueMicrotask,
writable: true,
diff --git a/lib/internal/queue_microtask.js b/lib/internal/queue_microtask.js
index e9cc414389..6421e7f940 100644
--- a/lib/internal/queue_microtask.js
+++ b/lib/internal/queue_microtask.js
@@ -5,27 +5,35 @@ const { AsyncResource } = require('async_hooks');
const { getDefaultTriggerAsyncId } = require('internal/async_hooks');
const { enqueueMicrotask } = internalBinding('util');
-// declared separately for name, arrow function to prevent construction
-const queueMicrotask = (callback) => {
- if (typeof callback !== 'function') {
- throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
- }
+const setupQueueMicrotask = (triggerFatalException) => {
+ const queueMicrotask = (callback) => {
+ if (typeof callback !== 'function') {
+ throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
+ }
- const asyncResource = new AsyncResource('Microtask', {
- triggerAsyncId: getDefaultTriggerAsyncId(),
- requireManualDestroy: true,
- });
+ const asyncResource = new AsyncResource('Microtask', {
+ triggerAsyncId: getDefaultTriggerAsyncId(),
+ requireManualDestroy: true,
+ });
- enqueueMicrotask(() => {
- asyncResource.runInAsyncScope(() => {
- try {
- callback();
- } catch (e) {
- process.emit('error', e);
- }
+ enqueueMicrotask(() => {
+ asyncResource.runInAsyncScope(() => {
+ try {
+ callback();
+ } catch (error) {
+ // TODO(devsnek) remove this if
+ // https://bugs.chromium.org/p/v8/issues/detail?id=8326
+ // is resolved such that V8 triggers the fatal exception
+ // handler for microtasks
+ triggerFatalException(error);
+ } finally {
+ asyncResource.emitDestroy();
+ }
+ });
});
- asyncResource.emitDestroy();
- });
+ };
+
+ return queueMicrotask;
};
-module.exports = { queueMicrotask };
+module.exports = { setupQueueMicrotask };