electron/patches/node/allow_embedder_to_control_codegenerationfromstringscallback.patch

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
2.2 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jeremy Rose <japthorp@slack-corp.com>
Date: Mon, 5 Dec 2022 14:28:40 -0800
Subject: allow embedder to control CodeGenerationFromStringsCallback
This is needed to blend Blink and Node's code generation policy.
This should be upstreamed.
diff --git a/src/api/environment.cc b/src/api/environment.cc
index b6981c37d5b286e22f24d11751eb05f72ca27619..c4a3a54753767e7686a0e32996bcda0c90f659a7 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -259,11 +259,15 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
isolate->SetMicrotasksPolicy(s.policy);
+ // Allow the embedder first chance at policy decisions.
+ // This is particularly important for embedders that combine Node and Blink,
+ // as Blink must be able to make Content Security Policy-based decisions.
auto* allow_wasm_codegen_cb = s.allow_wasm_code_generation_callback ?
s.allow_wasm_code_generation_callback : AllowWasmCodeGenerationCallback;
isolate->SetAllowWasmCodeGenerationCallback(allow_wasm_codegen_cb);
- isolate->SetModifyCodeGenerationFromStringsCallback(
- ModifyCodeGenerationFromStrings);
+ auto* modify_code_generation_from_strings_callback = s.modify_code_generation_from_strings_callback ?
+ s.modify_code_generation_from_strings_callback : ModifyCodeGenerationFromStrings;
+ isolate->SetModifyCodeGenerationFromStringsCallback(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 bee494f9da8470530ee9ec58958f8f2c7ce6a302..387ce8e5edf6524db170e2d46ef501a1cd956d98 100644
--- a/src/node.h
+++ b/src/node.h
@@ -461,6 +461,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