diff --git a/shell/common/gin_helper/event_emitter_caller.cc b/shell/common/gin_helper/event_emitter_caller.cc index d21a3fb77a..a64f36d614 100644 --- a/shell/common/gin_helper/event_emitter_caller.cc +++ b/shell/common/gin_helper/event_emitter_caller.cc @@ -11,7 +11,7 @@ namespace gin_helper::internal { v8::Local CallMethodWithArgs( v8::Isolate* isolate, v8::Local obj, - const char* method, + const std::string_view method, const base::span> args) { v8::EscapableHandleScope handle_scope{isolate}; @@ -27,8 +27,9 @@ v8::Local CallMethodWithArgs( v8::MicrotasksScope::kRunMicrotasks); // node::MakeCallback will also run pending tasks in Node.js. - v8::MaybeLocal ret = node::MakeCallback( - isolate, obj, method, args.size(), args.data(), {0, 0}); + v8::MaybeLocal ret = + node::MakeCallback(isolate, obj, gin::StringToV8(isolate, method), + args.size(), args.data(), {0, 0}); // If the JS function throws an exception (doesn't return a value) the result // of MakeCallback will be empty and therefore ToLocal will be false, in this diff --git a/shell/common/gin_helper/event_emitter_caller.h b/shell/common/gin_helper/event_emitter_caller.h index 25c935d660..5ac2f40363 100644 --- a/shell/common/gin_helper/event_emitter_caller.h +++ b/shell/common/gin_helper/event_emitter_caller.h @@ -6,6 +6,7 @@ #define ELECTRON_SHELL_COMMON_GIN_HELPER_EVENT_EMITTER_CALLER_H_ #include +#include #include #include "base/containers/span.h" @@ -20,17 +21,17 @@ namespace internal { v8::Local CallMethodWithArgs(v8::Isolate* isolate, v8::Local obj, - const char* method, + std::string_view method, base::span> args); } // namespace internal // obj.emit(name, args...); // The caller is responsible of allocating a HandleScope. -template +template v8::Local EmitEvent(v8::Isolate* isolate, v8::Local obj, - const StringType& name, + const std::string_view name, Args&&... args) { v8::EscapableHandleScope scope{isolate}; std::array, 1U + sizeof...(args)> converted_args = { @@ -45,7 +46,7 @@ v8::Local EmitEvent(v8::Isolate* isolate, template v8::Local CustomEmit(v8::Isolate* isolate, v8::Local object, - const char* custom_emit, + const std::string_view custom_emit, Args&&... args) { v8::EscapableHandleScope scope{isolate}; std::array, sizeof...(args)> converted_args = { @@ -58,7 +59,7 @@ v8::Local CustomEmit(v8::Isolate* isolate, template v8::Local CallMethod(v8::Isolate* isolate, gin_helper::DeprecatedWrappable* object, - const char* method_name, + const std::string_view method_name, Args&&... args) { v8::EscapableHandleScope scope(isolate); v8::Local v8_object; @@ -71,7 +72,7 @@ v8::Local CallMethod(v8::Isolate* isolate, template v8::Local CallMethod(gin_helper::DeprecatedWrappable* object, - const char* method_name, + const std::string_view method_name, Args&&... args) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); return CallMethod(isolate, object, method_name, std::forward(args)...); @@ -80,7 +81,7 @@ v8::Local CallMethod(gin_helper::DeprecatedWrappable* object, template v8::Local CallMethod(v8::Isolate* isolate, gin::Wrappable* object, - const char* method_name, + const std::string_view method_name, Args&&... args) { v8::EscapableHandleScope scope(isolate); v8::Local v8_object; @@ -93,7 +94,7 @@ v8::Local CallMethod(v8::Isolate* isolate, template v8::Local CallMethod(gin::Wrappable* object, - const char* method_name, + const std::string_view method_name, Args&&... args) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); return CallMethod(isolate, object, method_name, std::forward(args)...);