Skip to content

Commit

Permalink
src: allow embedder control of code generation policy
Browse files Browse the repository at this point in the history
PR-URL: nodejs#46368
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
codebytere authored Feb 3, 2023
1 parent 82ee782 commit 3aaeb30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,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()
Expand Down
5 changes: 4 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,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 {
Expand All @@ -468,6 +469,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
Expand Down

0 comments on commit 3aaeb30

Please sign in to comment.