Skip to content

Commit

Permalink
refactor: replace use of deprecated base::JSONWriter::WriteJson() (#…
Browse files Browse the repository at this point in the history
…41224)

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

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

Co-authored-by: Charles Kerr <charles@charleskerr.com>

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

Co-authored-by: Charles Kerr <charles@charleskerr.com>

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

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use base::WriteJson() in HandleAccessibilityRequestCallback()
  • Loading branch information
trop[bot] committed Feb 6, 2024
1 parent a4f6d8a commit b96b402
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions shell/browser/api/electron_api_debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand Down
7 changes: 4 additions & 3 deletions shell/browser/extensions/api/scripting/scripting_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,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, ",");
}
Expand Down
12 changes: 6 additions & 6 deletions shell/browser/mac/dict_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -56,10 +56,10 @@
}

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];
Expand Down
7 changes: 2 additions & 5 deletions shell/browser/ui/webui/accessibility_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b96b402

Please sign in to comment.