From 18e86879237b8a7a3a13cea281e26753da854c6d Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 15 Jul 2020 18:45:10 -0700 Subject: [PATCH] src: allow preventing SetPromiseRejectCallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/34387 Reviewed-By: Gus Caplan Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- src/api/environment.cc | 8 +++++--- src/node.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api/environment.cc b/src/api/environment.cc index 5526859e551c10..97d25cba579570 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -245,9 +245,11 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) { s.allow_wasm_code_generation_callback : AllowWasmCodeGenerationCallback; isolate->SetAllowWasmCodeGenerationCallback(allow_wasm_codegen_cb); - auto* promise_reject_cb = s.promise_reject_callback ? - s.promise_reject_callback : task_queue::PromiseRejectCallback; - isolate->SetPromiseRejectCallback(promise_reject_cb); + if ((s.flags & SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK) == 0) { + auto* promise_reject_cb = s.promise_reject_callback ? + s.promise_reject_callback : task_queue::PromiseRejectCallback; + isolate->SetPromiseRejectCallback(promise_reject_cb); + } auto* host_cleanup_cb = s.host_cleanup_finalization_group_callback ? s.host_cleanup_finalization_group_callback : diff --git a/src/node.h b/src/node.h index 886216e2cb533e..aba821a5e03f37 100644 --- a/src/node.h +++ b/src/node.h @@ -301,7 +301,8 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform { enum IsolateSettingsFlags { MESSAGE_LISTENER_WITH_ERROR_LEVEL = 1 << 0, - DETAILED_SOURCE_POSITIONS_FOR_PROFILING = 1 << 1 + DETAILED_SOURCE_POSITIONS_FOR_PROFILING = 1 << 1, + SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK = 1 << 2 }; struct IsolateSettings {