From 17eea1812eea7d875cf890ac0f9f6cba30c73686 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 3 Feb 2023 15:43:29 +0000 Subject: [PATCH] src: allow embedder control of code generation policy PR-URL: https://github.com/nodejs/node/pull/46368 Reviewed-By: Anna Henningsen Reviewed-By: Rafael Gonzaga Reviewed-By: Michael Dawson --- src/api/environment.cc | 10 +++++++++- src/node.h | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/api/environment.cc b/src/api/environment.cc index 86498671b5df02..f4a8479c3da6c7 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -263,8 +263,16 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) { auto* allow_wasm_codegen_cb = s.allow_wasm_code_generation_callback ? s.allow_wasm_code_generation_callback : AllowWasmCodeGenerationCallback; isolate->SetAllowWasmCodeGenerationCallback(allow_wasm_codegen_cb); + + auto* modify_code_generation_from_strings_callback = + ModifyCodeGenerationFromStrings; + if (s.flags & ALLOW_MODIFY_CODE_GENERATION_FROM_STRINGS_CALLBACK && + s.modify_code_generation_from_strings_callback) { + modify_code_generation_from_strings_callback = + s.modify_code_generation_from_strings_callback; + } isolate->SetModifyCodeGenerationFromStringsCallback( - ModifyCodeGenerationFromStrings); + modify_code_generation_from_strings_callback); Mutex::ScopedLock lock(node::per_process::cli_options_mutex); if (per_process::cli_options->get_per_isolate_options() diff --git a/src/node.h b/src/node.h index 58ff9010c78f31..812c4943cdc7d7 100644 --- a/src/node.h +++ b/src/node.h @@ -438,7 +438,8 @@ enum IsolateSettingsFlags { MESSAGE_LISTENER_WITH_ERROR_LEVEL = 1 << 0, DETAILED_SOURCE_POSITIONS_FOR_PROFILING = 1 << 1, SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK = 1 << 2, - SHOULD_NOT_SET_PREPARE_STACK_TRACE_CALLBACK = 1 << 3 + SHOULD_NOT_SET_PREPARE_STACK_TRACE_CALLBACK = 1 << 3, + ALLOW_MODIFY_CODE_GENERATION_FROM_STRINGS_CALLBACK = 1 << 4, }; struct IsolateSettings { @@ -456,6 +457,8 @@ struct IsolateSettings { v8::PromiseRejectCallback promise_reject_callback = nullptr; v8::AllowWasmCodeGenerationCallback allow_wasm_code_generation_callback = nullptr; + v8::ModifyCodeGenerationFromStringsCallback2 + modify_code_generation_from_strings_callback = nullptr; }; // Overriding IsolateSettings may produce unexpected behavior