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

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