From 1d6161eb20e05993bec4e5468ccc204373e27011 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Thu, 21 Dec 2017 18:45:36 -0500 Subject: [PATCH] lib, src: use process.config instead of regex Is safer to use a `process.binding(config)` defined boolean, than to regex on `process.execArgv`. Also, this better falls in line with the conventions of checking flags passed to the executable. PR-URL: https://github.com/nodejs/node/pull/17814 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- lib/internal/async_hooks.js | 5 +---- src/node_config.cc | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index e14a0000640e7d..ea49239a6178bb 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -82,9 +82,6 @@ const emitDestroyNative = emitHookFactory(destroy_symbol, 'emitDestroyNative'); const emitPromiseResolveNative = emitHookFactory(promise_resolve_symbol, 'emitPromiseResolveNative'); -// TODO(refack): move to node-config.cc -const abort_regex = /^--abort[_-]on[_-]uncaught[_-]exception$/; - // Setup the callbacks that node::AsyncWrap will call when there are hooks to // process. They use the same functions as the JS embedder API. These callbacks // are setup immediately to prevent async_wrap.setupHooks() from being hijacked @@ -104,7 +101,7 @@ function fatalError(e) { Error.captureStackTrace(o, fatalError); process._rawDebug(o.stack); } - if (process.execArgv.some((e) => abort_regex.test(e))) { + if (process.binding('config').shouldAbortOnUncaughtException) { process.abort(); } process.exit(1); diff --git a/src/node_config.cc b/src/node_config.cc index 07f891cf0c012a..0a78da7198b6b0 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -85,6 +85,9 @@ static void InitConfig(Local target, if (config_expose_http2) READONLY_BOOLEAN_PROPERTY("exposeHTTP2"); + if (env->abort_on_uncaught_exception()) + READONLY_BOOLEAN_PROPERTY("shouldAbortOnUncaughtException"); + READONLY_PROPERTY(target, "bits", Number::New(env->isolate(), 8 * sizeof(intptr_t)));