chore: modernize Value usage in converters (#34794)
* chore: modernize Value usage in converters * Date is parsed as an empty object now
This commit is contained in:
parent
d28ed0da20
commit
0ee7f14190
34 changed files with 203 additions and 829 deletions
|
@ -45,44 +45,35 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host,
|
|||
|
||||
base::StringPiece message_str(reinterpret_cast<const char*>(message.data()),
|
||||
message.size());
|
||||
std::unique_ptr<base::Value> parsed_message =
|
||||
base::JSONReader::ReadDeprecated(message_str,
|
||||
base::JSON_REPLACE_INVALID_CHARACTERS);
|
||||
absl::optional<base::Value> parsed_message = base::JSONReader::Read(
|
||||
message_str, base::JSON_REPLACE_INVALID_CHARACTERS);
|
||||
if (!parsed_message || !parsed_message->is_dict())
|
||||
return;
|
||||
auto* dict = static_cast<base::DictionaryValue*>(parsed_message.get());
|
||||
int id;
|
||||
if (!dict->GetInteger("id", &id)) {
|
||||
std::string method;
|
||||
if (!dict->GetString("method", &method))
|
||||
base::Value::Dict& dict = parsed_message->GetDict();
|
||||
absl::optional<int> id = dict.FindInt("id");
|
||||
if (!id) {
|
||||
std::string* method = dict.FindString("method");
|
||||
if (!method)
|
||||
return;
|
||||
std::string session_id;
|
||||
dict->GetString("sessionId", &session_id);
|
||||
base::DictionaryValue* params_value = nullptr;
|
||||
base::DictionaryValue params;
|
||||
if (dict->GetDictionary("params", ¶ms_value))
|
||||
params.Swap(params_value);
|
||||
Emit("message", method, params, session_id);
|
||||
std::string* session_id = dict.FindString("sessionId");
|
||||
base::Value::Dict* params = dict.FindDict("params");
|
||||
Emit("message", *method, params ? std::move(*params) : base::Value::Dict(),
|
||||
session_id ? *session_id : "");
|
||||
} else {
|
||||
auto it = pending_requests_.find(id);
|
||||
auto it = pending_requests_.find(*id);
|
||||
if (it == pending_requests_.end())
|
||||
return;
|
||||
|
||||
gin_helper::Promise<base::DictionaryValue> promise = std::move(it->second);
|
||||
gin_helper::Promise<base::Value::Dict> promise = std::move(it->second);
|
||||
pending_requests_.erase(it);
|
||||
|
||||
base::DictionaryValue* error = nullptr;
|
||||
if (dict->GetDictionary("error", &error)) {
|
||||
std::string message;
|
||||
error->GetString("message", &message);
|
||||
promise.RejectWithErrorMessage(message);
|
||||
base::Value::Dict* error = dict.FindDict("error");
|
||||
if (error) {
|
||||
std::string* message = error->FindString("message");
|
||||
promise.RejectWithErrorMessage(message ? *message : "");
|
||||
} else {
|
||||
base::DictionaryValue* result_body = nullptr;
|
||||
base::DictionaryValue result;
|
||||
if (dict->GetDictionary("result", &result_body)) {
|
||||
result.Swap(result_body);
|
||||
}
|
||||
promise.Resolve(result);
|
||||
base::Value::Dict* result = dict.FindDict("result");
|
||||
promise.Resolve(result ? std::move(*result) : base::Value::Dict());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +124,7 @@ void Debugger::Detach() {
|
|||
|
||||
v8::Local<v8::Promise> Debugger::SendCommand(gin::Arguments* args) {
|
||||
v8::Isolate* isolate = args->isolate();
|
||||
gin_helper::Promise<base::DictionaryValue> promise(isolate);
|
||||
gin_helper::Promise<base::Value::Dict> promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
if (!agent_host_) {
|
||||
|
@ -147,7 +138,7 @@ v8::Local<v8::Promise> Debugger::SendCommand(gin::Arguments* args) {
|
|||
return handle;
|
||||
}
|
||||
|
||||
base::DictionaryValue command_params;
|
||||
base::Value::Dict command_params;
|
||||
args->GetNext(&command_params);
|
||||
|
||||
std::string session_id;
|
||||
|
@ -156,22 +147,21 @@ v8::Local<v8::Promise> Debugger::SendCommand(gin::Arguments* args) {
|
|||
return handle;
|
||||
}
|
||||
|
||||
base::DictionaryValue request;
|
||||
base::Value::Dict request;
|
||||
int request_id = ++previous_request_id_;
|
||||
pending_requests_.emplace(request_id, std::move(promise));
|
||||
request.SetInteger("id", request_id);
|
||||
request.SetString("method", method);
|
||||
if (!command_params.DictEmpty()) {
|
||||
request.Set("params",
|
||||
base::Value::ToUniquePtrValue(command_params.Clone()));
|
||||
request.Set("id", request_id);
|
||||
request.Set("method", method);
|
||||
if (!command_params.empty()) {
|
||||
request.Set("params", base::Value(std::move(command_params)));
|
||||
}
|
||||
|
||||
if (!session_id.empty()) {
|
||||
request.SetString("sessionId", session_id);
|
||||
request.Set("sessionId", session_id);
|
||||
}
|
||||
|
||||
std::string json_args;
|
||||
base::JSONWriter::Write(request, &json_args);
|
||||
base::JSONWriter::Write(base::Value(std::move(request)), &json_args);
|
||||
agent_host_->DispatchProtocolMessage(
|
||||
this, base::as_bytes(base::make_span(json_args)));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue