Commit edaec0cb authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol (V8)

"Remove the JSON parser and revamp Value::parseBinary."
Upstream review: https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/2026351

In addition to the upstream changes, this PR includes the necessary
tweaks to the V8 inspector (now taking the detour via
CBOR to parse Javascript).

New Revision: 0e0a1995497511008864546c094e885f3f1e13a3

Change-Id: I5ccfea5a3e1bab3e183b45c87726747d17d06944
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2020518Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66116}
parent 5ae7258c
......@@ -521,8 +521,12 @@ Response InjectedScript::getInternalAndPrivateProperties(
}
void InjectedScript::releaseObject(const String16& objectId) {
std::vector<uint8_t> cbor;
v8_crdtp::json::ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(objectId.characters16(), objectId.length()),
&cbor);
std::unique_ptr<protocol::Value> parsedObjectId =
protocol::StringUtil::parseJSON(objectId);
protocol::Value::parseBinary(cbor.data(), cbor.size());
if (!parsedObjectId) return;
protocol::DictionaryValue* object =
protocol::DictionaryValue::cast(parsedObjectId.get());
......
......@@ -4,6 +4,7 @@
#include "src/inspector/remote-object-id.h"
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/inspector/protocol/Protocol.h"
#include "src/inspector/string-util.h"
......@@ -13,8 +14,12 @@ RemoteObjectIdBase::RemoteObjectIdBase() : m_injectedScriptId(0) {}
std::unique_ptr<protocol::DictionaryValue>
RemoteObjectIdBase::parseInjectedScriptId(const String16& objectId) {
std::vector<uint8_t> cbor;
v8_crdtp::json::ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(objectId.characters16(), objectId.length()),
&cbor);
std::unique_ptr<protocol::Value> parsedValue =
protocol::StringUtil::parseJSON(objectId);
protocol::Value::parseBinary(cbor.data(), cbor.size());
if (!parsedValue || parsedValue->type() != protocol::Value::TypeObject)
return nullptr;
......
......@@ -105,23 +105,6 @@ double StringUtil::toDouble(const char* s, size_t len, bool* isOk) {
*isOk = !std::isnan(result);
return result;
}
std::unique_ptr<protocol::Value> StringUtil::parseJSON(
const StringView& string) {
if (!string.length()) return nullptr;
if (string.is8Bit()) {
return parseJSONCharacters(string.characters8(),
static_cast<int>(string.length()));
}
return parseJSONCharacters(string.characters16(),
static_cast<int>(string.length()));
}
std::unique_ptr<protocol::Value> StringUtil::parseJSON(const String16& string) {
if (!string.length()) return nullptr;
return parseJSONCharacters(string.characters16(),
static_cast<int>(string.length()));
}
} // namespace protocol
namespace {
......
......@@ -65,8 +65,6 @@ class StringUtil {
StringBuilder& builder) { // NOLINT(runtime/references)
return builder.toString();
}
static std::unique_ptr<protocol::Value> parseJSON(const String16& json);
static std::unique_ptr<protocol::Value> parseJSON(const StringView& json);
static String fromUTF8(const uint8_t* data, size_t length) {
return String16::fromUTF8(reinterpret_cast<const char*>(data), length);
......
......@@ -6,6 +6,7 @@
#include <algorithm>
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/base/safe_conversions.h"
#include "src/debug/debug-interface.h"
#include "src/inspector/injected-script.h"
......@@ -1418,8 +1419,12 @@ void V8DebuggerAgentImpl::didParseSource(
if (inspected) {
// Script reused between different groups/sessions can have a stale
// execution context id.
const String16& aux = inspected->auxData();
std::vector<uint8_t> cbor;
v8_crdtp::json::ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(aux.characters16(), aux.length()), &cbor);
executionContextAuxData = protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(inspected->auxData()));
protocol::Value::parseBinary(cbor.data(), cbor.size()));
}
bool isLiveEdit = script->isLiveEdit();
bool hasSourceURLComment = script->hasSourceURLComment();
......
......@@ -347,16 +347,9 @@ void V8InspectorSessionImpl::dispatchProtocolMessage(
m_state->setBoolean("use_binary_protocol", true);
cbor = span<uint8_t>(message.characters8(), message.length());
} else {
if (message.is8Bit()) {
// We're ignoring the return value of these conversion functions
// intentionally. It means the |parsed_message| below will be nullptr.
ConvertJSONToCBOR(span<uint8_t>(message.characters8(), message.length()),
&converted_cbor);
} else {
ConvertJSONToCBOR(
span<uint16_t>(message.characters16(), message.length()),
&converted_cbor);
}
// We're ignoring the return value of the conversion function
// intentionally. It means the |parsed_message| below will be nullptr.
ConvertToCBOR(message, &converted_cbor);
cbor = SpanFrom(converted_cbor);
}
int callId;
......@@ -426,10 +419,12 @@ V8InspectorSession::Inspectable* V8InspectorSessionImpl::inspectedObject(
void V8InspectorSessionImpl::schedulePauseOnNextStatement(
const StringView& breakReason, const StringView& breakDetails) {
std::vector<uint8_t> cbor;
ConvertToCBOR(breakDetails, &cbor);
m_debuggerAgent->schedulePauseOnNextStatement(
toString16(breakReason),
protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(breakDetails)));
protocol::Value::parseBinary(cbor.data(), cbor.size())));
}
void V8InspectorSessionImpl::cancelPauseOnNextStatement() {
......@@ -438,10 +433,12 @@ void V8InspectorSessionImpl::cancelPauseOnNextStatement() {
void V8InspectorSessionImpl::breakProgram(const StringView& breakReason,
const StringView& breakDetails) {
std::vector<uint8_t> cbor;
ConvertToCBOR(breakDetails, &cbor);
m_debuggerAgent->breakProgram(
toString16(breakReason),
protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(breakDetails)));
protocol::Value::parseBinary(cbor.data(), cbor.size())));
}
void V8InspectorSessionImpl::setSkipAllPauses(bool skip) {
......
......@@ -32,6 +32,7 @@
#include <inttypes.h>
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/debug/debug-interface.h"
#include "src/inspector/injected-script.h"
#include "src/inspector/inspected-context.h"
......@@ -823,9 +824,14 @@ void V8RuntimeAgentImpl::reportExecutionContextCreated(
.setName(context->humanReadableName())
.setOrigin(context->origin())
.build();
if (!context->auxData().isEmpty())
const String16& aux = context->auxData();
if (!aux.isEmpty()) {
std::vector<uint8_t> cbor;
v8_crdtp::json::ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(aux.characters16(), aux.length()), &cbor);
description->setAuxData(protocol::DictionaryValue::cast(
protocol::StringUtil::parseJSON(context->auxData())));
protocol::Value::parseBinary(cbor.data(), cbor.size())));
}
m_frontend.executionContextCreated(std::move(description));
}
......
......@@ -10,6 +10,10 @@
#include "src/inspector/v8-debugger.h"
#include "src/inspector/v8-inspector-impl.h"
using v8_crdtp::SpanFrom;
using v8_crdtp::json::ConvertCBORToJSON;
using v8_crdtp::json::ConvertJSONToCBOR;
namespace v8_inspector {
int V8StackTraceImpl::maxCallStackSizeToCapture = 200;
......@@ -126,8 +130,17 @@ V8StackTraceId::V8StackTraceId(uintptr_t id,
V8StackTraceId::V8StackTraceId(const StringView& json)
: id(0), debugger_id(V8DebuggerId().pair()) {
auto dict =
protocol::DictionaryValue::cast(protocol::StringUtil::parseJSON(json));
if (json.length() == 0) return;
std::vector<uint8_t> cbor;
if (json.is8Bit()) {
ConvertJSONToCBOR(
v8_crdtp::span<uint8_t>(json.characters8(), json.length()), &cbor);
} else {
ConvertJSONToCBOR(
v8_crdtp::span<uint16_t>(json.characters16(), json.length()), &cbor);
}
auto dict = protocol::DictionaryValue::cast(
protocol::Value::parseBinary(cbor.data(), cbor.size()));
if (!dict) return;
String16 s;
if (!dict->getString(kId, &s)) return;
......@@ -152,7 +165,7 @@ std::unique_ptr<StringBuffer> V8StackTraceId::ToString() {
dict->setBoolean(kShouldPause, should_pause);
std::vector<uint8_t> json;
std::vector<uint8_t> cbor = std::move(*dict).TakeSerialized();
v8_crdtp::json::ConvertCBORToJSON(v8_crdtp::SpanFrom(cbor), &json);
ConvertCBORToJSON(SpanFrom(cbor), &json);
return StringBufferFrom(std::move(json));
}
......
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 0213a8545f6362cd1cd5091cedf29747736552e8
Revision: 0e0a1995497511008864546c094e885f3f1e13a3
License: BSD
License File: LICENSE
Security Critical: no
......
......@@ -4,21 +4,4 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef {{"_".join(config.protocol.namespace)}}_Parser_h
#define {{"_".join(config.protocol.namespace)}}_Parser_h
//#include "Forward.h"
//#include "Values.h"
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
{{config.lib.export_macro}} std::unique_ptr<Value> parseJSONCharacters(const uint8_t*, unsigned);
{{config.lib.export_macro}} std::unique_ptr<Value> parseJSONCharacters(const uint16_t*, unsigned);
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#endif // !defined({{"_".join(config.protocol.namespace)}}_Parser_h)
// TODO(johannes): Remove Parser_h.template.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment