refactor: replace use of deprecated base::JSONWriter::WriteJson() (#41215)

* refactor: use base::WriteJson() in ListValueToNSArray()

refactor: use base::WriteJson() in DictionaryValueToNSDictionary()

* refactor: use base::WriteJson() in Debugger::SendCommand()

* refactor: use base::WriteJson() in ScriptingExecuteScriptFunction::Run()

* refactor: use base::WriteJson() in HandleAccessibilityRequestCallback()
This commit is contained in:
Charles Kerr 2024-02-02 12:25:58 -06:00 committed by GitHub
parent 9bfa16ad7f
commit 2ebaebb603
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 16 deletions

View file

@ -159,8 +159,7 @@ v8::Local<v8::Promise> Debugger::SendCommand(gin::Arguments* args) {
request.Set("sessionId", session_id);
}
std::string json_args;
base::JSONWriter::Write(request, &json_args);
const auto json_args = base::WriteJson(request).value_or("");
agent_host_->DispatchProtocolMessage(
this, base::as_bytes(base::make_span(json_args)));

View file

@ -631,10 +631,11 @@ ExtensionFunction::ResponseAction ScriptingExecuteScriptFunction::Run() {
std::vector<std::string> string_args;
string_args.reserve(injection_.args->size());
for (const auto& arg : *injection_.args) {
std::string json;
if (!base::JSONWriter::Write(arg, &json))
if (auto json = base::WriteJson(arg)) {
string_args.push_back(std::move(*json));
} else {
return RespondNow(Error("Unserializable argument passed."));
string_args.push_back(std::move(json));
}
}
args_expression = base::JoinString(string_args, ",");
}

View file

@ -13,10 +13,10 @@
namespace electron {
NSArray* ListValueToNSArray(const base::Value::List& value) {
std::string json;
if (!base::JSONWriter::Write(base::ValueView{value}, &json))
const auto json = base::WriteJson(value);
if (!json.has_value())
return nil;
NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
NSData* jsonData = [NSData dataWithBytes:json->data() length:json->size()];
id obj = [NSJSONSerialization JSONObjectWithData:jsonData
options:0
error:nil];
@ -56,10 +56,10 @@ base::Value::List NSArrayToValue(NSArray* arr) {
}
NSDictionary* DictionaryValueToNSDictionary(const base::Value::Dict& value) {
std::string json;
if (!base::JSONWriter::Write(base::ValueView{value}, &json))
const auto json = base::WriteJson(value);
if (!json.has_value())
return nil;
NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
NSData* jsonData = [NSData dataWithBytes:json->data() length:json->size()];
id obj = [NSJSONSerialization JSONObjectWithData:jsonData
options:0
error:nil];

View file

@ -295,11 +295,8 @@ void HandleAccessibilityRequestCallback(
data.Set(kBrowsersField, std::move(window_list));
std::string json_string;
base::JSONWriter::Write(data, &json_string);
std::move(callback).Run(
base::MakeRefCounted<base::RefCountedString>(std::move(json_string)));
std::move(callback).Run(base::MakeRefCounted<base::RefCountedString>(
base::WriteJson(data).value_or("")));
}
} // namespace