refactor: add EmitWarning(v8::Isolate*) helper (#43722)

* refactor: add EmitWarning(Isolate*, ...) warning

* chore: remove EmitWarning(node::Environment*, ...)

* chore: add code comments

* fixup! refactor: add EmitWarning(Isolate*, ...) warning

* chore: remove unused node #includes
This commit is contained in:
Charles Kerr 2024-09-16 15:53:04 -05:00 committed by GitHub
parent 7d4f202c1c
commit 05dfd14913
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 72 additions and 89 deletions

View file

@ -6,6 +6,9 @@
#include "base/logging.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"
namespace electron::util {
@ -44,4 +47,22 @@ v8::MaybeLocal<v8::Value> CompileAndCall(
return ret;
}
void EmitWarning(const std::string_view warning_msg,
const std::string_view warning_type) {
EmitWarning(JavascriptEnvironment::GetIsolate(), warning_msg, warning_type);
}
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, "");
}
} // namespace electron::util