refactor: use base::as_string_view() (#45745)

Use `base::as_string_view()` as a safer alternative to `reinterpret_cast`
in a couple of places.

Xref: 5472408

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2025-02-21 10:14:05 -06:00 committed by GitHub
parent 02b85f1e6d
commit 8934eb1af5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -8,6 +8,7 @@
#include <string_view>
#include <utility>
#include "base/containers/span.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "content/public/browser/devtools_agent_host.h"
@ -44,8 +45,7 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);
std::string_view message_str(reinterpret_cast<const char*>(message.data()),
message.size());
const std::string_view message_str = base::as_string_view(message);
std::optional<base::Value> parsed_message = base::JSONReader::Read(
message_str, base::JSON_REPLACE_INVALID_CHARACTERS);
if (!parsed_message || !parsed_message->is_dict())