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

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

Xref: 5472408
This commit is contained in:
Charles Kerr 2025-02-20 18:19:36 -06:00 committed by GitHub
parent 4867b5dc75
commit ceaa0e26c7
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())