electron/patches/node/allow_embedder_to_control_codegenerationfromstringscallback.patch
Darshan Sen c326b0068e
fix: recommended node-gyp version in node.h error (#37829)
fix: recommended node-gyp version in node.h error

In
https://github.com/electron/electron/blob/main/docs/tutorial/using-native-node-modules.md#using-npm,
we recommend setting the `npm_config_disturl` variable but doing that
does not work on node-gyp v8.4.0 because after
https://github.com/nodejs/node-gyp/pull/2497
landed, the dist URL was read only from `gyp.opts['dist-url']`. The fix
for reading the value from `npm_config_disturl` by parsing
`gyp.opts.disturl` was landed in
https://github.com/nodejs/node-gyp/pull/2547 and that change was
released in node-gyp v9.0.0, so this change updates the error macro to
recommend node-gyp v9.0.0 as the minimum required version.

Signed-off-by: Darshan Sen <raisinten@gmail.com>
2023-04-11 13:26:26 +02:00

44 lines
2.2 KiB
Diff

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.
Upstreamed in https://github.com/nodejs/node/pull/46368.
diff --git a/src/api/environment.cc b/src/api/environment.cc
index a994221445471b92d12ed9cb3bef9ffb70670ab6..d6c6fd9c257cb51ba387c4b4d07a24ff80f9f060 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -268,11 +268,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 03f55b0a1853c055eb6c709a8e7916c2a95672d3..47ac8c24ef5e26822f694b583767e850fc5f7d96 100644
--- a/src/node.h
+++ b/src/node.h
@@ -463,6 +463,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