refactor: add EmitDeprecationWarning helper (#46879)

* refactor: add EmitDeprecationWarning helper

Also switches EmitWarning to using Node's ProcessEmitWarningGeneric

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* chore: use node namespace for function call

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
This commit is contained in:
trop[bot] 2025-05-01 09:44:59 -05:00 committed by GitHub
parent ee65ab75f5
commit c24f330b45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 19 deletions

View file

@ -666,10 +666,9 @@ void WebRequest::SetListener(Event event,
} }
if (filter_include_patterns.empty()) { if (filter_include_patterns.empty()) {
util::EmitWarning( util::EmitDeprecationWarning(
"The urls array in WebRequestFilter is empty, which is deprecated. " "The urls array in WebRequestFilter is empty, which is deprecated. "
"Please use '<all_urls>' to match all URLs.", "Please use '<all_urls>' to match all URLs.");
"DeprecationWarning");
filter_include_patterns.insert("<all_urls>"); filter_include_patterns.insert("<all_urls>");
} }

View file

@ -182,9 +182,8 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
if (windowType == "textured" && (transparent() || !has_frame())) { if (windowType == "textured" && (transparent() || !has_frame())) {
util::EmitWarning( util::EmitDeprecationWarning(
"The 'textured' window type is deprecated and will be removed", "The 'textured' window type is deprecated and will be removed");
"DeprecationWarning");
styleMask |= NSWindowStyleMaskTexturedBackground; styleMask |= NSWindowStyleMaskTexturedBackground;
} }
#pragma clang diagnostic pop #pragma clang diagnostic pop

View file

@ -286,9 +286,8 @@ v8::Local<v8::Value> NativeImage::GetBitmap(gin::Arguments* args) {
if (!deprecated_warning_issued) { if (!deprecated_warning_issued) {
deprecated_warning_issued = true; deprecated_warning_issued = true;
util::EmitWarning(isolate_, util::EmitDeprecationWarning(
"getBitmap() is deprecated, use toBitmap() instead.", isolate_, "getBitmap() is deprecated, use toBitmap() instead.");
"DeprecationWarning");
} }
return ToBitmap(args); return ToBitmap(args);

View file

@ -12,10 +12,10 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "gin/converter.h" #include "gin/converter.h"
#include "gin/dictionary.h"
#include "shell/browser/javascript_environment.h" #include "shell/browser/javascript_environment.h"
#include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/node_includes.h" #include "shell/common/node_includes.h"
#include "third_party/electron_node/src/node_process-inl.h"
namespace electron::util { namespace electron::util {
@ -65,14 +65,22 @@ void EmitWarning(const std::string_view warning_msg,
void EmitWarning(v8::Isolate* isolate, void EmitWarning(v8::Isolate* isolate,
const std::string_view warning_msg, const std::string_view warning_msg,
const std::string_view warning_type) { const std::string_view warning_type) {
v8::HandleScope scope{isolate}; node::ProcessEmitWarningGeneric(node::Environment::GetCurrent(isolate),
gin::Dictionary process{ warning_msg, warning_type);
isolate, node::Environment::GetCurrent(isolate)->process_object()}; }
base::RepeatingCallback<void(std::string_view, std::string_view,
std::string_view)> void EmitDeprecationWarning(const std::string_view warning_msg,
emit_warning; const std::string_view deprecation_code) {
process.Get("emitWarning", &emit_warning); EmitDeprecationWarning(JavascriptEnvironment::GetIsolate(), warning_msg,
emit_warning.Run(warning_msg, warning_type, ""); deprecation_code);
}
void EmitDeprecationWarning(v8::Isolate* isolate,
const std::string_view warning_msg,
const std::string_view deprecation_code) {
node::ProcessEmitWarningGeneric(node::Environment::GetCurrent(isolate),
warning_msg, "DeprecationWarning",
deprecation_code);
} }
node::Environment* CreateEnvironment(v8::Isolate* isolate, node::Environment* CreateEnvironment(v8::Isolate* isolate,

View file

@ -30,9 +30,19 @@ void EmitWarning(v8::Isolate* isolate,
std::string_view warning_type); std::string_view warning_type);
// Emit a warning via node's process.emitWarning(), // Emit a warning via node's process.emitWarning(),
// using JavscriptEnvironment's isolate // using JavascriptEnvironment's isolate
void EmitWarning(std::string_view warning_msg, std::string_view warning_type); void EmitWarning(std::string_view warning_msg, std::string_view warning_type);
// Emit a deprecation warning via node's process.emitWarning()
void EmitDeprecationWarning(v8::Isolate* isolate,
std::string_view warning_msg,
std::string_view deprecation_code = "");
// Emit a deprecation warning via node's process.emitWarning(),
// using JavascriptEnvironment's isolate
void EmitDeprecationWarning(std::string_view warning_msg,
std::string_view deprecation_code = "");
// Run a script with JS source bundled inside the binary as if it's wrapped // Run a script with JS source bundled inside the binary as if it's wrapped
// in a function called with a null receiver and arguments specified in C++. // in a function called with a null receiver and arguments specified in C++.
// The returned value is empty if an exception is encountered. // The returned value is empty if an exception is encountered.